2024-04-24 14:57:31 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
2024-04-18 20:20:50 +04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-04-24 14:57:31 +04:00
|
|
|
|
using UniversityContracts.BindingModels;
|
|
|
|
|
using UniversityContracts.SearchModels;
|
2024-04-18 20:20:50 +04:00
|
|
|
|
using UniversityContracts.StorageContracts;
|
2024-04-24 14:57:31 +04:00
|
|
|
|
using UniversityContracts.ViewModels;
|
|
|
|
|
using UniversityDatabaseImplement.Models;
|
2024-04-18 20:20:50 +04:00
|
|
|
|
|
|
|
|
|
namespace UniversityDatabaseImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class PlanOfStudyStorage : IPlanOfStudyStorage
|
|
|
|
|
{
|
2024-04-24 14:57:31 +04:00
|
|
|
|
public List<PlanOfStudyViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
using var context = new UniversityDatabase();
|
|
|
|
|
|
2024-05-28 19:50:44 +04:00
|
|
|
|
return context.PlanOfStudys
|
|
|
|
|
.Include(x => x.Teachers)
|
|
|
|
|
.ThenInclude(t => t.Teacher)
|
|
|
|
|
.ToList()
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
2024-04-24 14:57:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 17:22:43 +04:00
|
|
|
|
public List<DisciplineViewModel> GetDisciplineFromStudentsFromPlanOfStudys(PlanOfStudySearchModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new UniversityDatabase();
|
|
|
|
|
|
|
|
|
|
var students = context.Students
|
|
|
|
|
.Where(s => s.PlanOfStudyId == model.Id)
|
|
|
|
|
.Include(s => s.StudentDiscipline)
|
2024-05-28 22:09:26 +04:00
|
|
|
|
.ThenInclude(sd => sd.Discipline)
|
2024-05-02 17:22:43 +04:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
if(students == null)
|
|
|
|
|
{
|
|
|
|
|
return new List<DisciplineViewModel>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Получаем список дисциплин, которые соответствуют условиям поиска в модели PlanOfStudySearchModel
|
|
|
|
|
var disciplines = students
|
|
|
|
|
.SelectMany(s => s.StudentDiscipline)
|
|
|
|
|
.Distinct()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
if (disciplines == null)
|
|
|
|
|
{
|
|
|
|
|
return new List<DisciplineViewModel>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Преобразуем список дисциплин в список DisciplineViewModel и возвращаем его
|
|
|
|
|
return disciplines
|
|
|
|
|
.Select(d => d.Discipline.GetViewModel).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 14:57:31 +04:00
|
|
|
|
public List<PlanOfStudyViewModel> GetFilteredList(PlanOfStudySearchModel model)
|
|
|
|
|
{
|
2024-05-27 17:32:21 +04:00
|
|
|
|
if(model == null)
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
2024-04-24 14:57:31 +04:00
|
|
|
|
using var context = new UniversityDatabase();
|
2024-05-02 17:22:43 +04:00
|
|
|
|
var query = context.PlanOfStudys
|
2024-05-28 19:50:44 +04:00
|
|
|
|
.Include(x => x.Teachers)
|
|
|
|
|
.ThenInclude(x => x.Teacher)
|
2024-05-02 17:22:43 +04:00
|
|
|
|
.Include(x => x.Students)
|
2024-05-27 17:32:21 +04:00
|
|
|
|
.Include(x => x.User)
|
2024-05-02 17:22:43 +04:00
|
|
|
|
.AsQueryable();
|
2024-05-27 17:32:21 +04:00
|
|
|
|
if (model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.Id == model.Id.Value);
|
|
|
|
|
}
|
2024-05-02 17:22:43 +04:00
|
|
|
|
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
2024-04-24 14:57:31 +04:00
|
|
|
|
{
|
2024-05-02 17:22:43 +04:00
|
|
|
|
query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value);
|
2024-05-27 17:32:21 +04:00
|
|
|
|
};
|
|
|
|
|
return query.Select(x => x.GetViewModel).ToList();
|
2024-04-24 14:57:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PlanOfStudyViewModel? GetElement(PlanOfStudySearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (!model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new UniversityDatabase();
|
2024-05-28 19:50:44 +04:00
|
|
|
|
return context.PlanOfStudys
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.Include(x => x.Teachers)
|
|
|
|
|
.ThenInclude(x => x.Teacher)
|
|
|
|
|
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
|
|
|
|
|
.GetViewModel;
|
2024-04-24 14:57:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PlanOfStudyViewModel? Insert(PlanOfStudyBindingModel model)
|
|
|
|
|
{
|
2024-04-29 00:07:50 +04:00
|
|
|
|
using var context = new UniversityDatabase();
|
|
|
|
|
var newAttestation = PlanOfStudy.Create(context, model);
|
2024-04-24 14:57:31 +04:00
|
|
|
|
|
|
|
|
|
if (newAttestation == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 00:07:50 +04:00
|
|
|
|
context.PlanOfStudys.Add(newAttestation);
|
2024-04-24 14:57:31 +04:00
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
return newAttestation.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PlanOfStudyViewModel? Update(PlanOfStudyBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new UniversityDatabase();
|
2024-05-29 02:49:07 +04:00
|
|
|
|
var planOfStudy = context.PlanOfStudys.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
if (planOfStudy == null)
|
2024-04-24 14:57:31 +04:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-05-29 02:49:07 +04:00
|
|
|
|
planOfStudy.Update(model);
|
|
|
|
|
planOfStudy.UpdateTeachers(context, model);
|
2024-04-24 14:57:31 +04:00
|
|
|
|
context.SaveChanges();
|
2024-05-29 02:49:07 +04:00
|
|
|
|
return context.PlanOfStudys
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.Include(x => x.Teachers)
|
|
|
|
|
.ThenInclude(x => x.Teacher)
|
|
|
|
|
.FirstOrDefault(x => x.Id == model.Id)?
|
|
|
|
|
.GetViewModel;
|
2024-04-24 14:57:31 +04:00
|
|
|
|
}
|
2024-05-28 17:08:06 +04:00
|
|
|
|
public PlanOfStudyViewModel? Delete(PlanOfStudyBindingModel model)
|
2024-04-24 14:57:31 +04:00
|
|
|
|
{
|
|
|
|
|
using var context = new UniversityDatabase();
|
2024-04-29 00:07:50 +04:00
|
|
|
|
var element = context.PlanOfStudys.FirstOrDefault(rec => rec.Id == model.Id);
|
2024-04-24 14:57:31 +04:00
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
2024-04-29 00:07:50 +04:00
|
|
|
|
context.PlanOfStudys.Remove(element);
|
2024-04-24 14:57:31 +04:00
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-04-18 20:20:50 +04:00
|
|
|
|
}
|
|
|
|
|
}
|