2023-04-07 17:55:41 +04:00
|
|
|
|
using CaseAccountingContracts.BindingModels;
|
|
|
|
|
using CaseAccountingContracts.SearchModels;
|
|
|
|
|
using CaseAccountingContracts.StoragesContracts;
|
|
|
|
|
using CaseAccountingContracts.ViewModels;
|
2023-04-08 00:22:45 +04:00
|
|
|
|
using CaseAccountingDataBaseImplement.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-04-07 17:55:41 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CaseAccountingDataBaseImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class HearingStorage : IHearingStorage
|
|
|
|
|
{
|
|
|
|
|
public HearingViewModel? Delete(HearingBindingModel model)
|
|
|
|
|
{
|
2023-04-08 00:22:45 +04:00
|
|
|
|
using var context = new CaseAccountingDatabase();
|
|
|
|
|
var element = context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
context.Hearings.Remove(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return element.GetViewModel;
|
2023-04-07 17:55:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HearingViewModel? GetElement(HearingSearchModel model)
|
|
|
|
|
{
|
2023-04-08 00:22:45 +04:00
|
|
|
|
if (!model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new CaseAccountingDatabase();
|
|
|
|
|
return context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
|
|
|
|
?.GetViewModel;
|
2023-04-07 17:55:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<HearingViewModel> GetFilteredList(HearingSearchModel model)
|
|
|
|
|
{
|
2023-04-08 00:22:45 +04:00
|
|
|
|
using var context = new CaseAccountingDatabase();
|
|
|
|
|
if (model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.Where(x => x.Id == model.Id)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
else if (model.Date != null)
|
|
|
|
|
{
|
|
|
|
|
return context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.Where(x => x.Date == model.Date)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
else if (model.UserId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.Where(x => x.UserId == model.UserId)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
else if (model.CaseId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.Where(x => x.CaseId == model.CaseId)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
2023-04-07 17:55:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<HearingViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
using var context = new CaseAccountingDatabase();
|
2023-04-08 00:22:45 +04:00
|
|
|
|
return context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.Select(x => x.GetViewModel).ToList();
|
2023-04-07 17:55:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HearingViewModel? Insert(HearingBindingModel model)
|
|
|
|
|
{
|
2023-04-08 00:22:45 +04:00
|
|
|
|
var newHearing = Hearing.Create(model);
|
|
|
|
|
if (newHearing == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var context = new CaseAccountingDatabase();
|
|
|
|
|
|
|
|
|
|
context.Hearings.Add(newHearing);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.FirstOrDefault(x => x.Id == newHearing.Id)
|
|
|
|
|
?.GetViewModel;
|
2023-04-07 17:55:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HearingViewModel? Update(HearingBindingModel model)
|
|
|
|
|
{
|
2023-04-08 00:22:45 +04:00
|
|
|
|
using var context = new CaseAccountingDatabase();
|
|
|
|
|
|
|
|
|
|
var hearing = context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
|
|
|
|
|
if (hearing == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
hearing.Update(model);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return context.Hearings
|
|
|
|
|
.Include(x => x.Case)
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.FirstOrDefault(x => x.Id == model.Id)
|
|
|
|
|
?.GetViewModel;
|
2023-04-07 17:55:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|