diff --git a/UniversityContracts/ViewModels/ReportDiscipline.cs b/UniversityContracts/ViewModels/ReportDiscipline.cs new file mode 100644 index 0000000..45a25c8 --- /dev/null +++ b/UniversityContracts/ViewModels/ReportDiscipline.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportDiscipline + { + //выбираем дисциплину, выбираем период, отображаются студенты зачисленные через приказ в этот период со статусами обучения + } +} diff --git a/UniversityContracts/ViewModels/ReportStreamEducationGroup.cs b/UniversityContracts/ViewModels/ReportStreamEducationGroup.cs new file mode 100644 index 0000000..9373391 --- /dev/null +++ b/UniversityContracts/ViewModels/ReportStreamEducationGroup.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportStreamEducationGroup + { + // при выборе потока показывается список студентов на потоке и их статус обучения + } +} diff --git a/UniversityDataBaseImplemet/Database.cs b/UniversityDataBaseImplemet/Database.cs index af816dd..3ec12e1 100644 --- a/UniversityDataBaseImplemet/Database.cs +++ b/UniversityDataBaseImplemet/Database.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UniversityDataBaseImplemet.Models; +using Stream = UniversityDataBaseImplemet.Models.Stream; namespace UniversityDataBaseImplemet { @@ -20,9 +21,15 @@ namespace UniversityDataBaseImplemet } public virtual DbSet User { get; set; } public virtual DbSet Documents { get; set; } + public virtual DbSet Discipline { get; set; } public virtual DbSet EducationStatuses { get; set; } + public virtual DbSet EducationGroups { get; set; } + public virtual DbSet EducationGroupsDocuments { get; set; } + public virtual DbSet EducationGroupsStreams { get; set; } + public virtual DbSet Streams { get; set; } public virtual DbSet Students { get; set; } public virtual DbSet StudentDocuments { get; set; } + public virtual DbSet StudentStreams { get; set; } public virtual DbSet Roles { get; set; } } } diff --git a/UniversityDataBaseImplemet/Implements/DisciplineStorage.cs b/UniversityDataBaseImplemet/Implements/DisciplineStorage.cs new file mode 100644 index 0000000..0040889 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/DisciplineStorage.cs @@ -0,0 +1,106 @@ +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 DisciplineStorage:IDisciplineStorage + { + public DisciplineViewModel? GetElement(DisciplineSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.Discipline + .FirstOrDefault(record => record.Id == model.Id + || record.Name.Equals(model.Name)) + ?.GetViewModel; + } + public List GetFilteredList(DisciplineSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.Discipline + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.Discipline + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.Discipline + .Select(record => record.GetViewModel) + .ToList(); + } + public DisciplineViewModel? Insert(DisciplineBindingModel model) + { + var newDiscipline = Discipline.Create(model); + if (newDiscipline == null) + { + return null; + } + using var context = new Database(); + context.Discipline.Add(newDiscipline); + context.SaveChanges(); + return newDiscipline.GetViewModel; + } + public DisciplineViewModel? Update(DisciplineBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var stream = context.Discipline + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (stream == null) + { + return null; + } + stream.Update(model); + context.SaveChanges(); + transaction.Commit(); + return stream.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public DisciplineViewModel? Delete(DisciplineBindingModel model) + { + using var context = new Database(); + var stream = context.Discipline + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (stream == null) + { + return null; + } + context.Discipline.Remove(stream); + context.SaveChanges(); + return stream.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Implements/EducationGroupStorage.cs b/UniversityDataBaseImplemet/Implements/EducationGroupStorage.cs new file mode 100644 index 0000000..644cb19 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/EducationGroupStorage.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; +using UniversityDataBaseImplemet.Models; + +namespace UniversityDataBaseImplemet.Implements +{ + public class EducationGroupStorage + { + public EducationGroupViewModel? GetElement(EducationGroupSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.EducationGroups + .FirstOrDefault(record => record.Id == model.Id + || record.Name.Equals(model.Name)) + ?.GetViewModel; + } + public List GetFilteredList(EducationGroupSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.EducationGroups + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.EducationGroups + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.EducationGroups + .Select(record => record.GetViewModel) + .ToList(); + } + public EducationGroupViewModel? Insert(EducationGroupBindingModel model) + { + var newEducationGroup = EducationGroup.Create(model); + if (newEducationGroup == null) + { + return null; + } + using var context = new Database(); + context.EducationGroups.Add(newEducationGroup); + context.SaveChanges(); + return newEducationGroup.GetViewModel; + } + public EducationGroupViewModel? Update(EducationGroupBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var educationgroup = context.EducationGroups + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (educationgroup == null) + { + return null; + } + educationgroup.Update(model); + context.SaveChanges(); + transaction.Commit(); + return educationgroup.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public EducationGroupViewModel? Delete(EducationGroupBindingModel model) + { + using var context = new Database(); + var educationgroup = context.EducationGroups + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (educationgroup == null) + { + return null; + } + context.EducationGroups.Remove(educationgroup); + context.SaveChanges(); + return educationgroup.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Implements/StreamStorage.cs b/UniversityDataBaseImplemet/Implements/StreamStorage.cs new file mode 100644 index 0000000..cdcc7d1 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/StreamStorage.cs @@ -0,0 +1,107 @@ +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 Stream = UniversityDataBaseImplemet.Models.Stream; + +namespace UniversityDataBaseImplemet.Implements +{ + public class StreamStorage:IStreamStorage + { + public StreamViewModel? GetElement(StreamSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.Streams + .FirstOrDefault(record => record.Id == model.Id + || record.Name.Equals(model.Name)) + ?.GetViewModel; + } + public List GetFilteredList(StreamSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.Streams + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.Streams + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.Streams + .Select(record => record.GetViewModel) + .ToList(); + } + public StreamViewModel? Insert(StreamBindingModel model) + { + var newStream = Stream.Create(model); + if (newStream == null) + { + return null; + } + using var context = new Database(); + context.Streams.Add(newStream); + context.SaveChanges(); + return newStream.GetViewModel; + } + public StreamViewModel? Update(StreamBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var stream = context.Streams + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (stream == null) + { + return null; + } + stream.Update(model); + context.SaveChanges(); + transaction.Commit(); + return stream.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public StreamViewModel? Delete(StreamBindingModel model) + { + using var context = new Database(); + var stream = context.Streams + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (stream == null) + { + return null; + } + context.Streams.Remove(stream); + context.SaveChanges(); + return stream.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Implements/UserStorage.cs b/UniversityDataBaseImplemet/Implements/UserStorage.cs index 658a5ca..0c310b1 100644 --- a/UniversityDataBaseImplemet/Implements/UserStorage.cs +++ b/UniversityDataBaseImplemet/Implements/UserStorage.cs @@ -1,11 +1,4 @@ using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts;