need report

This commit is contained in:
ker73rus 2023-04-08 22:25:55 +04:00
parent 01d2821a87
commit f855a03cba
7 changed files with 351 additions and 7 deletions

View File

@ -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
{
//выбираем дисциплину, выбираем период, отображаются студенты зачисленные через приказ в этот период со статусами обучения
}
}

View File

@ -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
{
// при выборе потока показывается список студентов на потоке и их статус обучения
}
}

View File

@ -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> User { get; set; }
public virtual DbSet<Document> Documents { get; set; }
public virtual DbSet<Discipline> Discipline { get; set; }
public virtual DbSet<EducationStatus> EducationStatuses { get; set; }
public virtual DbSet<EducationGroup> EducationGroups { get; set; }
public virtual DbSet<EducationGroupDocument> EducationGroupsDocuments { get; set; }
public virtual DbSet<EducationGroupStream> EducationGroupsStreams { get; set; }
public virtual DbSet<Stream> Streams { get; set; }
public virtual DbSet<Student> Students { get; set; }
public virtual DbSet<StudentDocument> StudentDocuments { get; set; }
public virtual DbSet<StudentStream> StudentStreams { get; set; }
public virtual DbSet<Role> Roles { get; set; }
}
}

View File

@ -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<DisciplineViewModel> 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<DisciplineViewModel> 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;
}
}
}

View File

@ -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<EducationGroupViewModel> 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<EducationGroupViewModel> 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;
}
}
}

View File

@ -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<StreamViewModel> 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<StreamViewModel> 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;
}
}
}

View File

@ -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;