Исполнитель: реализация коммитов
This commit is contained in:
parent
90a164c508
commit
73a0f8af3f
@ -10,7 +10,6 @@ namespace VeterinaryContracts.StorageContracts
|
||||
List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model);
|
||||
PurchaseViewModel? GetElement(PurchaseSearchModel model);
|
||||
PurchaseViewModel? Insert(PurchaseBindingModel model);
|
||||
PurchaseViewModel? Update(PurchaseBindingModel model);
|
||||
PurchaseViewModel? Delete(PurchaseBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace VeterinaryContracts.StorageContracts
|
||||
List<VisitViewModel> GetFilteredList(VisitSearchModel model);
|
||||
VisitViewModel? GetElement(VisitSearchModel model);
|
||||
VisitViewModel? Insert(VisitBindingModel model);
|
||||
VisitViewModel? Update(VisitBindingModel model);
|
||||
VisitViewModel? Delete(VisitBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDatabaseImplement.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Implements
|
||||
{
|
||||
public class OwnerStorage : IOwnerStorage
|
||||
{
|
||||
public List<OwnerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Owners
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<OwnerViewModel> GetFilteredList(OwnerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.OwnerFIO) && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Owners
|
||||
.Where(x => (string.IsNullOrEmpty(model.OwnerFIO) || x.OwnerFIO.Contains(model.OwnerFIO) &&
|
||||
(string.IsNullOrEmpty(model.Login) || x.Login.Contains(model.Login)) &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public OwnerViewModel? GetElement(OwnerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.OwnerFIO) && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Owners
|
||||
.FirstOrDefault(x => (string.IsNullOrEmpty(model.OwnerFIO) || x.OwnerFIO == model.OwnerFIO) &&
|
||||
(!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Login) || x.Login == model.Login) &&
|
||||
(string.IsNullOrEmpty(model.Password) || x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public OwnerViewModel? Insert(OwnerBindingModel model)
|
||||
{
|
||||
var newOwner = Owner.Create(model);
|
||||
if (newOwner == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
context.Owners.Add(newOwner);
|
||||
context.SaveChanges();
|
||||
return newOwner.GetViewModel;
|
||||
}
|
||||
public OwnerViewModel? Update(OwnerBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var client = context.Owners.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
client.Update(model);
|
||||
context.SaveChanges();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
public OwnerViewModel? Delete(OwnerBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var element = context.Owners.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Owners.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDatabaseImplement.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Implements
|
||||
{
|
||||
public class PetStorage : IPetStorage
|
||||
{
|
||||
public List<PetViewModel> GetFullList()
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Pets
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<PetViewModel> GetFilteredList(PetSearchModel
|
||||
model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PetName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Pets
|
||||
.Where(x => x.PetName.Contains(model.PetName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public PetViewModel? GetElement(PetSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PetName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Pets
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.PetName) && x.PetName ==
|
||||
model.PetName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public PetViewModel? Insert(PetBindingModel model)
|
||||
{
|
||||
var newPet = Pet.Create(model);
|
||||
if (newPet == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
context.Pets.Add(newPet);
|
||||
context.SaveChanges();
|
||||
return newPet.GetViewModel;
|
||||
}
|
||||
public PetViewModel? Update(PetBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var component = context.Pets.FirstOrDefault(x => x.Id ==
|
||||
model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public PetViewModel? Delete(PetBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var element = context.Pets.FirstOrDefault(rec => rec.Id ==
|
||||
model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Pets.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDatabaseImplement.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Implements
|
||||
{
|
||||
public class PurchaseStorage : IPurchaseStorage
|
||||
{
|
||||
public List<PurchaseViewModel> GetFullList()
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Purchases.Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Owner)
|
||||
.Include(x => x.Drug).Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Purchases.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Drug)
|
||||
.Where(x => ((!model.Id.HasValue || x.Id == model.Id) &&
|
||||
(!model.DatePurchase.HasValue || x.DatePurchase >= model.DatePurchase) &&
|
||||
(!model.OwnerId.HasValue || x.OwnerId <= model.OwnerId) &&
|
||||
(!model.DrugId.HasValue || x.DrugId == model.DrugId)))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Purchases.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Drug).FirstOrDefault(
|
||||
x => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||
(model.OwnerId.HasValue && model.DrugId.HasValue &&
|
||||
x.OwnerId == model.OwnerId && x.DrugId == model.DrugId)))?.GetViewModel;
|
||||
}
|
||||
public PurchaseViewModel? Insert(PurchaseBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var newPurchase = Purchase.Create(context, model);
|
||||
if (newPurchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Purchases.Add(newPurchase);
|
||||
context.SaveChanges();
|
||||
return newPurchase.GetViewModel;
|
||||
}
|
||||
public PurchaseViewModel? Delete(PurchaseBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var element = context.Purchases.Include(x => x.Owner).Include(x => x.Pets).Include(x => x.Drug).FirstOrDefault
|
||||
(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Purchases.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Implements
|
||||
{
|
||||
public class VisitStorage : IVisitStorage
|
||||
{
|
||||
public List<VisitViewModel> GetFullList()
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Visits.Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Owner)
|
||||
.Include(x => x.Doctor).Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<VisitViewModel> GetFilteredList(VisitSearchModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Visits.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Doctor)
|
||||
.Where(x => ((!model.Id.HasValue || x.Id == model.Id) &&
|
||||
(!model.DateVisit.HasValue || x.DateVisit >= model.DateVisit) &&
|
||||
(!model.OwnerId.HasValue || x.OwnerId <= model.OwnerId) &&
|
||||
(!model.DoctorId.HasValue || x.DoctorId == model.DoctorId)))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public VisitViewModel? GetElement(VisitSearchModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Visits.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Doctor).FirstOrDefault(
|
||||
x => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||
(model.OwnerId.HasValue && model.DoctorId.HasValue &&
|
||||
x.OwnerId == model.OwnerId && x.DoctorId == model.DoctorId)))?.GetViewModel;
|
||||
}
|
||||
public VisitViewModel? Insert(VisitBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var newVisit = Visit.Create(context, model);
|
||||
if (newVisit == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Visits.Add(newVisit);
|
||||
context.SaveChanges();
|
||||
return newVisit.GetViewModel;
|
||||
}
|
||||
public VisitViewModel? Delete(VisitBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var element = context.Visits.Include(x => x.Owner).Include(x => x.Pets).Include(x => x.Doctor).FirstOrDefault
|
||||
(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Visits.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,8 +11,10 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int OwnerId { get; private set; }
|
||||
public virtual Owner? Owner { get; private set; }
|
||||
[Required]
|
||||
public int DrugId { get; private set; }
|
||||
public virtual Drug? Drug { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[Required]
|
||||
|
@ -11,8 +11,10 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int OwnerId { get; private set; }
|
||||
public virtual Owner? Owner { get; private set; }
|
||||
[Required]
|
||||
public int? DoctorId { get; private set; }
|
||||
public virtual Doctor? Doctor { get; private set; }
|
||||
[Required]
|
||||
public DateTime DateVisit { get; private set; }
|
||||
private Dictionary<int, IPetModel>? _visitPet = null;
|
||||
|
@ -11,10 +11,6 @@
|
||||
<ProjectReference Include="..\VeterinaryDataModels\VeterinaryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||
|
Loading…
Reference in New Issue
Block a user