Добавил сущности второй роли
This commit is contained in:
parent
9a74447419
commit
4237b97343
@ -13,6 +13,11 @@ namespace SchoolApp.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
|
@ -11,6 +11,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.16" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
7
School/SchoolApp/Views/Home/Register.cshtml
Normal file
7
School/SchoolApp/Views/Home/Register.cshtml
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Redister";
|
||||
}
|
||||
|
||||
<h1>Register</h1>
|
||||
|
115
School/SchoolBusinessLogic/BusinessLogic/ClubLogic.cs
Normal file
115
School/SchoolBusinessLogic/BusinessLogic/ClubLogic.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.BusinessLogicsContracts;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.StoragesContracts;
|
||||
using SchoolContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ClubLogic : IClubLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClubStorage _ClubStorage;
|
||||
public ClubLogic(ILogger<ClubLogic> logger, IClubStorage
|
||||
ClubStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_ClubStorage = ClubStorage;
|
||||
}
|
||||
public List<ClubViewModel>? ReadList(ClubSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ClubName:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _ClubStorage.GetFullList() :
|
||||
_ClubStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list?.Count);
|
||||
return list;
|
||||
}
|
||||
public ClubViewModel? ReadElement(ClubSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ClubName:{Name}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _ClubStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(ClubBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_ClubStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ClubBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_ClubStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ClubBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_ClubStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ClubBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия кружка",
|
||||
nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Club. ClubName:{ClubName}Id: { Id}", model.Name, model.Id);
|
||||
var element = _ClubStorage.GetElement(new ClubSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Кружок с таким именем уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
115
School/SchoolBusinessLogic/BusinessLogic/MaterialLogic.cs
Normal file
115
School/SchoolBusinessLogic/BusinessLogic/MaterialLogic.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.BusinessLogicsContracts;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.StoragesContracts;
|
||||
using SchoolContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class MaterialLogic : IMaterialLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMaterialStorage _MaterialStorage;
|
||||
public MaterialLogic(ILogger<MaterialLogic> logger, IMaterialStorage
|
||||
MaterialStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_MaterialStorage = MaterialStorage;
|
||||
}
|
||||
public List<MaterialViewModel>? ReadList(MaterialSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. MaterialName:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _MaterialStorage.GetFullList() :
|
||||
_MaterialStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list?.Count);
|
||||
return list;
|
||||
}
|
||||
public MaterialViewModel? ReadElement(MaterialSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. MaterialName:{Name}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _MaterialStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(MaterialBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_MaterialStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(MaterialBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_MaterialStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(MaterialBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_MaterialStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(MaterialBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия материала",
|
||||
nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Material. MaterialName:{MaterialName}Id: { Id}", model.Name, model.Id);
|
||||
var element = _MaterialStorage.GetElement(new MaterialSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Материал с таким именем уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ namespace SchoolBusinessLogic.BusinessLogic
|
||||
}
|
||||
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. UserName:{UserName}.Id:{ Id}", model?.Name, model?.Id);
|
||||
_logger.LogInformation("ReadList. UserName:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _UserStorage.GetFullList() :
|
||||
_UserStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
|
20
School/SchoolContracts/BindingModels/ClubBindingModel.cs
Normal file
20
School/SchoolContracts/BindingModels/ClubBindingModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.BindingModels
|
||||
{
|
||||
public class ClubBindingModel : IClubModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public Dictionary<int, ILessonModel> ClubLessons
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
@ -18,5 +18,11 @@ namespace SchoolContracts.BindingModels
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
|
||||
public Dictionary<int, IMaterialModel> InterestMaterials
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
||||
|
15
School/SchoolContracts/BindingModels/MaterialBindingModel.cs
Normal file
15
School/SchoolContracts/BindingModels/MaterialBindingModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.BindingModels
|
||||
{
|
||||
public class MaterialBindingModel : IMaterialModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
20
School/SchoolContracts/BusinessLogicsContracts/IClubLogic.cs
Normal file
20
School/SchoolContracts/BusinessLogicsContracts/IClubLogic.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IClubLogic
|
||||
{
|
||||
List<ClubViewModel>? ReadList(ClubSearchModel? model);
|
||||
ClubViewModel? ReadElement(ClubSearchModel model);
|
||||
bool Create(ClubBindingModel model);
|
||||
bool Update(ClubBindingModel model);
|
||||
bool Delete(ClubBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IMaterialLogic
|
||||
{
|
||||
List<MaterialViewModel>? ReadList(MaterialSearchModel? model);
|
||||
MaterialViewModel? ReadElement(MaterialSearchModel model);
|
||||
bool Create(MaterialBindingModel model);
|
||||
bool Update(MaterialBindingModel model);
|
||||
bool Delete(MaterialBindingModel model);
|
||||
}
|
||||
}
|
14
School/SchoolContracts/SearchModels/ClubSearchModel.cs
Normal file
14
School/SchoolContracts/SearchModels/ClubSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.SearchModels
|
||||
{
|
||||
public class ClubSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
14
School/SchoolContracts/SearchModels/MaterialSearchModel.cs
Normal file
14
School/SchoolContracts/SearchModels/MaterialSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.SearchModels
|
||||
{
|
||||
public class MaterialSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
21
School/SchoolContracts/StoragesContracts/IClubStorage.cs
Normal file
21
School/SchoolContracts/StoragesContracts/IClubStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.StoragesContracts
|
||||
{
|
||||
public interface IClubStorage
|
||||
{
|
||||
List<ClubViewModel> GetFullList();
|
||||
List<ClubViewModel> GetFilteredList(ClubSearchModel model);
|
||||
ClubViewModel? GetElement(ClubSearchModel model);
|
||||
ClubViewModel? Insert(ClubBindingModel model);
|
||||
ClubViewModel? Update(ClubBindingModel model);
|
||||
ClubViewModel? Delete(ClubBindingModel model);
|
||||
}
|
||||
}
|
21
School/SchoolContracts/StoragesContracts/IMaterialStorage.cs
Normal file
21
School/SchoolContracts/StoragesContracts/IMaterialStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.StoragesContracts
|
||||
{
|
||||
public interface IMaterialStorage
|
||||
{
|
||||
List<MaterialViewModel> GetFullList();
|
||||
List<MaterialViewModel> GetFilteredList(MaterialSearchModel model);
|
||||
MaterialViewModel? GetElement(MaterialSearchModel model);
|
||||
MaterialViewModel? Insert(MaterialBindingModel model);
|
||||
MaterialViewModel? Update(MaterialBindingModel model);
|
||||
MaterialViewModel? Delete(MaterialBindingModel model);
|
||||
}
|
||||
}
|
22
School/SchoolContracts/ViewModels/ClubViewModel.cs
Normal file
22
School/SchoolContracts/ViewModels/ClubViewModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.ViewModels
|
||||
{
|
||||
public class ClubViewModel : IClubModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название кружка")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public Dictionary<int, ILessonModel> ClubLessons
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
@ -22,5 +22,11 @@ namespace SchoolContracts.ViewModels
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
|
||||
public Dictionary<int, IMaterialModel> InterestMaterials
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
||||
|
17
School/SchoolContracts/ViewModels/MaterialViewModel.cs
Normal file
17
School/SchoolContracts/ViewModels/MaterialViewModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.ViewModels
|
||||
{
|
||||
public class MaterialViewModel : IMaterialModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название материала")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
61
School/SchoolDatabaseImplement/Models/Club.cs
Normal file
61
School/SchoolDatabaseImplement/Models/Club.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.ViewModels;
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement.Models
|
||||
{
|
||||
public class Club : IClubModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
private Dictionary<int, ILessonModel>? _ClubLessons = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, ILessonModel> ClubLessons
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ClubLessons == null)
|
||||
{
|
||||
_ClubLessons = Lessons.ToDictionary(recPC => recPC.LessonId, recPC => recPC.Lesson as ILessonModel);
|
||||
}
|
||||
return _ClubLessons;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ClubId")]
|
||||
public virtual List<ClubLesson> Lessons { get; set; } = new();
|
||||
public static Club? Create(ClubBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Club()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name
|
||||
};
|
||||
}
|
||||
public void Update(ClubBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
}
|
||||
public ClubViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name
|
||||
};
|
||||
}
|
||||
}
|
16
School/SchoolDatabaseImplement/Models/ClubLesson.cs
Normal file
16
School/SchoolDatabaseImplement/Models/ClubLesson.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SchoolDatabaseImplement.Models
|
||||
{
|
||||
public class ClubLesson
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int ClubId { get; set; }
|
||||
[Required]
|
||||
public int LessonId { get; set; }
|
||||
[Required]
|
||||
public virtual Lesson Lesson { get; set; } = new();
|
||||
public virtual Club Club { get; set; } = new();
|
||||
}
|
||||
}
|
@ -36,6 +36,25 @@ namespace SchoolDatabaseImplement.Models
|
||||
}
|
||||
[ForeignKey("InterestId")]
|
||||
public virtual List<InterestLesson> Lessons { get; set; } = new();
|
||||
|
||||
|
||||
[Required]
|
||||
private Dictionary<int, IMaterialModel>? _InterestMaterials = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMaterialModel> InterestMaterials
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_InterestMaterials == null)
|
||||
{
|
||||
_InterestMaterials = Materials.ToDictionary(recPC => recPC.MaterialId, recPC => recPC.Material as IMaterialModel) ;
|
||||
}
|
||||
return _InterestMaterials;
|
||||
}
|
||||
}
|
||||
[ForeignKey("InterestId")]
|
||||
public virtual List<InterestMaterial> Materials { get; set; } = new();
|
||||
|
||||
public static Interest Create(SchoolDatabase context, InterestBindingModel model)
|
||||
{
|
||||
return new Interest()
|
||||
@ -64,6 +83,9 @@ namespace SchoolDatabaseImplement.Models
|
||||
Description = Description,
|
||||
InterestLessons = InterestLessons
|
||||
};
|
||||
|
||||
|
||||
|
||||
public void UpdateLessons(SchoolDatabase context,
|
||||
InterestBindingModel model)
|
||||
{
|
||||
|
21
School/SchoolDatabaseImplement/Models/InterestMaterial.cs
Normal file
21
School/SchoolDatabaseImplement/Models/InterestMaterial.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement.Models
|
||||
{
|
||||
public class InterestMaterial
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int InterestId { get; set; }
|
||||
[Required]
|
||||
public int MaterialId { get; set; }
|
||||
[Required]
|
||||
public virtual Material Material { get; set; } = new();
|
||||
public virtual Interest Interest { get; set; } = new();
|
||||
}
|
||||
}
|
48
School/SchoolDatabaseImplement/Models/Material.cs
Normal file
48
School/SchoolDatabaseImplement/Models/Material.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.ViewModels;
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement.Models
|
||||
{
|
||||
public class Material : IMaterialModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[ForeignKey("MaterialId")]
|
||||
public virtual List<InterestMaterial> InterestMaterials { get; set; } = new();
|
||||
public static Material? Create(MaterialBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Material()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name
|
||||
};
|
||||
}
|
||||
public void Update(MaterialBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
}
|
||||
public MaterialViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name
|
||||
};
|
||||
}
|
||||
}
|
15
School/SchoolsDataModels/Models/IClubModel.cs
Normal file
15
School/SchoolsDataModels/Models/IClubModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDataModels.Models
|
||||
{
|
||||
public interface IClubModel
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
Dictionary<int, ILessonModel> ClubLessons { get; }
|
||||
}
|
||||
}
|
@ -15,5 +15,7 @@ namespace SchoolDataModels.Models
|
||||
string Description { get; }
|
||||
|
||||
Dictionary<int, ILessonModel> InterestLessons { get; }
|
||||
|
||||
Dictionary<int, IMaterialModel> InterestMaterials { get; }
|
||||
}
|
||||
}
|
||||
|
13
School/SchoolsDataModels/Models/IMaterialModel.cs
Normal file
13
School/SchoolsDataModels/Models/IMaterialModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDataModels.Models
|
||||
{
|
||||
public interface IMaterialModel
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user