Модели для базы данных закончил

This commit is contained in:
Kirill 2024-04-30 19:52:17 +04:00
parent ac02c11334
commit 609cc81c7a
12 changed files with 319 additions and 3 deletions

View File

@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolContracts", "SchoolCo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolBusinessLogic", "SchoolBusinessLogic\SchoolBusinessLogic.csproj", "{E78D42A3-7FA0-4E3A-B0C8-AEC70B3EE331}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolDatabaseImplement", "SchoolDatabaseImplement\SchoolDatabaseImplement.csproj", "{8C8F56D4-E267-498F-AFCD-06701962D09F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -33,6 +35,10 @@ Global
{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

View File

@ -6,4 +6,11 @@
<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>
</ItemGroup>
</Project>

View File

@ -12,7 +12,7 @@ namespace SchoolContracts.BindingModels
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Direction { get; set; } = string.Empty;
public string Discription { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public Dictionary<int, (ILessonModel, int)> InterestLessons
{
get;

View File

@ -16,7 +16,7 @@ namespace SchoolContracts.ViewModels
[DisplayName("Направление интереса")]
public string Direction { get; set; } = string.Empty;
[DisplayName("Описание интереса")]
public string Discription { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public Dictionary<int, (ILessonModel, int)> InterestLessons
{
get;

View File

@ -12,6 +12,8 @@ namespace SchoolContracts.ViewModels
{
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("Время конца занятия")]

View 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
};
}
}

View 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 Interest : IInterestModel
{
public int Id { get; private 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;
[ForeignKey("InterestId")]
public virtual List<InterestLesson> InterestLessons { get; set; } = new();
[Required]
Dictionary<int, (ILessonModel, int)> IInterestModel.InterestLessons => throw new NotImplementedException();
public static Interest? Create(InterestBindingModel model)
{
if (model == null)
{
return null;
}
return new Interest()
{
Id = model.Id,
Name = model.Name,
Direction = model.Direction,
Description = model.Description
};
}
public void Update(InterestBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Direction = model.Direction;
Description = model.Description;
}
public InterestViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Direction = Direction,
Description = Description
};
}
}

View 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();
}
}

View File

@ -0,0 +1,60 @@
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; }
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
};
}
}

View File

@ -0,0 +1,68 @@
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;
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
};
}
}

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Implements\" />
</ItemGroup>
<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>

View File

@ -12,7 +12,7 @@ namespace SchoolDataModels.Models
string Direction { get; }
string Discription { get; }
string Description { get; }
Dictionary<int, (ILessonModel, int)> InterestLessons { get; }
}