добавление оставшихся хранилищ
This commit is contained in:
parent
95e2b5f94f
commit
f66f89c461
79
CarService/CarServiceDatabase/Implements/CustomerStorage.cs
Normal file
79
CarService/CarServiceDatabase/Implements/CustomerStorage.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using CarServiceContracts.BindingModels;
|
||||||
|
using CarServiceContracts.SearchModels;
|
||||||
|
using CarServiceContracts.StorageContracts;
|
||||||
|
using CarServiceContracts.ViewModels;
|
||||||
|
using CarServiceDatabase.Models;
|
||||||
|
|
||||||
|
namespace CarServiceDatabase.Implements
|
||||||
|
{
|
||||||
|
public class CustomerStorage : ICustomerStorage
|
||||||
|
{
|
||||||
|
public List<CustomerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
return context.Customers
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<CustomerViewModel> GetFilteredList(CustomerSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
return context.Customers
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public CustomerViewModel? GetElement(CustomerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
if (model.Id.HasValue)//ищем по Id
|
||||||
|
{
|
||||||
|
return context.Customers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
//другие варианты поиска не реализуются (заглушка для роли клиента)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CustomerViewModel? Insert(CustomerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var newCustomer = Customer.Create(model);
|
||||||
|
if (newCustomer != null)
|
||||||
|
{
|
||||||
|
context.Customers.Add(newCustomer);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newCustomer.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CustomerViewModel? Update(CustomerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var customer = context.Customers
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (customer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
customer.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return customer.GetViewModel;
|
||||||
|
}
|
||||||
|
public CustomerViewModel? Delete(CustomerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var customer = context.Customers
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (customer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Customers.Remove(customer);
|
||||||
|
context.SaveChanges();
|
||||||
|
return customer.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
CarService/CarServiceDatabase/Implements/VehicleStorage.cs
Normal file
78
CarService/CarServiceDatabase/Implements/VehicleStorage.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using CarServiceContracts.BindingModels;
|
||||||
|
using CarServiceContracts.SearchModels;
|
||||||
|
using CarServiceContracts.StorageContracts;
|
||||||
|
using CarServiceContracts.ViewModels;
|
||||||
|
using CarServiceDatabase.Models;
|
||||||
|
|
||||||
|
namespace CarServiceDatabase.Implements
|
||||||
|
{
|
||||||
|
public class VehicleStorage : IVehicleStorage
|
||||||
|
{
|
||||||
|
public List<VehicleViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
return context.Vehicles
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<VehicleViewModel> GetFilteredList(VehicleSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
return context.Vehicles
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public VehicleViewModel? GetElement(VehicleSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
if (model.Id.HasValue)//ищем по Id
|
||||||
|
{
|
||||||
|
return context.Vehicles.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public VehicleViewModel? Insert(VehicleBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var newVehicle = Vehicle.Create(model);
|
||||||
|
if (newVehicle != null)
|
||||||
|
{
|
||||||
|
context.Vehicles.Add(newVehicle);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newVehicle.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public VehicleViewModel? Update(VehicleBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var vehicle = context.Vehicles
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (vehicle == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
vehicle.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return vehicle.GetViewModel;
|
||||||
|
}
|
||||||
|
public VehicleViewModel? Delete(VehicleBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var vehicle = context.Vehicles
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (vehicle == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Vehicles.Remove(vehicle);
|
||||||
|
context.SaveChanges();
|
||||||
|
return vehicle.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
using CarServiceContracts.BindingModels;
|
||||||
|
using CarServiceContracts.SearchModels;
|
||||||
|
using CarServiceContracts.StorageContracts;
|
||||||
|
using CarServiceContracts.ViewModels;
|
||||||
|
using CarServiceDatabase.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace CarServiceDatabase.Implements
|
||||||
|
{
|
||||||
|
public class WorkInRequestStorage : IWorkInRequestStorage
|
||||||
|
{
|
||||||
|
public List<WorkInRequestViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
return context.WorksInRequest
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<WorkInRequestViewModel> GetFilteredList(WorkInRequestSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
return context.WorksInRequest
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public WorkInRequestViewModel? GetElement(WorkInRequestSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.WorksInRequest
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public WorkInRequestViewModel? Insert(WorkInRequestBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var newWorkInRequest = WorkInRequest.Create(model);
|
||||||
|
if (newWorkInRequest != null)
|
||||||
|
{
|
||||||
|
context.WorksInRequest.Add(newWorkInRequest);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newWorkInRequest.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public WorkInRequestViewModel? Update(WorkInRequestBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var workInRequest = context.WorksInRequest.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (workInRequest == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
workInRequest.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return workInRequest.GetViewModel;
|
||||||
|
}
|
||||||
|
public WorkInRequestViewModel? Delete(WorkInRequestBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var workInRequest = context.WorksInRequest.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (workInRequest == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.WorksInRequest.Remove(workInRequest);
|
||||||
|
context.SaveChanges();
|
||||||
|
return workInRequest.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
using CarServiceContracts.BindingModels;
|
||||||
|
using CarServiceContracts.SearchModels;
|
||||||
|
using CarServiceContracts.StorageContracts;
|
||||||
|
using CarServiceContracts.ViewModels;
|
||||||
|
using CarServiceDatabase.Models;
|
||||||
|
|
||||||
|
namespace CarServiceDatabase.Implements
|
||||||
|
{
|
||||||
|
public class WorkPaymentStorage : IWorkPaymentStorage
|
||||||
|
{
|
||||||
|
public List<WorkPaymentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
return context.WorkPayments
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<WorkPaymentViewModel> GetFilteredList(WorkPaymentSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
return context.WorkPayments
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public WorkPaymentViewModel? GetElement(WorkPaymentSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.WorkPayments
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public WorkPaymentViewModel? Insert(WorkPaymentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var newWorkPayment = WorkPayment.Create(model);
|
||||||
|
if (newWorkPayment != null)
|
||||||
|
{
|
||||||
|
context.WorkPayments.Add(newWorkPayment);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newWorkPayment.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public WorkPaymentViewModel? Update(WorkPaymentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var workPayment = context.WorkPayments.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (workPayment == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
workPayment.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return workPayment.GetViewModel;
|
||||||
|
}
|
||||||
|
public WorkPaymentViewModel? Delete(WorkPaymentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new CarServiceDbContext();
|
||||||
|
var workPayment = context.WorkPayments.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (workPayment == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.WorkPayments.Remove(workPayment);
|
||||||
|
context.SaveChanges();
|
||||||
|
return workPayment.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user