Вроде доделано Databaseimplement для Поставщика
This commit is contained in:
parent
8423f1fdfd
commit
f5c1abd6ed
@ -12,5 +12,6 @@ namespace UniversityContracts.BindingModels
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
public DateTime Date { get; set; } = DateTime.Now;
|
public DateTime Date { get; set; } = DateTime.Now;
|
||||||
|
public int UserId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,7 @@ namespace UniversityContracts.BindingModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public int UserId { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,6 @@ namespace UniversityContracts.BindingModels
|
|||||||
public DateTime DateOfBirth { get; set; }
|
public DateTime DateOfBirth { get; set; }
|
||||||
public int StudentCard { get; set; }
|
public int StudentCard { get; set; }
|
||||||
public int EducationStatusId { get; set; }
|
public int EducationStatusId { get; set; }
|
||||||
|
public int UserId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,6 @@ namespace UniversityContracts.SearchModels
|
|||||||
public class DocumentSearchModel
|
public class DocumentSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
public int? UserId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,6 @@ namespace UniversityContracts.SearchModels
|
|||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
public int? UserId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,6 @@ namespace UniversityContracts.SearchModels
|
|||||||
public class StudentSearchModel
|
public class StudentSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
public int? UserId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UniversityContracts.BindingModels;
|
using UniversityContracts.BindingModels;
|
||||||
using UniversityContracts.SearchModels;
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
|
||||||
namespace UniversityContracts.StoragesContracts
|
namespace UniversityContracts.StoragesContracts
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UniversityContracts.BindingModels;
|
using UniversityContracts.BindingModels;
|
||||||
using UniversityContracts.SearchModels;
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
|
||||||
namespace UniversityContracts.StoragesContracts
|
namespace UniversityContracts.StoragesContracts
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UniversityContracts.BindingModels;
|
using UniversityContracts.BindingModels;
|
||||||
using UniversityContracts.SearchModels;
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
|
||||||
namespace UniversityContracts.StoragesContracts
|
namespace UniversityContracts.StoragesContracts
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ namespace UniversityContracts.ViewModels
|
|||||||
public class DocumentViewModel : IDocumentModel
|
public class DocumentViewModel : IDocumentModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int UserId { get; set; }
|
||||||
[DisplayName("Название документа")]
|
[DisplayName("Название документа")]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата создания документа")]
|
[DisplayName("Дата создания документа")]
|
||||||
|
@ -13,5 +13,6 @@ namespace UniversityContracts.ViewModels
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Название документа")]
|
[DisplayName("Название документа")]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public int UserId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,15 @@ namespace UniversityContracts.ViewModels
|
|||||||
public class StudentViewModel : IStudentModel
|
public class StudentViewModel : IStudentModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int UserId { get; set; }
|
||||||
[DisplayName("Имя студента")]
|
[DisplayName("Имя студента")]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
[DisplayName("Фамилия студента")]
|
[DisplayName("Фамилия студента")]
|
||||||
public string Surname { get; set; } = string.Empty;
|
public string Surname { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата рождения студента")]
|
[DisplayName("Дата рождения студента")]
|
||||||
public DateTime DateOfBirth { get; set; } = DateTime.Now;
|
public DateTime DateOfBirth { get; set; } = DateTime.Now;
|
||||||
|
[DisplayName("Статус обучения")]
|
||||||
|
public string EducationStatusName { get; set; } = string.Empty;
|
||||||
public int StudentCard { get; set; }
|
public int StudentCard { get; set; }
|
||||||
public int EducationStatusId { get; set; }
|
public int EducationStatusId { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
namespace UniversityDataBaseImplemet
|
|
||||||
{
|
|
||||||
public class Class1
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
26
UniversityDataBaseImplemet/Database.cs
Normal file
26
UniversityDataBaseImplemet/Database.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityDataBaseImplemet.Models;
|
||||||
|
|
||||||
|
namespace UniversityDataBaseImplemet
|
||||||
|
{
|
||||||
|
public class Database : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=University;Username=postgres;Password=postgres");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Document> Documents { get; set; }
|
||||||
|
public virtual DbSet<EducationStatus> EducationStatuses { get; set; }
|
||||||
|
public virtual DbSet<Student> Students { get; set; }
|
||||||
|
public virtual DbSet<StudentDocument> StudentDocuments { get; set; }
|
||||||
|
}
|
||||||
|
}
|
113
UniversityDataBaseImplemet/Implements/DocumentStorage.cs
Normal file
113
UniversityDataBaseImplemet/Implements/DocumentStorage.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.StoragesContracts;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityDataBaseImplemet.Models;
|
||||||
|
|
||||||
|
namespace UniversityDataBaseImplemet.Implements
|
||||||
|
{
|
||||||
|
public class DocumentStorage : IDocumentStorage
|
||||||
|
{
|
||||||
|
public DocumentViewModel? GetElement(DocumentSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new Database();
|
||||||
|
return context.Documents
|
||||||
|
.Include(record => record.User)
|
||||||
|
.FirstOrDefault(record => record.Id == model.Id)?
|
||||||
|
.GetViewModel;
|
||||||
|
}
|
||||||
|
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Documents
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(record => record.Id.Equals(model.Id))
|
||||||
|
.Select(record => record.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.UserId.HasValue)
|
||||||
|
{
|
||||||
|
return context.Documents
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(x => x.UserId == model.UserId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<DocumentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
return context.Documents
|
||||||
|
.Include(record => record.User)
|
||||||
|
.Select(record => record.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public DocumentViewModel? Insert(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
var newDocument = Document.Create(model);
|
||||||
|
if(newDocument == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new Database();
|
||||||
|
context.Documents.Add(newDocument);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newDocument.GetViewModel;
|
||||||
|
}
|
||||||
|
public DocumentViewModel? Update(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var document = context.Documents
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(record => record.Id.Equals(model.Id));
|
||||||
|
if (document == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
document.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
return document.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DocumentViewModel? Delete(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
var document = context.Documents
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(record => record.Id.Equals(model.Id));
|
||||||
|
if (document == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Documents.Remove(document);
|
||||||
|
context.SaveChanges();
|
||||||
|
return document.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
115
UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs
Normal file
115
UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.StoragesContracts;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityDataBaseImplemet.Models;
|
||||||
|
|
||||||
|
namespace UniversityDataBaseImplemet.Implements
|
||||||
|
{
|
||||||
|
public class EducationStatusStorage : IEducationStatusStorage
|
||||||
|
{
|
||||||
|
public EducationStatusViewModel? GetElement(EducationStatusSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new Database();
|
||||||
|
return context.EducationStatuses
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(record => record.Id == model.Id)?
|
||||||
|
.GetViewModel;
|
||||||
|
}
|
||||||
|
public List<EducationStatusViewModel> GetFilteredList(EducationStatusSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.EducationStatuses
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(record => record.Id.Equals(model.Id))
|
||||||
|
.Select(record => record.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.UserId.HasValue)
|
||||||
|
{
|
||||||
|
return context.EducationStatuses
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(x => x.UserId == model.UserId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<EducationStatusViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
return context.EducationStatuses
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Select(record => record.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public EducationStatusViewModel? Insert(EducationStatusBindingModel model)
|
||||||
|
{
|
||||||
|
var newEducationStatus = EducationStatus.Create(model);
|
||||||
|
if (newEducationStatus == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new Database();
|
||||||
|
context.EducationStatuses.Add(newEducationStatus);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.EducationStatuses
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(x => x.Id.Equals(newEducationStatus.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public EducationStatusViewModel? Update(EducationStatusBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var educationStatus = context.EducationStatuses
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(record => record.Id.Equals(model.Id));
|
||||||
|
if (educationStatus == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
educationStatus.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
return educationStatus.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public EducationStatusViewModel? Delete(EducationStatusBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
var educationStatus = context.EducationStatuses
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(record => record.Id.Equals(model.Id));
|
||||||
|
if (educationStatus == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.EducationStatuses.Remove(educationStatus);
|
||||||
|
context.SaveChanges();
|
||||||
|
return educationStatus.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
119
UniversityDataBaseImplemet/Implements/StudentStorage.cs
Normal file
119
UniversityDataBaseImplemet/Implements/StudentStorage.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.StoragesContracts;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityDataBaseImplemet.Models;
|
||||||
|
|
||||||
|
namespace UniversityDataBaseImplemet.Implements
|
||||||
|
{
|
||||||
|
public class StudentStorage : IStudentStorage
|
||||||
|
{
|
||||||
|
public StudentViewModel? GetElement(StudentSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new Database();
|
||||||
|
return context.Students
|
||||||
|
.Include(record => record.User)
|
||||||
|
.Include(record => record.EducationStatus)
|
||||||
|
.FirstOrDefault(record => record.Id.Equals(model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public List<StudentViewModel> GetFilteredList(StudentSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Students
|
||||||
|
.Include(record => record.EducationStatus)
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(record => record.Id.Equals(model.Id))
|
||||||
|
.Select(record => record.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.UserId.HasValue)
|
||||||
|
{
|
||||||
|
return context.Students
|
||||||
|
.Include(x => x.EducationStatus)
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(x => x.UserId == model.UserId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<StudentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
return context.Students
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Include(x => x.EducationStatus)
|
||||||
|
.Select(record => record.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public StudentViewModel? Insert(StudentBindingModel model)
|
||||||
|
{
|
||||||
|
var newStudent = Student.Create(model);
|
||||||
|
if (newStudent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new Database();
|
||||||
|
context.Students.Add(newStudent);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newStudent.GetViewModel;
|
||||||
|
}
|
||||||
|
public StudentViewModel? Update(StudentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var student = context.Students
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Include(x => x.EducationStatus)
|
||||||
|
.FirstOrDefault(record => record.Id.Equals(model.Id));
|
||||||
|
if (student == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
student.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
return student.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public StudentViewModel? Delete(StudentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
var student = context.Students
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Include(x => x.EducationStatus)
|
||||||
|
.FirstOrDefault(record => record.Id.Equals(model.Id));
|
||||||
|
if (student == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Students.Remove(student);
|
||||||
|
context.SaveChanges();
|
||||||
|
return student.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
UniversityDataBaseImplemet/Models/Document.cs
Normal file
55
UniversityDataBaseImplemet/Models/Document.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
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;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityModels.Models;
|
||||||
|
|
||||||
|
namespace UniversityDataBaseImplemet.Models
|
||||||
|
{
|
||||||
|
public class Document : IDocumentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int UserId { get; set; }
|
||||||
|
[ForeignKey("DocumentId")]
|
||||||
|
public virtual List<StudentDocument> Students { get; set; } = new();
|
||||||
|
public virtual EducationStatus User { get; set; }
|
||||||
|
|
||||||
|
public static Document? Create(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
return new Document()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
Date = model.Date,
|
||||||
|
UserId = model.UserId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
if(model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Name = model.Name;
|
||||||
|
Date = model.Date;
|
||||||
|
UserId = model.UserId;
|
||||||
|
}
|
||||||
|
public DocumentViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Date = Date,
|
||||||
|
UserId = UserId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
50
UniversityDataBaseImplemet/Models/EducationStatus.cs
Normal file
50
UniversityDataBaseImplemet/Models/EducationStatus.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityModels.Models;
|
||||||
|
|
||||||
|
namespace UniversityDataBaseImplemet.Models
|
||||||
|
{
|
||||||
|
public class EducationStatus : IEducationStatusModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public int UserId { get; set; }
|
||||||
|
[ForeignKey("EducationStatusId")]
|
||||||
|
public virtual List<Student> Students { get; set; } = new();
|
||||||
|
public virtual EducationStatus User { get; set; }
|
||||||
|
|
||||||
|
public static EducationStatus? Create(EducationStatusBindingModel model)
|
||||||
|
{
|
||||||
|
return new EducationStatus()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
UserId = model.UserId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(EducationStatusBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Name = model.Name;
|
||||||
|
UserId = model.UserId;
|
||||||
|
}
|
||||||
|
public EducationStatusViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
UserId = UserId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
64
UniversityDataBaseImplemet/Models/Student.cs
Normal file
64
UniversityDataBaseImplemet/Models/Student.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
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;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityModels.Models;
|
||||||
|
|
||||||
|
namespace UniversityDataBaseImplemet.Models
|
||||||
|
{
|
||||||
|
public class Student : IStudentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Surname { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public DateTime DateOfBirth { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int StudentCard { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int EducationStatusId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int UserId { get; set; }
|
||||||
|
[ForeignKey("StudentId")]
|
||||||
|
public virtual List<StudentDocument> DocumentStudents { get; set; } = new();
|
||||||
|
public virtual EducationStatus EducationStatus { get; set; }
|
||||||
|
public virtual EducationStatus User { get; set; }
|
||||||
|
|
||||||
|
public static Student Create(StudentBindingModel model)
|
||||||
|
{
|
||||||
|
return new Student()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
Surname = model.Surname,
|
||||||
|
DateOfBirth = model.DateOfBirth,
|
||||||
|
StudentCard = model.StudentCard,
|
||||||
|
EducationStatusId = model.EducationStatusId,
|
||||||
|
UserId = model.UserId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(StudentBindingModel model)
|
||||||
|
{
|
||||||
|
StudentCard = model.StudentCard;
|
||||||
|
EducationStatusId = model.EducationStatusId;
|
||||||
|
}
|
||||||
|
public StudentViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Surname = Surname,
|
||||||
|
DateOfBirth = DateOfBirth,
|
||||||
|
StudentCard = StudentCard,
|
||||||
|
EducationStatusId = EducationStatusId,
|
||||||
|
UserId = UserId,
|
||||||
|
EducationStatusName = EducationStatus.Name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
20
UniversityDataBaseImplemet/Models/StudentDocument.cs
Normal file
20
UniversityDataBaseImplemet/Models/StudentDocument.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace UniversityDataBaseImplemet.Models
|
||||||
|
{
|
||||||
|
public class StudentDocument
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int StudentId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int DocumentId { get; set; }
|
||||||
|
public virtual Student Student { get; set; } = new();
|
||||||
|
public virtual Document Document { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -6,4 +6,18 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Migrations\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\UniversityContracts\UniversityContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\UniversityModels\UniversityModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -10,5 +10,6 @@ namespace UniversityModels.Models
|
|||||||
{
|
{
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
DateTime Date { get; }
|
DateTime Date { get; }
|
||||||
|
int UserId { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,6 @@ namespace UniversityModels.Models
|
|||||||
public interface IEducationStatusModel : IId
|
public interface IEducationStatusModel : IId
|
||||||
{
|
{
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
int UserId { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,6 @@ namespace UniversityModels.Models
|
|||||||
DateTime DateOfBirth { get; }
|
DateTime DateOfBirth { get; }
|
||||||
int StudentCard { get; }
|
int StudentCard { get; }
|
||||||
int EducationStatusId { get; }
|
int EducationStatusId { get; }
|
||||||
|
int UserId { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user