изменения по группам

This commit is contained in:
kotcheshir73 2021-04-27 18:04:01 +04:00
parent c52d235a6c
commit 8169b49a94
16 changed files with 1593 additions and 93 deletions

View File

@ -64,7 +64,7 @@ namespace DatabaseCore
.WithMany(x => x.AcademicPlanRecordTimeNormHours)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<StudentGroup>().HasIndex(d => new { d.AcademicPlanId, d.EnrollmentYear, d.GroupNumber }).IsUnique();
modelBuilder.Entity<StudentGroup>().HasIndex(d => new { d.EducationDirectionId, d.AcademicCourse, d.GroupNumber }).IsUnique();
modelBuilder.Entity<Student>().HasIndex(d => new { d.NumberOfBook }).IsUnique();

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,67 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace DatabaseCore.Migrations
{
public partial class ChangeStudentGroups : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_StudentGroups_AcademicPlans_AcademicPlanId",
table: "StudentGroups");
migrationBuilder.RenameColumn(
name: "EnrollmentYear",
table: "StudentGroups",
newName: "AcademicCourse");
migrationBuilder.RenameColumn(
name: "AcademicPlanId",
table: "StudentGroups",
newName: "EducationDirectionId");
migrationBuilder.RenameIndex(
name: "IX_StudentGroups_AcademicPlanId_EnrollmentYear_GroupNumber",
table: "StudentGroups",
newName: "IX_StudentGroups_EducationDirectionId_AcademicCourse_GroupNumber");
migrationBuilder.AddForeignKey(
name: "FK_StudentGroups_EducationDirections_EducationDirectionId",
table: "StudentGroups",
column: "EducationDirectionId",
principalTable: "EducationDirections",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_StudentGroups_EducationDirections_EducationDirectionId",
table: "StudentGroups");
migrationBuilder.RenameColumn(
name: "EducationDirectionId",
table: "StudentGroups",
newName: "AcademicPlanId");
migrationBuilder.RenameColumn(
name: "AcademicCourse",
table: "StudentGroups",
newName: "EnrollmentYear");
migrationBuilder.RenameIndex(
name: "IX_StudentGroups_EducationDirectionId_AcademicCourse_GroupNumber",
table: "StudentGroups",
newName: "IX_StudentGroups_AcademicPlanId_EnrollmentYear_GroupNumber");
migrationBuilder.AddForeignKey(
name: "FK_StudentGroups_AcademicPlans_AcademicPlanId",
table: "StudentGroups",
column: "AcademicPlanId",
principalTable: "AcademicPlans",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -802,8 +802,8 @@ namespace DatabaseCore.Migrations
b.Property<Guid>("Id")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("AcademicPlanId")
.HasColumnType("uniqueidentifier");
b.Property<int>("AcademicCourse")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
@ -811,8 +811,8 @@ namespace DatabaseCore.Migrations
b.Property<DateTime?>("DateDelete")
.HasColumnType("datetime2");
b.Property<int>("EnrollmentYear")
.HasColumnType("int");
b.Property<Guid>("EducationDirectionId")
.HasColumnType("uniqueidentifier");
b.Property<int>("GroupNumber")
.HasColumnType("int");
@ -827,7 +827,7 @@ namespace DatabaseCore.Migrations
b.HasIndex("LecturerId");
b.HasIndex("AcademicPlanId", "EnrollmentYear", "GroupNumber")
b.HasIndex("EducationDirectionId", "AcademicCourse", "GroupNumber")
.IsUnique();
b.ToTable("StudentGroups");
@ -1278,9 +1278,9 @@ namespace DatabaseCore.Migrations
modelBuilder.Entity("DatabaseCore.Models.Department.StudentGroup", b =>
{
b.HasOne("DatabaseCore.Models.Department.AcademicPlan", "AcademicPlan")
b.HasOne("DatabaseCore.Models.Department.EducationDirection", "EducationDirection")
.WithMany("StudentGroups")
.HasForeignKey("AcademicPlanId")
.HasForeignKey("EducationDirectionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -1288,7 +1288,7 @@ namespace DatabaseCore.Migrations
.WithMany("StudentGroups")
.HasForeignKey("LecturerId");
b.Navigation("AcademicPlan");
b.Navigation("EducationDirection");
b.Navigation("Lecturer");
});
@ -1337,8 +1337,6 @@ namespace DatabaseCore.Migrations
modelBuilder.Entity("DatabaseCore.Models.Department.AcademicPlan", b =>
{
b.Navigation("AcademicPlanRecords");
b.Navigation("StudentGroups");
});
modelBuilder.Entity("DatabaseCore.Models.Department.AcademicPlanRecord", b =>
@ -1361,6 +1359,8 @@ namespace DatabaseCore.Migrations
modelBuilder.Entity("DatabaseCore.Models.Department.EducationDirection", b =>
{
b.Navigation("AcademicPlans");
b.Navigation("StudentGroups");
});
modelBuilder.Entity("DatabaseCore.Models.Department.Employee", b =>

View File

@ -39,9 +39,6 @@ namespace DatabaseCore.Models.Department
[ForeignKey("AcademicPlanId")]
public virtual List<AcademicPlanRecord> AcademicPlanRecords { get; set; }
[ForeignKey("AcademicPlanId")]
public virtual List<StudentGroup> StudentGroups { get; set; }
//-------------------------------------------------------------------------
public AcademicPlan SecurityCheck(AcademicPlan entity, bool allowFullData) => entity;

View File

@ -56,6 +56,9 @@ namespace DatabaseCore.Models.Department
[ForeignKey("EducationDirectionId")]
public virtual List<AcademicPlan> AcademicPlans { get; set; }
[ForeignKey("EducationDirectionId")]
public virtual List<StudentGroup> StudentGroups { get; set; }
//-------------------------------------------------------------------------
public EducationDirection SecurityCheck(EducationDirection entity, bool allowFullData) => entity;

View File

@ -14,14 +14,14 @@ namespace DatabaseCore.Models.Department
/// </summary>
[DataContract]
[EntityDescription("StudentGroup", "Учебная группа кафедры")]
[EntityDependency("AcademicPlan", "AcademicPlanId", "Учебный план, по которму учится группа")]
[EntityDependency("EducationDirection", "EducationDirectionId", "Направление, по которому учится группа")]
[EntityDependency("Lecturer", "LecturerId", "Куратор группы")]
public class StudentGroup : BaseEntity, IEntitySecurityExtenstion<StudentGroup>
{
[DataMember]
[Required(ErrorMessage = "required")]
[MapConfiguration("AcademicPlanId")]
public Guid AcademicPlanId { get; set; }
[MapConfiguration("EducationDirectionId")]
public Guid EducationDirectionId { get; set; }
[DataMember]
[Required(ErrorMessage = "required")]
@ -30,8 +30,8 @@ namespace DatabaseCore.Models.Department
[DataMember]
[Required(ErrorMessage = "required")]
[MapConfiguration("EnrollmentYear")]
public int EnrollmentYear { get; set; }
[MapConfiguration("AcademicCourse")]
public int AcademicCourse { get; set; }
[DataMember]
[MapConfiguration("LecturerId")]
@ -39,7 +39,7 @@ namespace DatabaseCore.Models.Department
//-------------------------------------------------------------------------
public virtual AcademicPlan AcademicPlan { get; set; }
public virtual EducationDirection EducationDirection { get; set; }
public virtual Lecturer Lecturer { get; set; }
@ -58,20 +58,6 @@ namespace DatabaseCore.Models.Department
public StudentGroup SecurityCheck(StudentGroup entity, bool allowFullData) => entity;
public override string ToString()
{
var builder = new StringBuilder();
builder.Append(AcademicPlan?.EducationDirection?.ShortName);
builder.Append('-');
var year = DateTime.Now.Year - EnrollmentYear;
if (DateTime.Now.Month > 8)
{
year++;
}
builder.Append(year);
builder.Append(GroupNumber);
return builder.ToString();
}
public override string ToString() => $"{EducationDirection?.ShortName}-{AcademicCourse}{GroupNumber}";
}
}

View File

@ -1,4 +1,5 @@
using ModuleTools.Attributes;
using DepartmentBusinessLogic.Enums;
using ModuleTools.Attributes;
using ModuleTools.BindingModels;
using System;
using System.ComponentModel.DataAnnotations;
@ -10,7 +11,7 @@ namespace DepartmentBusinessLogic.BindingModels
/// </summary>
public class StudentGroupGetBindingModel : GetBindingModel
{
public Guid? AcademicPlanId { get; set; }
public Guid? EducationDirectionId { get; set; }
public Guid? LecturerId { get; set; }
}
@ -21,16 +22,16 @@ namespace DepartmentBusinessLogic.BindingModels
public class StudentGroupSetBindingModel : SetBindingModel
{
[Required(ErrorMessage = "required")]
[MapConfiguration("AcademicPlanId")]
public Guid AcademicPlanId { get; set; }
[MapConfiguration("EducationDirectionId")]
public Guid EducationDirectionId { get; set; }
[Required(ErrorMessage = "required")]
[MapConfiguration("GroupNumber")]
public int GroupNumber { get; set; }
[Required(ErrorMessage = "required")]
[MapConfiguration("EnrollmentYear")]
public int EnrollmentYear { get; set; }
[MapConfiguration("AcademicCourse")]
public AcademicCourse AcademicCourse { get; set; }
[MapConfiguration("LecturerId")]
public Guid? LecturerId { get; set; }

View File

@ -0,0 +1,16 @@
namespace DepartmentBusinessLogic.Enums
{
/// <summary>
/// Учебный курс
/// </summary>
public enum AcademicCourse
{
Курс_1 = 1,
Курс_2 = 2,
Курс_3 = 3,
Курс_4 = 4
}
}

View File

@ -16,8 +16,6 @@ namespace DepartmentBusinessLogic.ViewModels
[ViewModelControlElementClass(HaveDependenceEntities = true, Width = 1200, Height = 800)]
[ViewModelControlElementDependenceEntity(Title = "Записи плана", Order = 1, ParentPropertyName = "AcademicPlanId",
ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlAcademicPlanRecordList, DepartmentWindowsDesktop")]
[ViewModelControlElementDependenceEntity(Title = "Группы", Order = 2, ParentPropertyName = "AcademicPlanId",
ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlStudentGroupList, DepartmentWindowsDesktop")]
public class AcademicPlanViewModel : ElementViewModel
{
[ViewModelControlElementProperty("Направление", ControlType.ControlGuid, MustHaveValue = false, ReadOnly = false, ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlEducationDirectionList, DepartmentWindowsDesktop")]

View File

@ -17,6 +17,8 @@ namespace DepartmentBusinessLogic.ViewModels
[ViewModelControlElementClass(HaveDependenceEntities = true, Width = 800, Height = 500)]
[ViewModelControlElementDependenceEntity(Title = "Учебные планы", Order = 1, ParentPropertyName = "EducationDirectionId",
ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlAcademicPlanList, DepartmentWindowsDesktop")]
[ViewModelControlElementDependenceEntity(Title = "Группы", Order = 2, ParentPropertyName = "EducationDirectionId",
ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlStudentGroupList, DepartmentWindowsDesktop")]
public class EducationDirectionViewModel : ElementViewModel
{
[ViewModelControlListProperty("Шифр", ColumnWidth = 80)]

View File

@ -1,8 +1,8 @@
using ModuleTools.Attributes;
using DepartmentBusinessLogic.Enums;
using ModuleTools.Attributes;
using ModuleTools.Enums;
using ModuleTools.ViewModels;
using System;
using System.Text;
namespace DepartmentBusinessLogic.ViewModels
{
@ -21,51 +21,36 @@ namespace DepartmentBusinessLogic.ViewModels
ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlOrderStudentRecordList, DepartmentWindowsDesktop")]
public class StudentGroupViewModel : ElementViewModel
{
[ViewModelControlElementProperty("Учебный план", ControlType.ControlGuid, MustHaveValue = true, ReadOnly = false, ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlAcademicPlanList, DepartmentWindowsDesktop")]
[MapConfiguration("AcademicPlanId")]
public Guid AcademicPlanId { get; set; }
[ViewModelControlElementProperty("Направление", ControlType.ControlGuid, MustHaveValue = true, ReadOnly = false, ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlEducationDirectionList, DepartmentWindowsDesktop")]
[MapConfiguration("EducationDirectionId")]
public Guid EducationDirectionId { get; set; }
[ViewModelControlListProperty("Шифр", ColumnWidth = 80)]
[MapConfiguration("AcademicPlan.EducationDirection.Cipher", IsDifficle = true)]
public string AcademicPlanEducationDirectionCipher { get; set; }
[MapConfiguration("EducationDirection.Cipher", IsDifficle = true)]
public string EducationDirectionCipher { get; set; }
[ViewModelControlListProperty("Профиль")]
[MapConfiguration("AcademicPlan.EducationDirection.Profile", IsDifficle = true)]
public string AcademicPlanEducationDirectionProfile { get; set; }
[MapConfiguration("EducationDirection.Profile", IsDifficle = true)]
public string EducationDirectionProfile { get; set; }
[MapConfiguration("AcademicPlan.EducationDirection.ShortName", IsDifficle = true)]
public string AcademicPlanEducationDirectionShortName { get; set; }
[MapConfiguration("EducationDirection.ShortName", IsDifficle = true)]
public string EducationDirectionShortName { get; set; }
[ViewModelControlListProperty("Группа")]
public string GroupName
{
get
{
var builder = new StringBuilder();
builder.Append(AcademicPlanEducationDirectionShortName);
builder.Append('-');
var year = DateTime.Now.Year - EnrollmentYear;
if (DateTime.Now.Month > 8)
{
year++;
}
builder.Append(year);
builder.Append(GroupNumber);
public string GroupName => $"{EducationDirectionShortName}-{(int)AcademicCourse}{GroupNumber}";
return builder.ToString();
}
}
[ViewModelControlElementProperty("Курс", ControlType.ControlEnum, MustHaveValue = true)]
[MapConfiguration("AcademicCourse")]
public AcademicCourse AcademicCourse { get; set; }
[ViewModelControlListProperty("Курс")]
public string AcademicCourseTitle => AcademicCourse.ToString("G");
[ViewModelControlListProperty("Номер группы")]
[ViewModelControlElementProperty("Номер группы", ControlType.ControlInt, MustHaveValue = true, MinValue = 1, MaxValue = 4)]
[ViewModelControlElementProperty("Номер группы", ControlType.ControlInt, MustHaveValue = true, MinValue = 0, MaxValue = 4)]
[MapConfiguration("GroupNumber")]
public int GroupNumber { get; set; }
[ViewModelControlListProperty("Год зачисления")]
[ViewModelControlElementProperty("Год зачисления", ControlType.ControlInt, MustHaveValue = true)]
[MapConfiguration("EnrollmentYear")]
public int EnrollmentYear { get; set; }
[ViewModelControlElementProperty("Куратор", ControlType.ControlGuid, MustHaveValue = false, ReadOnly = false, ControlTypeObject = "DepartmentWindowsDesktop.EntityControls.ControlLecturerList, DepartmentWindowsDesktop")]
[MapConfiguration("LecturerId")]
public Guid? LecturerId { get; set; }

View File

@ -12,8 +12,6 @@ using ModuleTools.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace DepartmentDatabaseImplementation.Implementations
@ -27,14 +25,7 @@ namespace DepartmentDatabaseImplementation.Implementations
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, AcademicPlanSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, AcademicPlan entity, AcademicPlanGetBindingModel model)
{
if (context.Set<StudentGroup>().Any(x => x.AcademicPlanId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Есть учебные группы, относящиеся к этому учебному плану", ResultServiceStatusCode.ExsistItem);
}
return OperationResultModel.Success(null);
}
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, AcademicPlan entity, AcademicPlanGetBindingModel model) => OperationResultModel.Success(null);
protected override IQueryable<AcademicPlan> AdditionalCheckingWhenReadingList(IQueryable<AcademicPlan> query, AcademicPlanGetBindingModel model)
{

View File

@ -26,6 +26,10 @@ namespace DepartmentDatabaseImplementation.Implementations
{
return OperationResultModel.Error("Error:", "Есть учебные планы, относящиеся к этому направлению", ResultServiceStatusCode.ExsistItem);
}
if (context.Set<StudentGroup>().Any(x => x.EducationDirectionId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Есть учебные группы, относящиеся к этому направлению", ResultServiceStatusCode.ExsistItem);
}
return OperationResultModel.Success(null);
}

View File

@ -31,9 +31,9 @@ namespace DepartmentDatabaseImplementation.Implementations
protected override IQueryable<StudentGroup> AdditionalCheckingWhenReadingList(IQueryable<StudentGroup> query, StudentGroupGetBindingModel model)
{
if (model.AcademicPlanId.HasValue)
if (model.EducationDirectionId.HasValue)
{
query = query.Where(x => x.AcademicPlanId == model.AcademicPlanId.Value);
query = query.Where(x => x.EducationDirectionId == model.EducationDirectionId.Value);
}
if (model.LecturerId.HasValue)
{
@ -55,10 +55,10 @@ namespace DepartmentDatabaseImplementation.Implementations
context.SaveChanges();
}
protected override StudentGroup GetUniqueEntity(StudentGroupSetBindingModel model, DbContext context) => context.Set<StudentGroup>().FirstOrDefault(x => x.AcademicPlanId == model.AcademicPlanId && x.EnrollmentYear == model.EnrollmentYear && x.GroupNumber == model.GroupNumber && x.Id != model.Id);
protected override StudentGroup GetUniqueEntity(StudentGroupSetBindingModel model, DbContext context) => context.Set<StudentGroup>().FirstOrDefault(x => x.EducationDirectionId == model.EducationDirectionId && x.AcademicCourse == (int)model.AcademicCourse && x.GroupNumber == model.GroupNumber && x.Id != model.Id);
protected override IQueryable<StudentGroup> IncludingWhenReading(IQueryable<StudentGroup> query) => query.Include(x => x.AcademicPlan).Include(x => x.AcademicPlan.EducationDirection).Include(x => x.Lecturer);
protected override IQueryable<StudentGroup> IncludingWhenReading(IQueryable<StudentGroup> query) => query.Include(x => x.EducationDirection).Include(x => x.Lecturer);
protected override IQueryable<StudentGroup> OrderingWhenReading(IQueryable<StudentGroup> query) => query.OrderBy(x => x.AcademicPlan.EducationDirection.Cipher).ThenBy(x => x.EnrollmentYear).ThenBy(x => x.GroupNumber);
protected override IQueryable<StudentGroup> OrderingWhenReading(IQueryable<StudentGroup> query) => query.OrderBy(x => x.EducationDirection.Cipher).ThenBy(x => x.AcademicCourse).ThenBy(x => x.GroupNumber);
}
}

View File

@ -55,6 +55,6 @@ namespace DepartmentDatabaseImplementation.Implementations
protected override IQueryable<Student> IncludingWhenReading(IQueryable<Student> query) => query.Include(x => x.StudentGroup).Include(x => x.User);
protected override IQueryable<Student> OrderingWhenReading(IQueryable<Student> query) => query.OrderBy(x => x.StudentGroup.EnrollmentYear).ThenBy(x => x.StudentGroup.GroupNumber).ThenBy(x => x.LastName).ThenBy(x => x.FirstName);
protected override IQueryable<Student> OrderingWhenReading(IQueryable<Student> query) => query.OrderBy(x => x.StudentGroup.AcademicCourse).ThenBy(x => x.StudentGroup.GroupNumber).ThenBy(x => x.LastName).ThenBy(x => x.FirstName);
}
}