Половина Implements DbStorage,
Добавил UserId в большинство классов SearchModel
This commit is contained in:
parent
be1b5b1a1c
commit
f5a2f51591
@ -18,6 +18,8 @@ namespace CaseAccountingContracts.SearchModels
|
||||
|
||||
public DateTime? Date { get; set; }
|
||||
|
||||
public int? SpecializationId { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,7 @@ namespace CaseAccountingContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
|
||||
public DateTime? Date { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,7 @@ namespace CaseAccountingContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
|
||||
public DateTime? Date { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,5 +13,7 @@ namespace CaseAccountingContracts.SearchModels
|
||||
public DateTime? Date { get; set; }
|
||||
|
||||
public int? CaseId { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,7 @@ namespace CaseAccountingContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? SpecializationId { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,7 @@ namespace CaseAccountingContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,169 @@
|
||||
using CaseAccountingContracts.BindingModels;
|
||||
using CaseAccountingContracts.SearchModels;
|
||||
using CaseAccountingContracts.StoragesContracts;
|
||||
using CaseAccountingContracts.ViewModels;
|
||||
using CaseAccountingDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CaseAccountingDataBaseImplement.Implements
|
||||
{
|
||||
public class CaseStorage : ICaseStorage
|
||||
{
|
||||
public CaseViewModel? Delete(CaseBindingModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
var element = context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Cases.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public CaseViewModel? GetElement(CaseSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CaseAccountingDatabase();
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CaseViewModel> GetFilteredList(CaseSearchModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.Name != null)
|
||||
{
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Name == model.Name)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.Applicant != null)
|
||||
{
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Applicant == model.Applicant)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.Defendant != null)
|
||||
{
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Defendant == model.Defendant)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.Date != null)
|
||||
{
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Date == model.Date)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.SpecializationId.HasValue)
|
||||
{
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.SpecializationId == model.SpecializationId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
|
||||
public List<CaseViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public CaseViewModel? Insert(CaseBindingModel model)
|
||||
{
|
||||
var newCase = Case.Create(model);
|
||||
if (newCase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new CaseAccountingDatabase();
|
||||
|
||||
context.Cases.Add(newCase);
|
||||
context.SaveChanges();
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == newCase.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public CaseViewModel? Update(CaseBindingModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
|
||||
var _case = context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (_case == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_case.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Cases
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
using CaseAccountingContracts.SearchModels;
|
||||
using CaseAccountingContracts.StoragesContracts;
|
||||
using CaseAccountingContracts.ViewModels;
|
||||
using CaseAccountingDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -14,33 +16,127 @@ namespace CaseAccountingDataBaseImplement.Implements
|
||||
{
|
||||
public HearingViewModel? Delete(HearingBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public HearingViewModel? GetElement(HearingSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public List<HearingViewModel> GetFilteredList(HearingSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public List<HearingViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
return context.Hearings.Select(x => x.GetViewModel).ToList();
|
||||
return context.Hearings
|
||||
.Include(x => x.Case)
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public HearingViewModel? Insert(HearingBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public HearingViewModel? Update(HearingBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,133 @@
|
||||
using CaseAccountingContracts.BindingModels;
|
||||
using CaseAccountingContracts.SearchModels;
|
||||
using CaseAccountingContracts.StoragesContracts;
|
||||
using CaseAccountingContracts.ViewModels;
|
||||
using CaseAccountingDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CaseAccountingDataBaseImplement.Implements
|
||||
{
|
||||
public class LawyerStorage : ILawyerStorage
|
||||
{
|
||||
public LawyerViewModel? Delete(LawyerBindingModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
var element = context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Lawyers.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public LawyerViewModel? GetElement(LawyerSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CaseAccountingDatabase();
|
||||
return context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<LawyerViewModel> GetFilteredList(LawyerSearchModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
return context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.SpecializationId.HasValue)
|
||||
{
|
||||
return context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.SpecializationId == model.SpecializationId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
|
||||
public List<LawyerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
return context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public LawyerViewModel? Insert(LawyerBindingModel model)
|
||||
{
|
||||
var newLawyer = Lawyer.Create(model);
|
||||
if (newLawyer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new CaseAccountingDatabase();
|
||||
|
||||
context.Lawyers.Add(newLawyer);
|
||||
context.SaveChanges();
|
||||
return context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == newLawyer.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public LawyerViewModel? Update(LawyerBindingModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
|
||||
var lawyer = context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (lawyer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
lawyer.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Lawyers
|
||||
.Include(x => x.Specialization)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
using CaseAccountingContracts.BindingModels;
|
||||
using CaseAccountingContracts.SearchModels;
|
||||
using CaseAccountingContracts.StoragesContracts;
|
||||
using CaseAccountingContracts.ViewModels;
|
||||
using CaseAccountingDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CaseAccountingDataBaseImplement.Implements
|
||||
{
|
||||
public class SpecializationStorage : ISpecializationStorage
|
||||
{
|
||||
public SpecializationViewModel? Delete(SpecializationBindingModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
var element = context.Specializations
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Specializations.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public SpecializationViewModel? GetElement(SpecializationSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CaseAccountingDatabase();
|
||||
return context.Specializations
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<SpecializationViewModel> GetFilteredList(SpecializationSearchModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Specializations
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.Name != null)
|
||||
{
|
||||
return context.Specializations
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Name == model.Name)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
return context.Specializations
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
}
|
||||
|
||||
public List<SpecializationViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
return context.Specializations
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public SpecializationViewModel? Insert(SpecializationBindingModel model)
|
||||
{
|
||||
var newSpecialization = Specialization.Create(model);
|
||||
if (newSpecialization == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new CaseAccountingDatabase();
|
||||
|
||||
context.Specializations.Add(newSpecialization);
|
||||
context.SaveChanges();
|
||||
return context.Specializations
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == newSpecialization.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public SpecializationViewModel? Update(SpecializationBindingModel model)
|
||||
{
|
||||
using var context = new CaseAccountingDatabase();
|
||||
|
||||
var specialization = context.Specializations
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (specialization == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
specialization.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Specializations
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user