Начата работа над базой данных
This commit is contained in:
parent
f93bc290e3
commit
e1482243ed
@ -9,6 +9,6 @@ namespace UniversityContracts.SearchModels
|
|||||||
public class AttestationSearchModel
|
public class AttestationSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? FormOfEvaluation { get; set; }
|
public int? StudentId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,99 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
using UniversityContracts.StorageContracts;
|
using UniversityContracts.StorageContracts;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityDatabaseImplement.Models;
|
||||||
|
|
||||||
namespace UniversityDatabaseImplement.Implements
|
namespace UniversityDatabaseImplement.Implements
|
||||||
{
|
{
|
||||||
public class AttestationStorage : IAttestationStorage
|
public class AttestationStorage : IAttestationStorage
|
||||||
{
|
{
|
||||||
|
public List<AttestationViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
|
||||||
|
return context.Attestations.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AttestationViewModel> GetFilteredList(AttestationSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Attestations
|
||||||
|
.Include(x => x.Student)
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.StudentId.HasValue)
|
||||||
|
{
|
||||||
|
return context.Attestations
|
||||||
|
.Include(x => x.Student)
|
||||||
|
.Where(x => x.StudentId == model.StudentId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttestationViewModel? GetElement(AttestationSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
return context.Attestations.Include(x => x.Student).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttestationViewModel? Insert(AttestationBindingModel model)
|
||||||
|
{
|
||||||
|
var newAttestation = Attestation.Create(model);
|
||||||
|
|
||||||
|
if (newAttestation == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
|
||||||
|
context.Attestations.Add(newAttestation);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return newAttestation.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AttestationViewModel? Update(AttestationBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
var order = context.Attestations.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.Attestations.Include(x => x.Student).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
public AttestationViewModel? Delete(AttestationBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
var element = context.Attestations.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Attestations.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,99 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
using UniversityContracts.StorageContracts;
|
using UniversityContracts.StorageContracts;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityDatabaseImplement.Models;
|
||||||
|
|
||||||
namespace UniversityDatabaseImplement.Implements
|
namespace UniversityDatabaseImplement.Implements
|
||||||
{
|
{
|
||||||
public class PlanOfStudyStorage : IPlanOfStudyStorage
|
public class PlanOfStudyStorage : IPlanOfStudyStorage
|
||||||
{
|
{
|
||||||
|
public List<PlanOfStudyViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
|
||||||
|
return context.PlanOfStudys.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PlanOfStudyViewModel> GetFilteredList(PlanOfStudySearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.PlanOfStudys
|
||||||
|
.Include(x => x.Student)
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.StudentId.HasValue)
|
||||||
|
{
|
||||||
|
return context.Attestations
|
||||||
|
.Include(x => x.Student)
|
||||||
|
.Where(x => x.StudentId == model.StudentId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlanOfStudyViewModel? GetElement(PlanOfStudySearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
return context.Attestations.Include(x => x.Student).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlanOfStudyViewModel? Insert(PlanOfStudyBindingModel model)
|
||||||
|
{
|
||||||
|
var newAttestation = Attestation.Create(model);
|
||||||
|
|
||||||
|
if (newAttestation == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
|
||||||
|
context.Attestations.Add(newAttestation);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return newAttestation.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlanOfStudyViewModel? Update(PlanOfStudyBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
var order = context.Attestations.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.Attestations.Include(x => x.Student).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
public PlanOfStudyViewModel? Delete(PlanOfStudyBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new UniversityDatabase();
|
||||||
|
var element = context.Attestations.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Attestations.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,63 +1,66 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UniversityContracts.BindingModels;
|
using UniversityContracts.BindingModels;
|
||||||
using UniversityContracts.ViewModels;
|
using UniversityContracts.ViewModels;
|
||||||
using UniversityDataModels.Models;
|
using UniversityDataModels.Enums;
|
||||||
|
using UniversityDataModels.Models;
|
||||||
namespace UniversityDatabaseImplement.Models
|
using static System.Formats.Asn1.AsnWriter;
|
||||||
{
|
|
||||||
public class Attestation : IAttestationModel
|
namespace UniversityDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public class Attestation : IAttestationModel
|
||||||
public int StudentId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public string FormOfEvaluation { get; private set; } = string.Empty;
|
|
||||||
[Required]
|
|
||||||
public string Score { get; private set; } = string.Empty;
|
|
||||||
}
|
|
||||||
public static Student? Create(StudentBindingModel model)
|
|
||||||
{
|
{
|
||||||
if (model == null)
|
public int Id { get; private set; }
|
||||||
|
public int StudentId { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string FormOfEvaluation { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public AttestationScore Score { get; private set; } = AttestationScore.Неявка;
|
||||||
|
public virtual Student Student { get; set; } = new();
|
||||||
|
public static Attestation? Create(AttestationBindingModel model)
|
||||||
{
|
{
|
||||||
return null;
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Attestation()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
StudentId = model.StudentId,
|
||||||
|
FormOfEvaluation = model.FormOfEvaluation,
|
||||||
|
Score = model.Score
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return new Student()
|
public static Attestation Create(AttestationViewModel model)
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
return new Attestation
|
||||||
PlanOfStudyId = model.PlanOfStudyId,
|
{
|
||||||
Name = model.Name,
|
Id = model.Id,
|
||||||
PhoneNumber = model.PhoneNumber
|
StudentId = model.StudentId,
|
||||||
|
FormOfEvaluation = model.FormOfEvaluation,
|
||||||
|
Score = model.Score
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(AttestationBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StudentId = model.StudentId;
|
||||||
|
FormOfEvaluation = model.FormOfEvaluation;
|
||||||
|
Score = model.Score;
|
||||||
|
}
|
||||||
|
public AttestationViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
StudentId = StudentId,
|
||||||
|
FormOfEvaluation = FormOfEvaluation,
|
||||||
|
Score = Score
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static Student Create(StudentViewModel model)
|
}
|
||||||
{
|
|
||||||
return new Student
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
PlanOfStudyId = model.PlanOfStudyId,
|
|
||||||
Name = model.Name,
|
|
||||||
PhoneNumber = model.PhoneNumber
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public void Update(StudentBindingModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PhoneNumber = model.PhoneNumber;
|
|
||||||
Name = model.Name;
|
|
||||||
PlanOfStudyId = model.PlanOfStudyId;
|
|
||||||
}
|
|
||||||
public StudentViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
PlanOfStudyId = PlanOfStudyId,
|
|
||||||
Name = Name,
|
|
||||||
PhoneNumber = PhoneNumber
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
@ -13,8 +13,8 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public class PlanOfStudy : IPlanOfStudyModel
|
public class PlanOfStudy : IPlanOfStudyModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; private set; }
|
||||||
public int WorkerId { get; set; }
|
public int WorkerId { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Profile { get; private set; } = string.Empty;
|
public string Profile { get; private set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
@ -35,6 +35,7 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
[ForeignKey("PlanOfStudyId")]
|
[ForeignKey("PlanOfStudyId")]
|
||||||
public virtual List<PlanOfStudyTeacher> Teachers { get; set; } = new();
|
public virtual List<PlanOfStudyTeacher> Teachers { get; set; } = new();
|
||||||
|
public virtual Worker Worker { get; set; } = new();
|
||||||
public static PlanOfStudy Create(UniversityDatabase context, PlanOfStudyBindingModel model)
|
public static PlanOfStudy Create(UniversityDatabase context, PlanOfStudyBindingModel model)
|
||||||
{
|
{
|
||||||
return new PlanOfStudy()
|
return new PlanOfStudy()
|
||||||
|
@ -14,7 +14,7 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
public int PlanOfStudyId { get; set; }
|
public int PlanOfStudyId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int TeacherId { get; set; }
|
public int TeacherId { get; set; }
|
||||||
public virtual PlanOfStudy PlanOfStudy { get; set; }
|
public virtual PlanOfStudy PlanOfStudy { get; set; } = new();
|
||||||
public virtual Teacher Teacher { get; set; }
|
public virtual Teacher Teacher { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ namespace UniversityDatabaseImplement.Models
|
|||||||
public string PhoneNumber { get; private set; } = string.Empty;
|
public string PhoneNumber { get; private set; } = string.Empty;
|
||||||
[ForeignKey("StudentId")]
|
[ForeignKey("StudentId")]
|
||||||
public virtual List<StudentDiscipline> StudentDiscipline { get; set; } = new();
|
public virtual List<StudentDiscipline> StudentDiscipline { get; set; } = new();
|
||||||
|
public virtual PlanOfStudy PlanOfStudy { get; set; } = new();
|
||||||
public static Student? Create(StudentBindingModel model)
|
public static Student? Create(StudentBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
|
14
University/UniversityDatabaseImplement/Models/Worker.cs
Normal file
14
University/UniversityDatabaseImplement/Models/Worker.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniversityDataModels.Models;
|
||||||
|
|
||||||
|
namespace UniversityDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Worker : IWorkerModel
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user