Compare commits
11 Commits
main
...
ConnectDat
Author | SHA1 | Date | |
---|---|---|---|
|
c28d6e23b3 | ||
|
4237b97343 | ||
|
9a74447419 | ||
|
78516eef25 | ||
|
5cec4e59ac | ||
|
609cc81c7a | ||
|
ac02c11334 | ||
|
0434c5f14c | ||
|
550ec77222 | ||
|
cb98039241 | ||
|
78ffb8ff1b |
@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32602.215
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolApp", "SchoolApp\SchoolApp.csproj", "{9E7F8CCA-B349-49EC-B85E-D54299CC2759}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolApp", "SchoolApp\SchoolApp.csproj", "{9E7F8CCA-B349-49EC-B85E-D54299CC2759}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolDataModels", "SchoolsDataModels\SchoolDataModels.csproj", "{ADBB4992-BE2F-4B10-83CC-335E5B92EA35}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolContracts", "SchoolContracts\SchoolContracts.csproj", "{D58B0AFE-E28D-4583-B9F1-C0EDF443243F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolBusinessLogic", "SchoolBusinessLogic\SchoolBusinessLogic.csproj", "{E78D42A3-7FA0-4E3A-B0C8-AEC70B3EE331}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolDatabaseImplement", "SchoolDatabaseImplement\SchoolDatabaseImplement.csproj", "{8C8F56D4-E267-498F-AFCD-06701962D09F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +23,22 @@ Global
|
||||
{9E7F8CCA-B349-49EC-B85E-D54299CC2759}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9E7F8CCA-B349-49EC-B85E-D54299CC2759}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9E7F8CCA-B349-49EC-B85E-D54299CC2759}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ADBB4992-BE2F-4B10-83CC-335E5B92EA35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ADBB4992-BE2F-4B10-83CC-335E5B92EA35}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ADBB4992-BE2F-4B10-83CC-335E5B92EA35}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ADBB4992-BE2F-4B10-83CC-335E5B92EA35}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D58B0AFE-E28D-4583-B9F1-C0EDF443243F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D58B0AFE-E28D-4583-B9F1-C0EDF443243F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D58B0AFE-E28D-4583-B9F1-C0EDF443243F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D58B0AFE-E28D-4583-B9F1-C0EDF443243F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E78D42A3-7FA0-4E3A-B0C8-AEC70B3EE331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E78D42A3-7FA0-4E3A-B0C8-AEC70B3EE331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E78D42A3-7FA0-4E3A-B0C8-AEC70B3EE331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E78D42A3-7FA0-4E3A-B0C8-AEC70B3EE331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8C8F56D4-E267-498F-AFCD-06701962D09F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8C8F56D4-E267-498F-AFCD-06701962D09F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8C8F56D4-E267-498F-AFCD-06701962D09F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8C8F56D4-E267-498F-AFCD-06701962D09F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -13,6 +13,11 @@ namespace SchoolApp.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@ -6,4 +6,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
|
||||
<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>
|
||||
<ProjectReference Include="..\SchoolBusinessLogic\SchoolBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\SchoolContracts\SchoolContracts.csproj" />
|
||||
<ProjectReference Include="..\SchoolDatabaseImplement\SchoolDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\SchoolsDataModels\SchoolDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
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>
|
||||
|
111
School/SchoolBusinessLogic/BusinessLogic/AchievementLogic.cs
Normal file
111
School/SchoolBusinessLogic/BusinessLogic/AchievementLogic.cs
Normal file
@ -0,0 +1,111 @@
|
||||
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 AchievementLogic : IAchievementLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IAchievementStorage _AchievementStorage;
|
||||
|
||||
public AchievementLogic(ILogger<AchievementLogic> logger, IAchievementStorage AchievementStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_AchievementStorage = AchievementStorage;
|
||||
}
|
||||
|
||||
public List<AchievementViewModel>? ReadList(AchievementSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name} AchievementId:{Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _AchievementStorage.GetFullList() : _AchievementStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public AchievementViewModel? ReadElement(AchievementSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement.Id:{ Id}", model.Id);
|
||||
var element = _AchievementStorage.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(AchievementBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_AchievementStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public bool Update(AchievementBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_AchievementStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(AchievementBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_AchievementStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(AchievementBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия достижения",
|
||||
nameof(model.Name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Description))
|
||||
{
|
||||
throw new ArgumentNullException("Нет описания достижения",
|
||||
nameof(model.Description));
|
||||
}
|
||||
_logger.LogInformation("Achievement. Id:{Id}. LessonId:{LessonId}. Name:{Name}. Description:{Description} .ReceiptDate{ReceiptDate}", model.Id, model.LessonId, model.Name, model.Description, model.ReceiptDate);
|
||||
}
|
||||
}
|
||||
}
|
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("Кружок с таким именем уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
117
School/SchoolBusinessLogic/BusinessLogic/InterestLogic.cs
Normal file
117
School/SchoolBusinessLogic/BusinessLogic/InterestLogic.cs
Normal file
@ -0,0 +1,117 @@
|
||||
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 InterestLogic : IInterestLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IInterestStorage _InterestStorage;
|
||||
public InterestLogic(ILogger<InterestLogic> logger, IInterestStorage
|
||||
InterestStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_InterestStorage = InterestStorage;
|
||||
}
|
||||
public List<InterestViewModel>? ReadList(InterestSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. InterestName:{InterestName}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _InterestStorage.GetFullList() :
|
||||
_InterestStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list?.Count);
|
||||
return list;
|
||||
}
|
||||
public InterestViewModel? ReadElement(InterestSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. InterestName:{InterestName}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _InterestStorage.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(InterestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_InterestStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(InterestBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_InterestStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(InterestBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_InterestStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(InterestBindingModel 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));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Direction))
|
||||
{
|
||||
throw new ArgumentNullException("Нет направления интереса",
|
||||
nameof(model.Direction));
|
||||
}
|
||||
_logger.LogInformation("Interest. InterestName:{InterestName}.Direction:{Direction}. Id: { Id}", model.Name, model.Direction, model.Id);
|
||||
var element = _InterestStorage.GetElement(new InterestSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Интерес с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
107
School/SchoolBusinessLogic/BusinessLogic/LessonLogic.cs
Normal file
107
School/SchoolBusinessLogic/BusinessLogic/LessonLogic.cs
Normal file
@ -0,0 +1,107 @@
|
||||
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 LessonLogic : ILessonLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILessonStorage _LessonStorage;
|
||||
|
||||
public LessonLogic(ILogger<LessonLogic> logger, ILessonStorage LessonStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_LessonStorage = LessonStorage;
|
||||
}
|
||||
|
||||
public List<LessonViewModel>? ReadList(LessonSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. LessonId:{Id}", model?.Id);
|
||||
var list = model == null ? _LessonStorage.GetFullList() : _LessonStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public LessonViewModel? ReadElement(LessonSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement.Id:{ Id}", model.Id);
|
||||
var element = _LessonStorage.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(LessonBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_LessonStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public bool Update(LessonBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_LessonStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(LessonBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_LessonStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(LessonBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (model.TimeStart >= model.TimeEnd)
|
||||
{
|
||||
throw new ArgumentNullException("Занятие должно начинаться раньше чем заканчивается");
|
||||
}
|
||||
_logger.LogInformation("Lesson. Id:{Id}. UserId:{UserId}. TimeStart:{TimeStart}. TimeEnd:{TimeEnd}", model.Id, model.UserId, model.TimeStart, model.TimeEnd);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
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("Материал с таким именем уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
127
School/SchoolBusinessLogic/BusinessLogic/UserLogic.cs
Normal file
127
School/SchoolBusinessLogic/BusinessLogic/UserLogic.cs
Normal file
@ -0,0 +1,127 @@
|
||||
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 UserLogic : IUserLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUserStorage _UserStorage;
|
||||
public UserLogic(ILogger<UserLogic> logger, IUserStorage
|
||||
UserStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_UserStorage = UserStorage;
|
||||
}
|
||||
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. UserName:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _UserStorage.GetFullList() :
|
||||
_UserStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list?.Count);
|
||||
return list;
|
||||
}
|
||||
public UserViewModel? ReadElement(UserSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. UserName:{Name}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _UserStorage.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(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_UserStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_UserStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_UserStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(UserBindingModel 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));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Mail))
|
||||
{
|
||||
throw new ArgumentNullException("Нет электронной почты",
|
||||
nameof(model.Mail));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.PhoneNumber))
|
||||
{
|
||||
throw new ArgumentNullException("Нет номера телефона",
|
||||
nameof(model.PhoneNumber));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля пользователя",
|
||||
nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("User. UserName:{UserName}.Birthdate:{ BirthDate}. Mail:{ Mail}. PhoneNumber{ PhoneNumber} Id: { Id}", model.Name, model.BirthDate, model.Mail, model.PhoneNumber, model.Id);
|
||||
var element = _UserStorage.GetElement(new UserSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Пользователь с таким именем уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
School/SchoolBusinessLogic/SchoolBusinessLogic.csproj
Normal file
17
School/SchoolBusinessLogic/SchoolBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SchoolContracts\SchoolContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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 AchievementBindingModel : IAchievementModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int LessonId { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public DateTime ReceiptDate { get; set; }
|
||||
}
|
||||
}
|
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();
|
||||
}
|
||||
}
|
28
School/SchoolContracts/BindingModels/InterestBindingModel.cs
Normal file
28
School/SchoolContracts/BindingModels/InterestBindingModel.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SchoolDataModels.Models;
|
||||
|
||||
namespace SchoolContracts.BindingModels
|
||||
{
|
||||
public class InterestBindingModel : IInterestModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Direction { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public Dictionary<int, ILessonModel> InterestLessons
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
|
||||
public Dictionary<int, IMaterialModel> InterestMaterials
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
21
School/SchoolContracts/BindingModels/LessonBindingModel.cs
Normal file
21
School/SchoolContracts/BindingModels/LessonBindingModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.BindingModels
|
||||
{
|
||||
public class LessonBindingModel : ILessonModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public DateTime TimeStart { get; set; }
|
||||
|
||||
public DateTime TimeEnd { get; set; }
|
||||
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
24
School/SchoolContracts/BindingModels/UserBindingModel.cs
Normal file
24
School/SchoolContracts/BindingModels/UserBindingModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SchoolDataModels.Models;
|
||||
|
||||
|
||||
namespace SchoolContracts.BindingModels
|
||||
{
|
||||
public class UserBindingModel : IUserModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
public string Mail { get; set; } = string.Empty;
|
||||
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -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 IAchievementLogic
|
||||
{
|
||||
List<AchievementViewModel>? ReadList(AchievementSearchModel? model);
|
||||
AchievementViewModel? ReadElement(AchievementSearchModel model);
|
||||
bool Create(AchievementBindingModel model);
|
||||
bool Update(AchievementBindingModel model);
|
||||
bool Delete(AchievementBindingModel model);
|
||||
}
|
||||
}
|
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 IInterestLogic
|
||||
{
|
||||
List<InterestViewModel>? ReadList(InterestSearchModel? model);
|
||||
InterestViewModel? ReadElement(InterestSearchModel model);
|
||||
bool Create(InterestBindingModel model);
|
||||
bool Update(InterestBindingModel model);
|
||||
bool Delete(InterestBindingModel 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 ILessonLogic
|
||||
{
|
||||
List<LessonViewModel>? ReadList(LessonSearchModel? model);
|
||||
LessonViewModel? ReadElement(LessonSearchModel model);
|
||||
bool Create(LessonBindingModel model);
|
||||
bool Update(LessonBindingModel model);
|
||||
bool Delete(LessonBindingModel 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);
|
||||
}
|
||||
}
|
20
School/SchoolContracts/BusinessLogicsContracts/IUserLogic.cs
Normal file
20
School/SchoolContracts/BusinessLogicsContracts/IUserLogic.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 IUserLogic
|
||||
{
|
||||
List<UserViewModel>? ReadList(UserSearchModel? model);
|
||||
UserViewModel? ReadElement(UserSearchModel model);
|
||||
bool Create(UserBindingModel model);
|
||||
bool Update(UserBindingModel model);
|
||||
bool Delete(UserBindingModel model);
|
||||
}
|
||||
}
|
13
School/SchoolContracts/SchoolContracts.csproj
Normal file
13
School/SchoolContracts/SchoolContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SchoolsDataModels\SchoolDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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 AchievementSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
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/InterestSearchModel.cs
Normal file
14
School/SchoolContracts/SearchModels/InterestSearchModel.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 InterestSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
13
School/SchoolContracts/SearchModels/LessonSearchModel.cs
Normal file
13
School/SchoolContracts/SearchModels/LessonSearchModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolContracts.SearchModels
|
||||
{
|
||||
public class LessonSearchModel
|
||||
{
|
||||
public int? Id { 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; }
|
||||
}
|
||||
}
|
14
School/SchoolContracts/SearchModels/UserSearchModel.cs
Normal file
14
School/SchoolContracts/SearchModels/UserSearchModel.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 UserSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
@ -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 IAchievementStorage
|
||||
{
|
||||
List<AchievementViewModel> GetFullList();
|
||||
List<AchievementViewModel> GetFilteredList(AchievementSearchModel model);
|
||||
AchievementViewModel? GetElement(AchievementSearchModel model);
|
||||
AchievementViewModel? Insert(AchievementBindingModel model);
|
||||
AchievementViewModel? Update(AchievementBindingModel model);
|
||||
AchievementViewModel? Delete(AchievementBindingModel model);
|
||||
}
|
||||
}
|
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/IInterestStorage.cs
Normal file
21
School/SchoolContracts/StoragesContracts/IInterestStorage.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 IInterestStorage
|
||||
{
|
||||
List<InterestViewModel> GetFullList();
|
||||
List<InterestViewModel> GetFilteredList(InterestSearchModel model);
|
||||
InterestViewModel? GetElement(InterestSearchModel model);
|
||||
InterestViewModel? Insert(InterestBindingModel model);
|
||||
InterestViewModel? Update(InterestBindingModel model);
|
||||
InterestViewModel? Delete(InterestBindingModel model);
|
||||
}
|
||||
}
|
21
School/SchoolContracts/StoragesContracts/ILessonStorage.cs
Normal file
21
School/SchoolContracts/StoragesContracts/ILessonStorage.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 ILessonStorage
|
||||
{
|
||||
List<LessonViewModel> GetFullList();
|
||||
List<LessonViewModel> GetFilteredList(LessonSearchModel model);
|
||||
LessonViewModel? GetElement(LessonSearchModel model);
|
||||
LessonViewModel? Insert(LessonBindingModel model);
|
||||
LessonViewModel? Update(LessonBindingModel model);
|
||||
LessonViewModel? Delete(LessonBindingModel 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);
|
||||
}
|
||||
}
|
21
School/SchoolContracts/StoragesContracts/IUserStorage.cs
Normal file
21
School/SchoolContracts/StoragesContracts/IUserStorage.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 IUserStorage
|
||||
{
|
||||
List<UserViewModel> GetFullList();
|
||||
List<UserViewModel> GetFilteredList(UserSearchModel model);
|
||||
UserViewModel? GetElement(UserSearchModel model);
|
||||
UserViewModel? Insert(UserBindingModel model);
|
||||
UserViewModel? Update(UserBindingModel model);
|
||||
UserViewModel? Delete(UserBindingModel model);
|
||||
}
|
||||
}
|
22
School/SchoolContracts/ViewModels/AchievementViewModel.cs
Normal file
22
School/SchoolContracts/ViewModels/AchievementViewModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SchoolContracts.ViewModels
|
||||
{
|
||||
public class AchievementViewModel : IAchievementModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int LessonId { get; set; }
|
||||
[DisplayName("Название достижения")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Описание достижения")]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
[DisplayName("Дата время получения")]
|
||||
public DateTime ReceiptDate { get; set; }
|
||||
}
|
||||
}
|
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();
|
||||
}
|
||||
}
|
32
School/SchoolContracts/ViewModels/InterestViewModel.cs
Normal file
32
School/SchoolContracts/ViewModels/InterestViewModel.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SchoolContracts.ViewModels
|
||||
{
|
||||
public class InterestViewModel : IInterestModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название интереса")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Направление интереса")]
|
||||
public string Direction { get; set; } = string.Empty;
|
||||
[DisplayName("Описание интереса")]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public Dictionary<int, ILessonModel> InterestLessons
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
|
||||
public Dictionary<int, IMaterialModel> InterestMaterials
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
22
School/SchoolContracts/ViewModels/LessonViewModel.cs
Normal file
22
School/SchoolContracts/ViewModels/LessonViewModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SchoolContracts.ViewModels
|
||||
{
|
||||
public class LessonViewModel : ILessonModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int UserId { get; set; }
|
||||
[DisplayName("Пользователь")]
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
[DisplayName("Время начала занятие")]
|
||||
public DateTime TimeStart { get; set; }
|
||||
[DisplayName("Время конца занятия")]
|
||||
public DateTime TimeEnd { get; set; }
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
24
School/SchoolContracts/ViewModels/UserViewModel.cs
Normal file
24
School/SchoolContracts/ViewModels/UserViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SchoolContracts.ViewModels
|
||||
{
|
||||
public class UserViewModel : IUserModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Имя пользователя")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Дата рождения")]
|
||||
public DateTime BirthDate { get; set; }
|
||||
[DisplayName("Электронная почта")]
|
||||
public string Mail { get; set; } = string.Empty;
|
||||
[DisplayName("Номер телефона")]
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.StoragesContracts;
|
||||
using SchoolContracts.ViewModels;
|
||||
using SchoolDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement.Implements
|
||||
{
|
||||
public class AchievementStorage : IAchievementStorage
|
||||
{
|
||||
public List<AchievementViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Achievements
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<AchievementViewModel> GetFilteredList(AchievementSearchModel
|
||||
model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Achievements
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public AchievementViewModel? GetElement(AchievementSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Achievements
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Name) && x.Name ==
|
||||
model.Name) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public AchievementViewModel? Insert(AchievementBindingModel model)
|
||||
{
|
||||
var newAchievement = Achievement.Create(model);
|
||||
if (newAchievement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
context.Achievements.Add(newAchievement);
|
||||
context.SaveChanges();
|
||||
return newAchievement.GetViewModel;
|
||||
}
|
||||
public AchievementViewModel? Update(AchievementBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
var Achievement = context.Achievements.FirstOrDefault(x => x.Id ==
|
||||
model.Id);
|
||||
if (Achievement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Achievement.Update(model);
|
||||
context.SaveChanges();
|
||||
return Achievement.GetViewModel;
|
||||
}
|
||||
public AchievementViewModel? Delete(AchievementBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
var element = context.Achievements.FirstOrDefault(rec => rec.Id ==
|
||||
model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Achievements.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
111
School/SchoolDatabaseImplement/Implements/InterestStorage.cs
Normal file
111
School/SchoolDatabaseImplement/Implements/InterestStorage.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.StoragesContracts;
|
||||
using SchoolContracts.ViewModels;
|
||||
using SchoolDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement.Implements
|
||||
{
|
||||
public class InterestStorage : IInterestStorage
|
||||
{
|
||||
public List<InterestViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Interests
|
||||
.Include(x => x.Lessons)
|
||||
.ThenInclude(x => x.Lesson)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<InterestViewModel> GetFilteredList(InterestSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Interests
|
||||
.Include(x => x.Lessons)
|
||||
.ThenInclude(x => x.Lesson)
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public InterestViewModel? GetElement(InterestSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Interests
|
||||
.Include(x => x.Lessons)
|
||||
.ThenInclude(x => x.Lesson)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) &&
|
||||
x.Name == model.Name) ||
|
||||
(model.Id.HasValue && x.Id ==
|
||||
model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public InterestViewModel? Insert(InterestBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
var newComputer = Interest.Create(context, model);
|
||||
if (newComputer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Interests.Add(newComputer);
|
||||
context.SaveChanges();
|
||||
return newComputer.GetViewModel;
|
||||
}
|
||||
public InterestViewModel? Update(InterestBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var Computer = context.Interests.FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
if (Computer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Computer.Update(model);
|
||||
context.SaveChanges();
|
||||
Computer.UpdateLessons(context, model);
|
||||
transaction.Commit();
|
||||
return Computer.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public InterestViewModel? Delete(InterestBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
var element = context.Interests
|
||||
.Include(x => x.Lessons)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Interests.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
82
School/SchoolDatabaseImplement/Implements/LessonStorage.cs
Normal file
82
School/SchoolDatabaseImplement/Implements/LessonStorage.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.StoragesContracts;
|
||||
using SchoolContracts.ViewModels;
|
||||
using SchoolDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement.Implements
|
||||
{
|
||||
public class LessonStorage : ILessonStorage
|
||||
{
|
||||
public List<LessonViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Lessons.Include(x => x.Achievements)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<LessonViewModel> GetFilteredList(LessonSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Lessons.Include(x => x.Achievements)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public LessonViewModel? GetElement(LessonSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Lessons.Include(x => x.Achievements).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
public LessonViewModel? Insert(LessonBindingModel model)
|
||||
{
|
||||
var newLesson = Lesson.Create(model);
|
||||
if (newLesson == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
context.Lessons.Add(newLesson);
|
||||
context.SaveChanges();
|
||||
return newLesson.GetViewModel;
|
||||
}
|
||||
public LessonViewModel? Update(LessonBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
var Lesson = context.Lessons.Include(x => x.Achievements).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (Lesson == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Lesson.Update(model);
|
||||
context.SaveChanges();
|
||||
return Lesson.GetViewModel;
|
||||
}
|
||||
public LessonViewModel? Delete(LessonBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
var element = context.Lessons.Include(x => x.Achievements).FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Lessons.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
84
School/SchoolDatabaseImplement/Implements/UserStorage.cs
Normal file
84
School/SchoolDatabaseImplement/Implements/UserStorage.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.SearchModels;
|
||||
using SchoolContracts.StoragesContracts;
|
||||
using SchoolContracts.ViewModels;
|
||||
using SchoolDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement.Implements
|
||||
{
|
||||
public class UserStorage
|
||||
{
|
||||
public List<UserViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Users.Include(x => x.Lessons)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<UserViewModel> GetFilteredList(UserSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Users.Include(x => x.Lessons)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public UserViewModel? GetElement(UserSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
return context.Users.Include(x => x.Lessons).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
public UserViewModel? Insert(UserBindingModel model)
|
||||
{
|
||||
var newUser = User.Create(model);
|
||||
if (newUser == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new SchoolDatabase();
|
||||
context.Users.Add(newUser);
|
||||
context.SaveChanges();
|
||||
return newUser.GetViewModel;
|
||||
}
|
||||
public UserViewModel? Update(UserBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
var user = context.Users.Include(x => x.Lessons).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
user.Update(model);
|
||||
context.SaveChanges();
|
||||
return user.GetViewModel;
|
||||
}
|
||||
public UserViewModel? Delete(UserBindingModel model)
|
||||
{
|
||||
using var context = new SchoolDatabase();
|
||||
var element = context.Users.Include(x => x.Lessons).FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Users.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
287
School/SchoolDatabaseImplement/Migrations/20240501191433_InitialCreate.Designer.cs
generated
Normal file
287
School/SchoolDatabaseImplement/Migrations/20240501191433_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,287 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SchoolDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SchoolDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SchoolDatabase))]
|
||||
[Migration("20240501191433_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Achievement", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("LessonId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ReceiptDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LessonId");
|
||||
|
||||
b.ToTable("Achievements");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Interest", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Direction")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Interests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestLesson", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("InterestId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("LessonId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("InterestId");
|
||||
|
||||
b.HasIndex("LessonId");
|
||||
|
||||
b.ToTable("InterestLessons");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestMaterial", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("InterestId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaterialId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("InterestId");
|
||||
|
||||
b.HasIndex("MaterialId");
|
||||
|
||||
b.ToTable("InterestMaterial");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("TimeEnd")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("TimeStart")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Lessons");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Material");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Mail")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Achievement", b =>
|
||||
{
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Lesson", "Lesson")
|
||||
.WithMany("Achievements")
|
||||
.HasForeignKey("LessonId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Lesson");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestLesson", b =>
|
||||
{
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Interest", "Interest")
|
||||
.WithMany("Lessons")
|
||||
.HasForeignKey("InterestId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Lesson", "Lesson")
|
||||
.WithMany("InterestLessons")
|
||||
.HasForeignKey("LessonId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Interest");
|
||||
|
||||
b.Navigation("Lesson");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestMaterial", b =>
|
||||
{
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Interest", "Interest")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("InterestId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Material", "Material")
|
||||
.WithMany("InterestMaterials")
|
||||
.HasForeignKey("MaterialId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Interest");
|
||||
|
||||
b.Navigation("Material");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
|
||||
{
|
||||
b.HasOne("SchoolDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Lessons")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Interest", b =>
|
||||
{
|
||||
b.Navigation("Lessons");
|
||||
|
||||
b.Navigation("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
|
||||
{
|
||||
b.Navigation("Achievements");
|
||||
|
||||
b.Navigation("InterestLessons");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.Navigation("InterestMaterials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Navigation("Lessons");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SchoolDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Interests",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Direction = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Description = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Interests", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Material",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Material", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
BirthDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Mail = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "InterestMaterial",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
InterestId = table.Column<int>(type: "int", nullable: false),
|
||||
MaterialId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_InterestMaterial", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_InterestMaterial_Interests_InterestId",
|
||||
column: x => x.InterestId,
|
||||
principalTable: "Interests",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_InterestMaterial_Material_MaterialId",
|
||||
column: x => x.MaterialId,
|
||||
principalTable: "Material",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Lessons",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
TimeStart = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
TimeEnd = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
UserId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Lessons", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Lessons_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Achievements",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
LessonId = table.Column<int>(type: "int", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
ReceiptDate = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Achievements", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Achievements_Lessons_LessonId",
|
||||
column: x => x.LessonId,
|
||||
principalTable: "Lessons",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "InterestLessons",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
InterestId = table.Column<int>(type: "int", nullable: false),
|
||||
LessonId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_InterestLessons", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_InterestLessons_Interests_InterestId",
|
||||
column: x => x.InterestId,
|
||||
principalTable: "Interests",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_InterestLessons_Lessons_LessonId",
|
||||
column: x => x.LessonId,
|
||||
principalTable: "Lessons",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Achievements_LessonId",
|
||||
table: "Achievements",
|
||||
column: "LessonId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_InterestLessons_InterestId",
|
||||
table: "InterestLessons",
|
||||
column: "InterestId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_InterestLessons_LessonId",
|
||||
table: "InterestLessons",
|
||||
column: "LessonId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_InterestMaterial_InterestId",
|
||||
table: "InterestMaterial",
|
||||
column: "InterestId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_InterestMaterial_MaterialId",
|
||||
table: "InterestMaterial",
|
||||
column: "MaterialId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Lessons_UserId",
|
||||
table: "Lessons",
|
||||
column: "UserId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Achievements");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "InterestLessons");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "InterestMaterial");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Lessons");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Interests");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Material");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,284 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SchoolDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SchoolDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(SchoolDatabase))]
|
||||
partial class SchoolDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Achievement", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("LessonId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ReceiptDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LessonId");
|
||||
|
||||
b.ToTable("Achievements");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Interest", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Direction")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Interests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestLesson", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("InterestId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("LessonId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("InterestId");
|
||||
|
||||
b.HasIndex("LessonId");
|
||||
|
||||
b.ToTable("InterestLessons");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestMaterial", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("InterestId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaterialId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("InterestId");
|
||||
|
||||
b.HasIndex("MaterialId");
|
||||
|
||||
b.ToTable("InterestMaterial");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("TimeEnd")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("TimeStart")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Lessons");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Material");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Mail")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Achievement", b =>
|
||||
{
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Lesson", "Lesson")
|
||||
.WithMany("Achievements")
|
||||
.HasForeignKey("LessonId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Lesson");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestLesson", b =>
|
||||
{
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Interest", "Interest")
|
||||
.WithMany("Lessons")
|
||||
.HasForeignKey("InterestId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Lesson", "Lesson")
|
||||
.WithMany("InterestLessons")
|
||||
.HasForeignKey("LessonId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Interest");
|
||||
|
||||
b.Navigation("Lesson");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.InterestMaterial", b =>
|
||||
{
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Interest", "Interest")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("InterestId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("SchoolDatabaseImplement.Models.Material", "Material")
|
||||
.WithMany("InterestMaterials")
|
||||
.HasForeignKey("MaterialId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Interest");
|
||||
|
||||
b.Navigation("Material");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
|
||||
{
|
||||
b.HasOne("SchoolDatabaseImplement.Models.User", "User")
|
||||
.WithMany("Lessons")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Interest", b =>
|
||||
{
|
||||
b.Navigation("Lessons");
|
||||
|
||||
b.Navigation("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Lesson", b =>
|
||||
{
|
||||
b.Navigation("Achievements");
|
||||
|
||||
b.Navigation("InterestLessons");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.Material", b =>
|
||||
{
|
||||
b.Navigation("InterestMaterials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SchoolDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Navigation("Lessons");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
61
School/SchoolDatabaseImplement/Models/Achievement.cs
Normal file
61
School/SchoolDatabaseImplement/Models/Achievement.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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement.Models
|
||||
{
|
||||
public class Achievement : IAchievementModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int LessonId { get; private set; }
|
||||
public virtual Lesson? Lesson { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public string Description { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime ReceiptDate { get; private set; }
|
||||
public static Achievement? Create(AchievementBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Achievement()
|
||||
{
|
||||
Id = model.Id,
|
||||
LessonId = model.LessonId,
|
||||
Name = model.Name,
|
||||
Description = model.Description,
|
||||
ReceiptDate = model.ReceiptDate
|
||||
};
|
||||
}
|
||||
public void Update(AchievementBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Description = model.Description;
|
||||
ReceiptDate = model.ReceiptDate;
|
||||
}
|
||||
public AchievementViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
LessonId = LessonId,
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
ReceiptDate = ReceiptDate
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
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();
|
||||
}
|
||||
}
|
118
School/SchoolDatabaseImplement/Models/Interest.cs
Normal file
118
School/SchoolDatabaseImplement/Models/Interest.cs
Normal file
@ -0,0 +1,118 @@
|
||||
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 Interest : IInterestModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Direction { get; private set; } = string.Empty;
|
||||
|
||||
public string Description { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
private Dictionary<int, ILessonModel>? _InterestLessons = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, ILessonModel> InterestLessons
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_InterestLessons == null)
|
||||
{
|
||||
_InterestLessons = Lessons.ToDictionary(recPC => recPC.LessonId, recPC => recPC.Lesson as ILessonModel);
|
||||
}
|
||||
return _InterestLessons;
|
||||
}
|
||||
}
|
||||
[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()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Direction = model.Direction,
|
||||
Description = model.Description,
|
||||
Lessons = model.InterestLessons.Select(x => new InterestLesson
|
||||
{
|
||||
Lesson = context.Lessons.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(InterestBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Direction = model.Direction;
|
||||
Description = model.Description;
|
||||
}
|
||||
public InterestViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Direction = Direction,
|
||||
Description = Description,
|
||||
InterestLessons = InterestLessons
|
||||
};
|
||||
|
||||
|
||||
|
||||
public void UpdateLessons(SchoolDatabase context,
|
||||
InterestBindingModel model)
|
||||
{
|
||||
var InterestLessons = context.InterestLessons.Where(rec => rec.InterestId == model.Id).ToList();
|
||||
if (InterestLessons != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.InterestLessons.RemoveRange(InterestLessons.Where(rec
|
||||
=> !model.InterestLessons.ContainsKey(rec.LessonId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateLesson in InterestLessons)
|
||||
{
|
||||
model.InterestLessons.Remove(updateLesson.LessonId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var Interest = context.Interests.First(x => x.Id == Id);
|
||||
foreach (var pc in model.InterestLessons)
|
||||
{
|
||||
context.InterestLessons.Add(new InterestLesson
|
||||
{
|
||||
Interest = Interest,
|
||||
Lesson = context.Lessons.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_InterestLessons = null;
|
||||
}
|
||||
}
|
||||
}
|
22
School/SchoolDatabaseImplement/Models/InterestLesson.cs
Normal file
22
School/SchoolDatabaseImplement/Models/InterestLesson.cs
Normal file
@ -0,0 +1,22 @@
|
||||
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 InterestLesson
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int InterestId { get; set; }
|
||||
[Required]
|
||||
public int LessonId { get; set; }
|
||||
[Required]
|
||||
public virtual Lesson Lesson { get; set; } = new();
|
||||
public virtual Interest Interest { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
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();
|
||||
}
|
||||
}
|
63
School/SchoolDatabaseImplement/Models/Lesson.cs
Normal file
63
School/SchoolDatabaseImplement/Models/Lesson.cs
Normal file
@ -0,0 +1,63 @@
|
||||
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 Lesson : ILessonModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public DateTime TimeStart { get; private set; }
|
||||
[Required]
|
||||
public DateTime TimeEnd { get; private set; }
|
||||
[ForeignKey("LessonId")]
|
||||
public virtual List<InterestLesson> InterestLessons { get; set; } = new();
|
||||
[Required]
|
||||
public int UserId { get; private set; }
|
||||
public virtual User? User { get; private set; }
|
||||
|
||||
[ForeignKey("LessonId")]
|
||||
public virtual List<Achievement> Achievements { get; set; } = new();
|
||||
public static Lesson? Create(LessonBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Lesson()
|
||||
{
|
||||
Id = model.Id,
|
||||
UserId = model.UserId,
|
||||
TimeStart = model.TimeStart,
|
||||
TimeEnd = model.TimeEnd
|
||||
};
|
||||
}
|
||||
public void Update(LessonBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
TimeStart = model.TimeStart;
|
||||
TimeEnd = model.TimeEnd;
|
||||
}
|
||||
public LessonViewModel GetViewModel => new()
|
||||
{
|
||||
UserId = UserId,
|
||||
TimeStart = TimeStart,
|
||||
TimeEnd = TimeEnd,
|
||||
Id = Id,
|
||||
UserName = User?.Name ?? string.Empty
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
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
|
||||
};
|
||||
}
|
||||
}
|
71
School/SchoolDatabaseImplement/Models/User.cs
Normal file
71
School/SchoolDatabaseImplement/Models/User.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using SchoolContracts.BindingModels;
|
||||
using SchoolContracts.ViewModels;
|
||||
using SchoolDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
|
||||
namespace SchoolDatabaseImplement.Models
|
||||
{
|
||||
public class User : IUserModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime BirthDate { get; private set; }
|
||||
public string Mail { get; private set; } = string.Empty;
|
||||
|
||||
public string PhoneNumber { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public virtual List<Lesson> Lessons { get; set; } = new();
|
||||
public static User? Create(UserBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new User()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
BirthDate = model.BirthDate,
|
||||
Mail = model.Mail,
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(UserBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
BirthDate = model.BirthDate;
|
||||
Mail = model.Mail;
|
||||
PhoneNumber = model.PhoneNumber;
|
||||
Password = model.Password;
|
||||
}
|
||||
public UserViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
BirthDate = BirthDate,
|
||||
Mail = Mail,
|
||||
PhoneNumber = PhoneNumber,
|
||||
Password = Password
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
30
School/SchoolDatabaseImplement/SchoolDatabase.cs
Normal file
30
School/SchoolDatabaseImplement/SchoolDatabase.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SchoolDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDatabaseImplement
|
||||
{
|
||||
public class SchoolDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder
|
||||
optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=firsovpk;Initial Catalog=SchoolDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"
|
||||
);
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<User> Users { set; get; }
|
||||
public virtual DbSet<Lesson> Lessons { set; get; }
|
||||
public virtual DbSet<InterestLesson> InterestLessons { set; get; }
|
||||
public virtual DbSet<Interest> Interests { set; get; }
|
||||
public virtual DbSet<Achievement> Achievements { set; get; }
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SchoolContracts\SchoolContracts.csproj" />
|
||||
<ProjectReference Include="..\SchoolsDataModels\SchoolDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
14
School/SchoolsDataModels/IId.cs
Normal file
14
School/SchoolsDataModels/IId.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
|
||||
}
|
||||
}
|
16
School/SchoolsDataModels/Models/IAchievementModel.cs
Normal file
16
School/SchoolsDataModels/Models/IAchievementModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDataModels.Models
|
||||
{
|
||||
public interface IAchievementModel : IId
|
||||
{
|
||||
int LessonId { get; }
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
DateTime ReceiptDate { get; }
|
||||
}
|
||||
}
|
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; }
|
||||
}
|
||||
}
|
21
School/SchoolsDataModels/Models/IInterestModel.cs
Normal file
21
School/SchoolsDataModels/Models/IInterestModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDataModels.Models
|
||||
{
|
||||
public interface IInterestModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
string Direction { get; }
|
||||
|
||||
string Description { get; }
|
||||
|
||||
Dictionary<int, ILessonModel> InterestLessons { get; }
|
||||
|
||||
Dictionary<int, IMaterialModel> InterestMaterials { get; }
|
||||
}
|
||||
}
|
15
School/SchoolsDataModels/Models/ILessonModel.cs
Normal file
15
School/SchoolsDataModels/Models/ILessonModel.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 ILessonModel : IId
|
||||
{
|
||||
int UserId { get; }
|
||||
DateTime TimeStart { get; }
|
||||
DateTime TimeEnd { 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; }
|
||||
}
|
||||
}
|
17
School/SchoolsDataModels/Models/IUserModel.cs
Normal file
17
School/SchoolsDataModels/Models/IUserModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SchoolDataModels.Models
|
||||
{
|
||||
public interface IUserModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
DateTime BirthDate { get; }
|
||||
string Mail { get; }
|
||||
string PhoneNumber { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
9
School/SchoolsDataModels/SchoolDataModels.csproj
Normal file
9
School/SchoolsDataModels/SchoolDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user