update models
This commit is contained in:
@@ -10,10 +10,11 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
{
|
||||
string Title { get; }
|
||||
string Description { get; }
|
||||
string TaskName { get; }
|
||||
string? TaskName { get; }
|
||||
DateTime DateCreate { get; }
|
||||
int TaskId { get; }
|
||||
int? TaskId { get; }
|
||||
int StudentId { get; }
|
||||
string StudentName { get; }
|
||||
Dictionary<int, IInterest> DiyInterests { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
{
|
||||
string Title { get; }
|
||||
string Description { get; }
|
||||
|
||||
int StudentId { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,10 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
{
|
||||
string Title { get; }
|
||||
DateTime DateEvent { get; }
|
||||
int ProductId { get; }
|
||||
string ProductName { get; }
|
||||
int? ProductId { get; }
|
||||
string? ProductName { get; }
|
||||
int TeacherId { get; }
|
||||
string TeacherName { get; }
|
||||
Dictionary<int, IMaterial> LessonMaterials { get; }
|
||||
|
||||
}
|
||||
|
||||
@@ -10,5 +10,6 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
{
|
||||
string Title { get; }
|
||||
string SphereUse { get; }
|
||||
int TeacherId { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
string Description { get; }
|
||||
DateTime DateCreate { get; }
|
||||
int StudentId { get; }
|
||||
string StudentName { get; }
|
||||
Dictionary<int, IInterest> ProductInterests { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
string Email { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
Dictionary<int, IInterest> StudentInterests { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
DateTime DateIssue { get;}
|
||||
DateTime DateDelivery { get;}
|
||||
int TeacherId { get; }
|
||||
string TeacherName { get; }
|
||||
Dictionary<int, IMaterial> TaskMaterials { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,5 @@ namespace SchoolAgainStudyDataModels.Models
|
||||
string Phone { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
Dictionary<int, IMaterial> TeacherMaterials { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,15 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SchoolAgainStudyDataBaseImplements\SchoolAgainStudyDataBaseImplements.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -15,10 +15,11 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
public int TaskId { get; set; }
|
||||
public string TaskName { get; set; } = string.Empty;
|
||||
public int? TaskId { get; set; }
|
||||
public string? TaskName { get; set; } = string.Empty;
|
||||
|
||||
public int StudentId { get; set; }
|
||||
public string StudentName { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IInterest> DiyInterests { get; set; } = new();
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public int StudentId { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
|
||||
public DateTime DateEvent { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public int? ProductId { get; set; }
|
||||
public string? ProductName { get; set; } = string.Empty;
|
||||
|
||||
public int TeacherId { get; set; }
|
||||
public string TeacherName { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IMaterial> LessonMaterials { get; set; } = new();
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public string SphereUse { get; set; } = string.Empty;
|
||||
public int TeacherId { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
public int StudentId { get; set; }
|
||||
public string StudentName { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IInterest> ProductInterests { get; set; } = new();
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IInterest> StudentInterests { get; set; } = new() ;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public int TeacherId { get; set; }
|
||||
public string TeacherName { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IMaterial> TaskMaterials { get; set; } = new();
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ namespace SchoolAgainStudyContracts.BindingModel
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IMaterial> TeacherMaterials { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace SchoolAgainStudyContracts.BusinessLogicContracts
|
||||
List<ReportInterestLessonViewModel> GetInterestLesson();
|
||||
|
||||
|
||||
List<ReportInterestViewModel> GetOrders(ReportBindingModel model);
|
||||
List<ReportInterestViewModel> GetInterests(ReportBindingModel model);
|
||||
List<ReportDiyMaterialViewModel> GetDiyMaterial();
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace SchoolAgainStudyContracts.SearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public int? StudentId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace SchoolAgainStudyContracts.SearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public int? StudentId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace SchoolAgainStudyContracts.SearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public int? TeacherId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
@@ -10,5 +10,6 @@ namespace SchoolAgainStudyContracts.SearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public int? TeacherId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace SchoolAgainStudyContracts.SearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public int? StudentId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace SchoolAgainStudyContracts.SearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public int? TeacherId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
@@ -17,9 +17,11 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
public int TaskId { get; set; }
|
||||
public int? TaskId { get; set; }
|
||||
[DisplayName("Задание")]
|
||||
public string TaskName { get; set; } = string.Empty;
|
||||
public string? TaskName { get; set; } = string.Empty;
|
||||
[DisplayName("Школьник")]
|
||||
public string StudentName { get; set; } = string.Empty;
|
||||
|
||||
public int StudentId { get; set; }
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
{
|
||||
public class InterestViewModel : IInterest
|
||||
{
|
||||
public int StudentId { get; set; }
|
||||
[DisplayName("Название")]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
[DisplayName("Описание")]
|
||||
|
||||
@@ -15,9 +15,11 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
[DisplayName("Дата проведения")]
|
||||
public DateTime DateEvent { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int? ProductId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public string? ProductName { get; set; } = string.Empty;
|
||||
[DisplayName("Учитель")]
|
||||
public string TeacherName { get; set; } = string.Empty;
|
||||
|
||||
public int TeacherId { get; set; }
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
{
|
||||
public class MaterialViewModel : IMaterial
|
||||
{
|
||||
public int TeacherId { get; set; }
|
||||
[DisplayName("Название")]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
[DisplayName("Сфера использования")]
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
public int StudentId { get; set; }
|
||||
[DisplayName("Школьник")]
|
||||
public string StudentName { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IInterest> ProductInterests { get; set; } = new();
|
||||
[DisplayName("Номер")]
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IInterest> StudentInterests { get; set; } = new() ;
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
public DateTime DateIssue { get; set; }
|
||||
[DisplayName("Дата сдачи")]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
[DisplayName("Учитель")]
|
||||
public string TeacherName { get; set; } = string.Empty;
|
||||
|
||||
public int TeacherId { get; set; }
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace SchoolAgainStudyContracts.ViewModel
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IMaterial> TeacherMaterials { get; set; } = new();
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
@@ -22,10 +22,13 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; }
|
||||
[Required]
|
||||
public int TaskId { get; set; }
|
||||
public string TaskName { get; set; } = string.Empty;
|
||||
public virtual Task task { get; set; }
|
||||
public int? TaskId { get; set; }
|
||||
public string? TaskName { get; set; } = string.Empty;
|
||||
public virtual Task Task { get; set; }
|
||||
[Required]
|
||||
public int StudentId { get; set; }
|
||||
public string StudentName { get; set; } = string.Empty;
|
||||
public virtual Student Student { get; set; }
|
||||
private Dictionary<int, IInterest>? _DiyInterests = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IInterest> DiyInterests {
|
||||
@@ -54,6 +57,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
TaskId = model.TaskId,
|
||||
TaskName = model.TaskName,
|
||||
StudentId = model.StudentId,
|
||||
StudentName = model.StudentName,
|
||||
Interests = model.DiyInterests.Select(x => new DiyInterest
|
||||
{
|
||||
Interest = context.Interests.First(y => y.Id == x.Key),
|
||||
@@ -77,6 +81,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
TaskId = TaskId,
|
||||
TaskName = TaskName,
|
||||
StudentId = StudentId,
|
||||
StudentName = StudentName,
|
||||
DiyInterests=DiyInterests
|
||||
};
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("InterestId")]
|
||||
public virtual List<StudentInterest> StudentInterests { get; set; } = new();
|
||||
[Required]
|
||||
public int StudentId { get; set; }
|
||||
public virtual Student Student { get; set; }
|
||||
[ForeignKey("InterestId")]
|
||||
public virtual List<DiyInterest> DiyInterests { get; set; } = new();
|
||||
[ForeignKey("InterestId")]
|
||||
@@ -37,19 +38,11 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
Description = model.Description
|
||||
Description = model.Description,
|
||||
StudentId = model.StudentId,
|
||||
};
|
||||
}
|
||||
|
||||
public static Interest Create(InterestViewModel model)
|
||||
{
|
||||
return new Interest
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
Description = model.Description
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(InterestBindingModel model)
|
||||
{
|
||||
@@ -65,7 +58,8 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
Id = Id,
|
||||
Title = Title,
|
||||
Description = Description
|
||||
Description = Description,
|
||||
StudentId = StudentId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,15 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
[Required]
|
||||
public DateTime DateEvent { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
public int? ProductId { get; set; }
|
||||
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public string? ProductName { get; set; } = string.Empty;
|
||||
|
||||
public virtual Product product { get; set; }
|
||||
public virtual Product Product { get; set; }
|
||||
[Required]
|
||||
public int TeacherId { get; set; }
|
||||
public string TeacherName { get; set; } = string.Empty;
|
||||
public virtual Teacher Teacher { get; set; }
|
||||
private Dictionary<int, IMaterial>? _LessonMaterials = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMaterial> LessonMaterials
|
||||
@@ -52,6 +55,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
ProductId = model.ProductId,
|
||||
ProductName = model.ProductName,
|
||||
TeacherId = model.TeacherId,
|
||||
TeacherName=model.TeacherName,
|
||||
Materials = model.LessonMaterials.Select(x => new LessonMaterial
|
||||
{
|
||||
Material = context.Materials.First(y => y.Id == x.Key),
|
||||
@@ -73,6 +77,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
ProductId = ProductId,
|
||||
ProductName = ProductName,
|
||||
TeacherId = TeacherId,
|
||||
TeacherName=TeacherName,
|
||||
LessonMaterials = LessonMaterials
|
||||
};
|
||||
|
||||
|
||||
@@ -17,15 +17,16 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
public string Title { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string SphereUse { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int TeacherId { get; set; }
|
||||
public virtual Teacher Teacher { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("MaterialId")]
|
||||
public virtual List<LessonMaterial> LessonMaterials { get; set; } = new();
|
||||
[ForeignKey("MaterialId")]
|
||||
public virtual List<TaskMaterial> TaskMaterial { get; set; } = new();
|
||||
[ForeignKey("MaterialId")]
|
||||
public virtual List<TeacherMaterial> TeacherMaterial { get; set; } = new();
|
||||
|
||||
|
||||
public static Material? Create(MaterialBindingModel model)
|
||||
{
|
||||
@@ -37,7 +38,8 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
SphereUse = model.SphereUse
|
||||
SphereUse = model.SphereUse,
|
||||
TeacherId = model.TeacherId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,7 +49,8 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
Title = model.Title,
|
||||
SphereUse = model.SphereUse
|
||||
SphereUse = model.SphereUse,
|
||||
TeacherId=model.TeacherId
|
||||
};
|
||||
}
|
||||
|
||||
@@ -65,7 +68,8 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
Id = Id,
|
||||
Title = Title,
|
||||
SphereUse = SphereUse
|
||||
SphereUse = SphereUse,
|
||||
TeacherId = TeacherId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
public string Description { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; }
|
||||
[Required]
|
||||
public int StudentId { get; set; }
|
||||
public string StudentName { get; set; } = string.Empty;
|
||||
public virtual Student Student { get; set; }
|
||||
private Dictionary<int, IInterest>? _ProductInterests = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IInterest> ProductInterests
|
||||
@@ -49,6 +52,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
Description = model.Description,
|
||||
DateCreate = model.DateCreate,
|
||||
StudentId = model.StudentId,
|
||||
StudentName=model.StudentName,
|
||||
Interests = model.ProductInterests.Select(x => new ProductInterest
|
||||
{
|
||||
Interest = context.Interests.First(y => y.Id == x.Key),
|
||||
@@ -70,6 +74,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
Description = Description,
|
||||
DateCreate = DateCreate,
|
||||
StudentId = StudentId,
|
||||
StudentName = StudentName,
|
||||
ProductInterests = ProductInterests
|
||||
};
|
||||
|
||||
|
||||
@@ -26,25 +26,10 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
private Dictionary<int, IInterest>? _StudentInterests = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IInterest> StudentInterests
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_StudentInterests == null)
|
||||
{
|
||||
_StudentInterests = Interests
|
||||
.ToDictionary(recPC => recPC.InterestId, recPC => (recPC.Interest as IInterest));
|
||||
}
|
||||
return _StudentInterests;
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("StudentId")]
|
||||
public virtual List<StudentInterest> Interests { get; set; } = new();
|
||||
public virtual List<Interest> Interests { get; set; } = new();
|
||||
[ForeignKey("StudentId")]
|
||||
public virtual List<Diy> Diys { get; set; } = new();
|
||||
[ForeignKey("StudentId")]
|
||||
@@ -59,10 +44,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
Email = model.Email,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
Interests = model.StudentInterests.Select(x => new StudentInterest
|
||||
{
|
||||
Interest = context.Interests.First(y => y.Id == x.Key),
|
||||
}).ToList()
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -82,35 +64,10 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
Class = Class,
|
||||
Email = Email,
|
||||
Login = Login,
|
||||
Password = Password,
|
||||
StudentInterests = StudentInterests
|
||||
Password = Password
|
||||
|
||||
};
|
||||
|
||||
public void UpdateInterests(SchoolDataBase context, StudentBindingModel model)
|
||||
{
|
||||
var studentInterests = context.StudentInterests.Where(rec => rec.StudentId == model.Id).ToList();
|
||||
if (studentInterests != null && studentInterests.Count > 0)
|
||||
{
|
||||
context.StudentInterests.RemoveRange(studentInterests.Where(rec => !model.StudentInterests.ContainsKey(rec.InterestId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateInterest in studentInterests)
|
||||
{
|
||||
model.StudentInterests.Remove(updateInterest.InterestId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var student = context.Students.First(x => x.Id == Id);
|
||||
foreach (var pc in model.StudentInterests)
|
||||
{
|
||||
context.StudentInterests.Add(new StudentInterest
|
||||
{
|
||||
Student = student,
|
||||
Interest = context.Interests.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_StudentInterests = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class StudentInterest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int StudentId { get; set; }
|
||||
[Required]
|
||||
public int InterestId { get; set; }
|
||||
public virtual Student Student { get; set; } = new();
|
||||
public virtual Interest Interest { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,10 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
public DateTime DateIssue { get; set; }
|
||||
[Required]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
[Required]
|
||||
public int TeacherId { get; set; }
|
||||
public string TeacherName { get; set; } = string.Empty;
|
||||
public virtual Teacher Teacher { get; set; }
|
||||
private Dictionary<int, IMaterial>? _TaskMaterials = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMaterial> TaskMaterials { get
|
||||
@@ -49,6 +51,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
DateIssue = model.DateIssue,
|
||||
DateDelivery = model.DateDelivery,
|
||||
TeacherId = model.TeacherId,
|
||||
TeacherName = model.TeacherName,
|
||||
Materials = model.TaskMaterials.Select(x => new TaskMaterial
|
||||
{
|
||||
Material = context.Materials.First(y => y.Id == x.Key),
|
||||
@@ -70,6 +73,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
DateIssue = DateIssue,
|
||||
DateDelivery = DateDelivery,
|
||||
TeacherId = TeacherId,
|
||||
TeacherName= TeacherName,
|
||||
TaskMaterials = TaskMaterials
|
||||
};
|
||||
|
||||
|
||||
@@ -24,23 +24,10 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
private Dictionary<int, IMaterial>? _TeacherMaterials = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMaterial> TeacherMaterials {
|
||||
get
|
||||
{
|
||||
if (_TeacherMaterials == null)
|
||||
{
|
||||
_TeacherMaterials = Materials
|
||||
.ToDictionary(recPC => recPC.MaterialId, recPC => (recPC.Material as IMaterial));
|
||||
}
|
||||
return _TeacherMaterials;
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("TeacherId")]
|
||||
public virtual List<TeacherMaterial> Materials { get; set; } = new();
|
||||
public virtual List<Material> Materials { get; set; } = new();
|
||||
[ForeignKey("TeacherId")]
|
||||
public virtual List<Task> Tasks { get; set; } = new();
|
||||
[ForeignKey("TeacherId")]
|
||||
@@ -55,10 +42,7 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
Phone = model.Phone,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
Materials = model.TeacherMaterials.Select(x => new TeacherMaterial
|
||||
{
|
||||
Material = context.Materials.First(y => y.Id == x.Key),
|
||||
}).ToList()
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,34 +63,9 @@ namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
Phone = Phone,
|
||||
Login = Login,
|
||||
Password = Password,
|
||||
TeacherMaterials = TeacherMaterials
|
||||
|
||||
};
|
||||
|
||||
public void UpdateMaterials(SchoolDataBase context, TeacherBindingModel model)
|
||||
{
|
||||
var teacherMaterials = context.TeacherMaterials.Where(rec => rec.TeacherId == model.Id).ToList();
|
||||
if (teacherMaterials != null && teacherMaterials.Count > 0)
|
||||
{
|
||||
context.TeacherMaterials.RemoveRange(teacherMaterials.Where(rec => !model.TeacherMaterials.ContainsKey(rec.MaterialId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateMaterial in teacherMaterials)
|
||||
{
|
||||
model.TeacherMaterials.Remove(updateMaterial.MaterialId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var teacher = context.Teachers.First(x => x.Id == Id);
|
||||
foreach (var pc in model.TeacherMaterials)
|
||||
{
|
||||
context.TeacherMaterials.Add(new TeacherMaterial
|
||||
{
|
||||
Teacher = teacher,
|
||||
Material = context.Materials.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_TeacherMaterials = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolAgainStudyDataBaseImplements.Models
|
||||
{
|
||||
public class TeacherMaterial
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int TeacherId { get; set; }
|
||||
[Required]
|
||||
public int MaterialId { get; set; }
|
||||
public virtual Teacher Teacher { get; set; } = new();
|
||||
public virtual Material Material { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -20,4 +20,8 @@
|
||||
<ProjectReference Include="..\SchoolAgainStudyContracts\SchoolAgainStudyContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -24,8 +24,6 @@ namespace SchoolAgainStudyDataBaseImplements
|
||||
|
||||
public virtual DbSet<Student> Students { set; get; }
|
||||
|
||||
public virtual DbSet<StudentInterest> StudentInterests { set; get; }
|
||||
|
||||
public virtual DbSet<Interest> Interests { set; get; }
|
||||
|
||||
public virtual DbSet<Diy> Diys { set; get; }
|
||||
@@ -35,8 +33,6 @@ namespace SchoolAgainStudyDataBaseImplements
|
||||
|
||||
public virtual DbSet<Teacher> Teachers { set; get; }
|
||||
|
||||
public virtual DbSet<TeacherMaterial> TeacherMaterials { set; get; }
|
||||
|
||||
public virtual DbSet<Material> Materials { set; get; }
|
||||
|
||||
public virtual DbSet<Lesson> Lessons { set; get; }
|
||||
|
||||
Reference in New Issue
Block a user