57 lines
2.6 KiB
C#
57 lines
2.6 KiB
C#
|
using CoreDatabase;
|
|||
|
using CoreDatabase.Models.Department;
|
|||
|
using DepartmentContract.BindingModels;
|
|||
|
using DepartmentContract.Services.IGenericEntityService;
|
|||
|
using DepartmentContract.ViewModels;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
using System.Linq;
|
|||
|
using ToolsModule.ManagmentEntity;
|
|||
|
|
|||
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Реализация интерфейса IBasicDepartmentService
|
|||
|
/// </summary>
|
|||
|
public class BasicDepartmentService :
|
|||
|
AbstractGenerticEntityService<BasicDepartmentGetBindingModel, BasicDepartmentSetBindingModel, BasicDepartment, BasicDepartmentListViewModel, BasicDepartmentViewModel>,
|
|||
|
IBasicDepartmentService
|
|||
|
{
|
|||
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, BasicDepartmentSetBindingModel model) => OperationResultModel.Success(null);
|
|||
|
|
|||
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, BasicDepartment entity, BasicDepartmentGetBindingModel model) => OperationResultModel.Success(null);
|
|||
|
|
|||
|
protected override IQueryable<BasicDepartment> AdditionalCheckingWhenReadingList(IQueryable<BasicDepartment> query, BasicDepartmentGetBindingModel model)
|
|||
|
{
|
|||
|
if (model.LecturerId.HasValue)
|
|||
|
{
|
|||
|
query = query.Where(x => x.LecturerId == model.LecturerId.Value);
|
|||
|
}
|
|||
|
return query;
|
|||
|
}
|
|||
|
|
|||
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, BasicDepartmentSetBindingModel model) => OperationResultModel.Success(null);
|
|||
|
|
|||
|
protected override void AdditionalDeleting(DbContext context, BasicDepartment entity, BasicDepartmentGetBindingModel model)
|
|||
|
{
|
|||
|
var studentrecords = context.Set<Student>().Where(x => x.BasicDepartmentId == model.Id);
|
|||
|
foreach (var record in studentrecords)
|
|||
|
{
|
|||
|
record.BasicDepartmentId = null;
|
|||
|
}
|
|||
|
context.SaveChanges();
|
|||
|
|
|||
|
var disciplinerecords = context.Set<Discipline>().Where(x => x.BasicDepartmentId == model.Id);
|
|||
|
foreach (var record in disciplinerecords)
|
|||
|
{
|
|||
|
record.BasicDepartmentId = null;
|
|||
|
}
|
|||
|
context.SaveChanges();
|
|||
|
}
|
|||
|
|
|||
|
protected override BasicDepartment GetUniqueEntity(BasicDepartmentSetBindingModel model, DbContext context) => context.Set<BasicDepartment>().FirstOrDefault(x => x.BasicDepartmentName == model.BasicDepartmentName && x.Id != model.Id);
|
|||
|
|
|||
|
protected override IQueryable<BasicDepartment> IncludingWhenReading(IQueryable<BasicDepartment> query) => query.Include(x => x.Lecturer);
|
|||
|
|
|||
|
protected override IQueryable<BasicDepartment> OrderingWhenReading(IQueryable<BasicDepartment> query) => query.OrderBy(x => x.BasicDepartmentName);
|
|||
|
}
|
|||
|
}
|