Вроде пашет
This commit is contained in:
parent
62d4b6aebc
commit
8f6f381a25
@ -1,4 +1,9 @@
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,5 +14,96 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
public class PresaleStorage : IPresaleStorage
|
||||
{
|
||||
public PresaleViewModel? Delete(PresaleBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
var element = context.Presales
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
var deletedElement = context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
context.Presales.Remove(element);
|
||||
context.SaveChanges();
|
||||
return deletedElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PresaleViewModel? GetElement(PresaleSearchModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<PresaleViewModel> GetFilteredList(PresaleSearchModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<PresaleViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public PresaleViewModel? Insert(PresaleBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
var newPresale = Presale.Create(context, model);
|
||||
if (newPresale == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Presales.Add(newPresale);
|
||||
context.SaveChanges();
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.FirstOrDefault(x => x.Id == newPresale.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public PresaleViewModel? Update(PresaleBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
var order = context.Presales.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Presales
|
||||
.Include(x => x.Bundlings)
|
||||
.ThenInclude(x => x.Bundling)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,5 +14,90 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
public class RequestStorage : IRequestStorage
|
||||
{
|
||||
public RequestViewModel? Delete(RequestBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
var element = context.Requests
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
var deletedElement = context.Requests
|
||||
.Include(x => x.Presale)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
context.Requests.Remove(element);
|
||||
context.SaveChanges();
|
||||
return deletedElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public RequestViewModel? GetElement(RequestSearchModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return context.Requests
|
||||
.Include(x => x.Presale)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<RequestViewModel> GetFilteredList(RequestSearchModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Requests
|
||||
.Include(x => x.Presale)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<RequestViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
return context.Requests
|
||||
.Include(x => x.Presale)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public RequestViewModel? Insert(RequestBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
var newRequest = Request.Create(model);
|
||||
if (newRequest == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Requests.Add(newRequest);
|
||||
context.SaveChanges();
|
||||
return context.Requests
|
||||
.Include(x => x.Presale)
|
||||
.FirstOrDefault(x => x.Id == newRequest.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public RequestViewModel? Update(RequestBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
var order = context.Requests.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Requests
|
||||
.Include(x => x.Presale)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.BindingModels;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterContracts.StoragesContracts;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,5 +14,86 @@ namespace CarCenterDatabaseImplement.Implements
|
||||
{
|
||||
public class WorkerStorage : IWorkerStorage
|
||||
{
|
||||
public List<WorkerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
return context.Workers
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<WorkerViewModel> GetFilteredList(WorkerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var res = GetElement(model);
|
||||
|
||||
return res != null ? new() { res } : new();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public WorkerViewModel? GetElement(WorkerSearchModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
if (model.Id.HasValue)
|
||||
return context.Workers
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public WorkerViewModel? Delete(WorkerBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
var res = context.Workers
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
context.Workers.Remove(res);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public WorkerViewModel? Insert(WorkerBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
var res = Worker.Create(model);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
context.Workers.Add(res);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public WorkerViewModel? Update(WorkerBindingModel model)
|
||||
{
|
||||
using var context = new CarCenterDatabase();
|
||||
|
||||
var res = context.Workers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
res.Update(model);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user