Реализация хранилищ

This commit is contained in:
ityurner02@mail.ru 2023-04-09 23:34:46 +04:00
parent 298be7e0df
commit 98b2139237
29 changed files with 997 additions and 165 deletions

View File

@ -6,7 +6,7 @@ namespace ElectronicJournalContracts.BindingModels
{
public string Form { get; set; } = string.Empty;
public DateTime Date { get; set; }
public DateOnly Date { get; set; }
public string Mark { get; set; } = string.Empty;

View File

@ -4,7 +4,7 @@ namespace ElectronicJournalContracts.BindingModels
{
public class StatementBindingModel : IStatement
{
public DateTime Date { get; set; }
public DateOnly Date { get; set; }
public int DisciplineId { get; set; }

View File

@ -6,7 +6,7 @@ namespace ElectronicJournalContracts.BindingModels
{
public string Name { get; set; } = string.Empty;
public string Academic_title { get; set; } = string.Empty;
public string AcademicTitle { get; set; } = string.Empty;
public int Id { get; set; }
}

View File

@ -4,7 +4,8 @@
{
public int? Id { get; set; }
public string? Form { get; set; }
public DateTime? Date { get; set; }
public DateOnly? DateFrom { get; set; }
public DateOnly? DateTo { get; set; }
public string? Mark { get; set; }
public int? StudentId { get; set; }
public string? StudentName { get; set; }

View File

@ -3,7 +3,8 @@
public class StatementSearchModel
{
public int? Id { get; set; }
public DateTime? Date { get; set; }
public DateOnly? DateFrom { get; set; }
public DateOnly? DateTo { get; set; }
public int? DisciplineId { get; set; }
public string? DisciplineName { get; set; }
public int? GroupId { get; set; }

View File

@ -10,7 +10,7 @@ namespace ElectronicJournalContracts.ViewModels
[DisplayName("Форма")]
public string Form { get; set; } = string.Empty;
[DisplayName("Дата")]
public DateTime Date { get; set; }
public DateOnly Date { get; set; }
[DisplayName("Оценка")]
public string Mark { get; set; } = string.Empty;
public int StudentId { get; set; }

View File

@ -8,7 +8,7 @@ namespace ElectronicJournalContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
[DisplayName("Дата")]
public DateTime Date { get; set; }
public DateOnly Date { get; set; }
public int DisciplineId { get; set; }
[DisplayName("Дисциплина")]
public string DisciplineName { get; set; } = string.Empty;

View File

@ -10,6 +10,6 @@ namespace ElectronicJournalContracts.ViewModels
[DisplayName("Имя")]
public string Name { get; set; } = string.Empty;
[DisplayName("Ученое звание")]
public string Academic_title { get; set; } = string.Empty;
public string AcademicTitle { get; set; } = string.Empty;
}
}

View File

@ -3,7 +3,7 @@
public interface IResultOfControl : IId
{
string Form { get; }
DateTime Date { get; }
DateOnly Date { get; }
string Mark { get; }
int StudentId { get; }
int StatementId { get; }

View File

@ -2,7 +2,7 @@
{
public interface IStatement : IId
{
DateTime Date { get; }
DateOnly Date { get; }
int DisciplineId { get; }
int GroupId { get; }
int TeacherId { get; }

View File

@ -3,6 +3,6 @@
public interface ITeacher : IId
{
string Name { get; }
string Academic_title { get; }
string AcademicTitle { get; }
}
}

View File

@ -1,23 +0,0 @@
using ElectronicJournalDataModels.Models;
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement;
/// <summary>
/// Данная таблица отвечает за хранение данных по дисциплинам. Содержит два поля: id (тип integer), название (тип varchar).
/// </summary>
public partial class Discipline
{
/// <summary>
/// Идентификатор дисциплины
/// </summary>
public int Id { get; set; }
/// <summary>
/// Название
/// </summary>
public string Title { get; set; } = null!;
public virtual ICollection<Statement> Statements { get; } = new List<Statement>();
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using ElectronicJournalDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ElectronicJournalDatabaseImplement;

View File

@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement;
/// <summary>
/// Данная таблица отвечает за хранение данных по группам. Содержит три поля: id (тип integer), название (тип varchar), курс (тип integer).
/// </summary>
public partial class Group
{
/// <summary>
/// Идентификатор группы
/// </summary>
public int Id { get; set; }
/// <summary>
/// Название
/// </summary>
public string Title { get; set; } = null!;
/// <summary>
/// Курс
/// </summary>
public int Course { get; set; }
public virtual ICollection<Statement> Statements { get; } = new List<Statement>();
public virtual ICollection<Student> Students { get; } = new List<Student>();
}

View File

@ -0,0 +1,84 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.SearchModels;
using ElectronicJournalContracts.StorageContracts;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDatabaseImplement.Models;
namespace ElectronicJournalDatabaseImplement.Implements
{
public class DisciplineStorage : IDisciplineStorage
{
public DisciplineViewModel? Delete(DisciplineBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var element = context.Disciplines.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Disciplines.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public DisciplineViewModel? GetElement(DisciplineSearchModel model)
{
if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue)
{
return null;
}
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Disciplines
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Title) && x.Title == model.Title) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<DisciplineViewModel> GetFilteredList(DisciplineSearchModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Disciplines
.OrderBy(x => x.Title)
.Where(x => x.Title.Contains(model.Title))
.Select(x => x.GetViewModel)
.ToList();
}
public List<DisciplineViewModel> GetFullList()
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Disciplines
.OrderBy(x => x.Title)
.Select(x => x.GetViewModel)
.ToList();
}
public DisciplineViewModel? Insert(DisciplineBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
model.Id = context.Disciplines.Count() > 0 ? context.Disciplines.Max(x => x.Id) + 1 : 1;
var newDiscipline = Discipline.Create(model);
if (newDiscipline == null)
{
return null;
}
context.Disciplines.Add(newDiscipline);
context.SaveChanges();
return newDiscipline.GetViewModel;
}
public DisciplineViewModel? Update(DisciplineBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var discipline = context.Disciplines.FirstOrDefault(x => x.Id == model.Id);
if (discipline == null)
{
return null;
}
discipline.Update(model);
context.SaveChanges();
return discipline.GetViewModel;
}
}
}

View File

@ -0,0 +1,84 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.SearchModels;
using ElectronicJournalContracts.StorageContracts;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDatabaseImplement.Models;
namespace ElectronicJournalDatabaseImplement.Implements
{
public class GroupStorage : IGroupStorage
{
public GroupViewModel? Delete(GroupBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var element = context.Groups.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Groups.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public GroupViewModel? GetElement(GroupSearchModel model)
{
if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue)
{
return null;
}
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Groups
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Title) && x.Title == model.Title && x.Course == model.Course) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<GroupViewModel> GetFilteredList(GroupSearchModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Groups
.OrderBy(x => x.Title)
.Where(x => x.Title.Contains(model.Title) || x.Course == model.Course)
.Select(x => x.GetViewModel)
.ToList();
}
public List<GroupViewModel> GetFullList()
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Groups
.OrderBy(x => x.Title)
.Select(x => x.GetViewModel)
.ToList();
}
public GroupViewModel? Insert(GroupBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
model.Id = context.Groups.Count() > 0 ? context.Groups.Max(x => x.Id) + 1 : 1;
var newGroup = Group.Create(model);
if (newGroup == null)
{
return null;
}
context.Groups.Add(newGroup);
context.SaveChanges();
return newGroup.GetViewModel;
}
public GroupViewModel? Update(GroupBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var group = context.Groups.FirstOrDefault(x => x.Id == model.Id);
if (group == null)
{
return null;
}
group.Update(model);
context.SaveChanges();
return group.GetViewModel;
}
}
}

View File

@ -0,0 +1,105 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.SearchModels;
using ElectronicJournalContracts.StorageContracts;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDatabaseImplement.Models;
using ElectronicJournalDataModels.Models;
using Microsoft.EntityFrameworkCore;
namespace ElectronicJournalDatabaseImplement.Implements
{
public class ResultOfControlStorage : IResultOfControlStorage
{
public ResultOfControlViewModel? Delete(ResultOfControlBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var element = context.ResultOfControls.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.ResultOfControls
.Include(x => x.Student)
.Include(x => x.Statement)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
context.ResultOfControls.Remove(element);
context.SaveChanges();
return deletedElement;
}
return null;
}
public ResultOfControlViewModel? GetElement(ResultOfControlSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
ElectronicJournalContext context = new ElectronicJournalContext();
return context.ResultOfControls
.Include(x => x.Student)
.Include(x => x.Statement)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
public List<ResultOfControlViewModel> GetFilteredList(ResultOfControlSearchModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.ResultOfControls
.OrderBy(x => x.Date)
.Include(x => x.Student)
.Include(x => x.Statement)
.Where(x =>
(x.Date >= model.DateFrom && x.Date <= model.DateTo)
|| x.Student.Name.Contains(model.StudentName)
|| x.StatementId == model.StatementId)
.Select(x => x.GetViewModel)
.ToList();
}
public List<ResultOfControlViewModel> GetFullList()
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.ResultOfControls
.OrderBy(x => x.Date)
.Include(x => x.Student)
.Include(x => x.Statement)
.Select(x => x.GetViewModel)
.ToList();
}
public ResultOfControlViewModel? Insert(ResultOfControlBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
model.Id = context.ResultOfControls.Count() > 0 ? context.ResultOfControls.Max(x => x.Id) + 1 : 1;
var newResultOfControl = ResultOfControl.Create(model);
if (newResultOfControl == null)
{
return null;
}
context.ResultOfControls.Add(newResultOfControl);
context.SaveChanges();
return context.ResultOfControls
.Include(x => x.Student)
.Include(x => x.Statement)
.FirstOrDefault(x => x.Id == newResultOfControl.Id)
?.GetViewModel;
}
public ResultOfControlViewModel? Update(ResultOfControlBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var result = context.ResultOfControls.FirstOrDefault(x => x.Id == model.Id);
if (result == null)
{
return null;
}
result.Update(model);
context.SaveChanges();
return context.ResultOfControls
.Include(x => x.Student)
.Include(x => x.Statement)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
}
}

View File

@ -0,0 +1,111 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.SearchModels;
using ElectronicJournalContracts.StorageContracts;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ElectronicJournalDatabaseImplement.Implements
{
public class StatementStorage : IStatementStorage
{
public StatementViewModel? Delete(StatementBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var element = context.Statements.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.Statements
.Include(x => x.Discipline)
.Include(x => x.Group)
.Include(x => x.Teacher)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
context.Statements.Remove(element);
context.SaveChanges();
return deletedElement;
}
return null;
}
public StatementViewModel? GetElement(StatementSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Statements
.Include(x => x.Discipline)
.Include(x => x.Group)
.Include(x => x.Teacher)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
public List<StatementViewModel> GetFilteredList(StatementSearchModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Statements
.OrderBy(x => x.Date)
.Include(x => x.Discipline)
.Include(x => x.Group)
.Include(x => x.Teacher)
.Where(x =>
(x.Date >= model.DateFrom && x.Date <= model.DateTo)
|| x.Discipline.Title.Contains(model.DisciplineName)
|| x.Group.Title.Contains(model.GroupName)
|| x.Teacher.Name.Contains(model.TeacherName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<StatementViewModel> GetFullList()
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Statements
.OrderBy(x => x.Date)
.Include(x => x.Discipline)
.Include(x => x.Group)
.Include(x => x.Teacher)
.Select(x => x.GetViewModel)
.ToList();
}
public StatementViewModel? Insert(StatementBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
model.Id = context.Statements.Count() > 0 ? context.Statements.Max(x => x.Id) + 1 : 1;
var newStatement = Statement.Create(model);
if (newStatement == null)
{
return null;
}
context.Statements.Add(newStatement);
context.SaveChanges();
return context.Statements
.Include(x => x.Discipline)
.Include(x => x.Group)
.Include(x => x.Teacher)
.FirstOrDefault(x => x.Id == newStatement.Id)
?.GetViewModel;
}
public StatementViewModel? Update(StatementBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var statement = context.Statements.FirstOrDefault(x => x.Id == model.Id);
if (statement == null)
{
return null;
}
statement.Update(model);
context.SaveChanges();
return context.Statements
.Include(x => x.Discipline)
.Include(x => x.Group)
.Include(x => x.Teacher)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
}
}

View File

@ -0,0 +1,100 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.SearchModels;
using ElectronicJournalContracts.StorageContracts;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ElectronicJournalDatabaseImplement.Implements
{
public class StudentStorage : IStudentStorage
{
public StudentViewModel? Delete(StudentBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var element = context.Students.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.Students
.Include(x => x.Group)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
context.Students.Remove(element);
context.SaveChanges();
return deletedElement;
}
return null;
}
public StudentViewModel? GetElement(StudentSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Students
.Include(x => x.Group)
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<StudentViewModel> GetFilteredList(StudentSearchModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Students
.OrderBy(x => x.Name)
.Include(x => x.Group)
.Where(x =>
x.Name.Contains(model.Name)
|| x.Group.Title.Contains(model.GroupName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<StudentViewModel> GetFullList()
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Students
.OrderBy(x => x.Name)
.Include(x => x.Group)
.Select(x => x.GetViewModel)
.ToList();
}
public StudentViewModel? Insert(StudentBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
model.Id = context.Students.Count() > 0 ? context.Students.Max(x => x.Id) + 1 : 1;
var newStudent = Student.Create(model);
if (newStudent == null)
{
return null;
}
context.Students.Add(newStudent);
context.SaveChanges();
return context.Students
.Include(x => x.Group)
.FirstOrDefault(x => x.Id == newStudent.Id)
?.GetViewModel;
}
public StudentViewModel? Update(StudentBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var student = context.Students.FirstOrDefault(x => x.Id ==
model.Id);
if (student == null)
{
return null;
}
student.Update(model);
context.SaveChanges();
return context.Students
.Include(x => x.Group)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
}
}

View File

@ -0,0 +1,84 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.SearchModels;
using ElectronicJournalContracts.StorageContracts;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDatabaseImplement.Models;
namespace ElectronicJournalDatabaseImplement.Implements
{
public class TeacherStorage : ITeacherStorage
{
public TeacherViewModel? Delete(TeacherBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var element = context.Teachers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Teachers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public TeacherViewModel? GetElement(TeacherSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Teachers
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && x.AcademicTitle == model.Academic_title) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<TeacherViewModel> GetFilteredList(TeacherSearchModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Teachers
.OrderBy(x => x.Name)
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.ToList();
}
public List<TeacherViewModel> GetFullList()
{
ElectronicJournalContext context = new ElectronicJournalContext();
return context.Teachers
.OrderBy(x => x.Name)
.Select(x => x.GetViewModel)
.ToList();
}
public TeacherViewModel? Insert(TeacherBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
model.Id = context.Teachers.Count() > 0 ? context.Teachers.Max(x => x.Id) + 1 : 1;
var newTeacher = Teacher.Create(model);
if (newTeacher == null)
{
return null;
}
context.Teachers.Add(newTeacher);
context.SaveChanges();
return newTeacher.GetViewModel;
}
public TeacherViewModel? Update(TeacherBindingModel model)
{
ElectronicJournalContext context = new ElectronicJournalContext();
var teacher = context.Teachers.FirstOrDefault(x => x.Id == model.Id);
if (teacher == null)
{
return null;
}
teacher.Update(model);
context.SaveChanges();
return teacher.GetViewModel;
}
}
}

View File

@ -0,0 +1,58 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDataModels.Models;
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement.Models;
/// <summary>
/// Данная таблица отвечает за хранение данных по дисциплинам. Содержит два поля: id (тип integer), название (тип varchar).
/// </summary>
public partial class Discipline : IDiscipline
{
/// <summary>
/// Идентификатор дисциплины
/// </summary>
public int Id { get; set; }
/// <summary>
/// Название
/// </summary>
public string Title { get; set; } = null!;
public virtual List<Statement> Statements { get; } = new List<Statement>();
public static Discipline? Create(DisciplineBindingModel model)
{
if (model == null)
{
return null;
}
return new Discipline()
{
Id = model.Id,
Title = model.Title
};
}
public static Discipline Create(DisciplineViewModel model)
{
return new Discipline
{
Id = model.Id,
Title = model.Title
};
}
public void Update(DisciplineBindingModel model)
{
if (model == null)
{
return;
}
Title = model.Title;
}
public DisciplineViewModel GetViewModel => new()
{
Id = Id,
Title = Title
};
}

View File

@ -0,0 +1,69 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDataModels.Models;
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement.Models;
/// <summary>
/// Данная таблица отвечает за хранение данных по группам. Содержит три поля: id (тип integer), название (тип varchar), курс (тип integer).
/// </summary>
public partial class Group : IGroup
{
/// <summary>
/// Идентификатор группы
/// </summary>
public int Id { get; set; }
/// <summary>
/// Название
/// </summary>
public string Title { get; set; } = null!;
/// <summary>
/// Курс
/// </summary>
public int Course { get; set; }
public virtual List<Statement> Statements { get; } = new List<Statement>();
public virtual List<Student> Students { get; } = new List<Student>();
public static Group? Create(GroupBindingModel model)
{
if (model == null)
{
return null;
}
return new Group()
{
Id = model.Id,
Title = model.Title,
Course = model.Course
};
}
public static Group Create(GroupViewModel model)
{
return new Group
{
Id = model.Id,
Title = model.Title,
Course = model.Course
};
}
public void Update(GroupBindingModel model)
{
if (model == null)
{
return;
}
Title = model.Title;
Course = model.Course;
}
public GroupViewModel GetViewModel => new()
{
Id = Id,
Title = Title,
Course = Course
};
}

View File

@ -1,12 +1,16 @@
using System;
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDataModels.Models;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace ElectronicJournalDatabaseImplement;
namespace ElectronicJournalDatabaseImplement.Models;
/// <summary>
/// Данная таблица отвечает за хранение данных по результатам контроля. Содержит шесть полей: id (тип integer), форма контроля (тип varchar), дата (тип date), оценка (тип varchar), внешний ключ на студента (тип integer), внешний ключ на ведомость (тип integer).
/// </summary>
public partial class ResultOfControl
public partial class ResultOfControl : IResultOfControl
{
/// <summary>
/// Идентификатор результата контроля
@ -41,4 +45,54 @@ public partial class ResultOfControl
public virtual Statement Statement { get; set; } = null!;
public virtual Student Student { get; set; } = null!;
public static ResultOfControl? Create(ResultOfControlBindingModel model)
{
if (model == null)
{
return null;
}
return new ResultOfControl()
{
Id = model.Id,
Form = model.Form,
Date = model.Date,
Mark = model.Mark,
StudentId = model.StudentId,
StatementId = model.StatementId
};
}
public static ResultOfControl Create(ResultOfControlViewModel model)
{
return new ResultOfControl
{
Id = model.Id,
Form = model.Form,
Date = model.Date,
Mark = model.Mark,
StudentId = model.StudentId,
StatementId = model.StatementId
};
}
public void Update(ResultOfControlBindingModel model)
{
if (model == null)
{
return;
}
Form = model.Form;
Date = model.Date;
Mark = model.Mark;
StudentId = model.StudentId;
StatementId = model.StatementId;
}
public ResultOfControlViewModel GetViewModel => new()
{
Id = Id,
Form = Form,
Date = Date,
Mark = Mark,
StudentId = StudentId,
StatementId = StatementId,
StudentName = Student.Name
};
}

View File

@ -0,0 +1,94 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDataModels.Models;
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement.Models;
/// <summary>
/// Данная таблица отвечает за хранение данных по ведомостям. Содержит пять полей: id (тип integer), дата (тип date), внешний ключ на дисциплину (тип integer), внешний ключ на группу (тип integer), внешний ключ на преподавателя (тип integer).
/// </summary>
public partial class Statement : IStatement
{
/// <summary>
/// Идентификатор ведомости
/// </summary>
public int Id { get; set; }
/// <summary>
/// Дата
/// </summary>
public DateOnly Date { get; set; }
/// <summary>
/// Внешний ключ на дисциплину
/// </summary>
public int DisciplineId { get; set; }
/// <summary>
/// Внешний ключ на группу
/// </summary>
public int GroupId { get; set; }
/// <summary>
/// Внешний ключ на преподавателя
/// </summary>
public int TeacherId { get; set; }
public virtual Discipline Discipline { get; set; } = null!;
public virtual Group Group { get; set; } = null!;
public virtual List<ResultOfControl> ResultOfControls { get; } = new List<ResultOfControl>();
public virtual Teacher Teacher { get; set; } = null!;
public static Statement? Create(StatementBindingModel model)
{
if (model == null)
{
return null;
}
return new Statement()
{
Id = model.Id,
Date = model.Date,
DisciplineId = model.DisciplineId,
TeacherId = model.TeacherId,
GroupId = model.GroupId
};
}
public static Statement Create(StatementViewModel model)
{
return new Statement
{
Id = model.Id,
Date = model.Date,
DisciplineId = model.DisciplineId,
TeacherId = model.TeacherId,
GroupId = model.GroupId
};
}
public void Update(StatementBindingModel model)
{
if (model == null)
{
return;
}
Date = model.Date;
DisciplineId = model.DisciplineId;
TeacherId = model.TeacherId;
GroupId = model.GroupId;
}
public StatementViewModel GetViewModel => new()
{
Id = Id,
Date = Date,
DisciplineId = DisciplineId,
GroupId = GroupId,
TeacherId = TeacherId,
DisciplineName = Discipline.Title,
GroupName = Group.Title,
TeacherName = Teacher.Name
};
}

View File

@ -0,0 +1,70 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDataModels.Models;
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement.Models;
/// <summary>
/// Данная таблица отвечает за хранение данных по студентам. Содержит три поля: id (тип integer), имя (тип varchar), внешний ключ на группу (тип integer).
/// </summary>
public partial class Student : IStudent
{
/// <summary>
/// Идентификатор студента
/// </summary>
public int Id { get; set; }
/// <summary>
/// Имя
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// Внешний ключ на группу
/// </summary>
public int GroupId { get; set; }
public virtual Group Group { get; set; } = null!;
public virtual List<ResultOfControl> ResultOfControls { get; } = new List<ResultOfControl>();
public static Student? Create(StudentBindingModel model)
{
if (model == null)
{
return null;
}
return new Student()
{
Id = model.Id,
Name = model.Name,
GroupId = model.GroupId
};
}
public static Student Create(StudentViewModel model)
{
return new Student
{
Id = model.Id,
Name = model.Name,
GroupId = model.GroupId
};
}
public void Update(StudentBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
GroupId = model.GroupId;
}
public StudentViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
GroupId = GroupId,
GroupName = Group.Title
};
}

View File

@ -0,0 +1,67 @@
using ElectronicJournalContracts.BindingModels;
using ElectronicJournalContracts.ViewModels;
using ElectronicJournalDataModels.Models;
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement.Models;
/// <summary>
/// Данная таблица отвечает за хранение данных по преподавателям. Содержит три поля: id (тип integer), имя (тип varchar), ученое звание (тип integer).
/// </summary>
public partial class Teacher : ITeacher
{
/// <summary>
/// Идентификатор преподавателя
/// </summary>
public int Id { get; set; }
/// <summary>
/// Имя
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// Ученое звание
/// </summary>
public string? AcademicTitle { get; set; }
public virtual List<Statement> Statements { get; } = new List<Statement>();
public static Teacher? Create(TeacherBindingModel model)
{
if (model == null)
{
return null;
}
return new Teacher()
{
Id = model.Id,
Name = model.Name,
AcademicTitle = model.AcademicTitle
};
}
public static Teacher Create(TeacherViewModel model)
{
return new Teacher
{
Id = model.Id,
Name = model.Name,
AcademicTitle = model.AcademicTitle
};
}
public void Update(TeacherBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
AcademicTitle = model.AcademicTitle;
}
public TeacherViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
AcademicTitle = AcademicTitle
};
}

View File

@ -1,43 +0,0 @@
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement;
/// <summary>
/// Данная таблица отвечает за хранение данных по ведомостям. Содержит пять полей: id (тип integer), дата (тип date), внешний ключ на дисциплину (тип integer), внешний ключ на группу (тип integer), внешний ключ на преподавателя (тип integer).
/// </summary>
public partial class Statement
{
/// <summary>
/// Идентификатор ведомости
/// </summary>
public int Id { get; set; }
/// <summary>
/// Дата
/// </summary>
public DateOnly Date { get; set; }
/// <summary>
/// Внешний ключ на дисциплину
/// </summary>
public int DisciplineId { get; set; }
/// <summary>
/// Внешний ключ на группу
/// </summary>
public int GroupId { get; set; }
/// <summary>
/// Внешний ключ на преподавателя
/// </summary>
public int TeacherId { get; set; }
public virtual Discipline Discipline { get; set; } = null!;
public virtual Group Group { get; set; } = null!;
public virtual ICollection<ResultOfControl> ResultOfControls { get; } = new List<ResultOfControl>();
public virtual Teacher Teacher { get; set; } = null!;
}

View File

@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement;
/// <summary>
/// Данная таблица отвечает за хранение данных по студентам. Содержит три поля: id (тип integer), имя (тип varchar), внешний ключ на группу (тип integer).
/// </summary>
public partial class Student
{
/// <summary>
/// Идентификатор студента
/// </summary>
public int Id { get; set; }
/// <summary>
/// Имя
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// Внешний ключ на группу
/// </summary>
public int GroupId { get; set; }
public virtual Group Group { get; set; } = null!;
public virtual ICollection<ResultOfControl> ResultOfControls { get; } = new List<ResultOfControl>();
}

View File

@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
namespace ElectronicJournalDatabaseImplement;
/// <summary>
/// Данная таблица отвечает за хранение данных по преподавателям. Содержит три поля: id (тип integer), имя (тип varchar), ученое звание (тип integer).
/// </summary>
public partial class Teacher
{
/// <summary>
/// Идентификатор преподавателя
/// </summary>
public int Id { get; set; }
/// <summary>
/// Имя
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// Ученое звание
/// </summary>
public string? AcademicTitle { get; set; }
public virtual ICollection<Statement> Statements { get; } = new List<Statement>();
}