6 laba storages
This commit is contained in:
parent
1d8c53582b
commit
6d669290c5
@ -4,8 +4,6 @@ using PizzeriaContracts.ViewModels;
|
|||||||
using PizzeriaDatabaseImplement.Models;
|
using PizzeriaDatabaseImplement.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PizzeriaContracts.StorageContracts;
|
using PizzeriaContracts.StorageContracts;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.Implements
|
namespace PizzeriaDatabaseImplement.Implements
|
||||||
{
|
{
|
||||||
@ -27,13 +25,41 @@ namespace PizzeriaDatabaseImplement.Implements
|
|||||||
using var context = new PizzeriaDatabase();
|
using var context = new PizzeriaDatabase();
|
||||||
if (model.DateFrom.HasValue)
|
if (model.DateFrom.HasValue)
|
||||||
{
|
{
|
||||||
return context.Orders.Include(x => x.Pizza).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
if (model.ClientId.HasValue)
|
if (model.ClientId.HasValue)
|
||||||
{
|
{
|
||||||
return context.Orders.Include(x => x.Pizza).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.Where(x => x.ClientId == model.ClientId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
return context.Orders.Include(x => x.Pizza).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
else if (model.ImplementerId.HasValue)
|
||||||
|
{
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.Where(x => x.ImplementerId == model.ImplementerId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
@ -43,7 +69,15 @@ namespace PizzeriaDatabaseImplement.Implements
|
|||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new PizzeriaDatabase();
|
using var context = new PizzeriaDatabase();
|
||||||
return context.Orders.Include(x => x.Pizza).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status)
|
||||||
|
|| model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId
|
||||||
|
|| model.Id.HasValue && x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
@ -58,7 +92,12 @@ namespace PizzeriaDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newOrder.GetViewModel;
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
@ -69,9 +108,14 @@ namespace PizzeriaDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
order.Update(model);
|
order.Update(context,model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return order.GetViewModel;
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
@ -80,9 +124,15 @@ namespace PizzeriaDatabaseImplement.Implements
|
|||||||
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (order != null)
|
if (order != null)
|
||||||
{
|
{
|
||||||
|
var deletedElement = context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
context.Orders.Remove(order);
|
context.Orders.Remove(order);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return order.GetViewModel;
|
return deletedElement;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ namespace PizzeriaDatabaseImplement
|
|||||||
public virtual DbSet<PizzaComponent> PizzaComponents { set; get; }
|
public virtual DbSet<PizzaComponent> PizzaComponents { set; get; }
|
||||||
public virtual DbSet<Order> Orders { set; get; }
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
public virtual DbSet<Client> Clients { set; get; }
|
public virtual DbSet<Client> Clients { set; get; }
|
||||||
|
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,16 +10,19 @@ namespace PizzeriaFileImplement
|
|||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string PizzaFileName = "Pizza.xml";
|
private readonly string PizzaFileName = "Pizza.xml";
|
||||||
private readonly string ClientFileName = "Client.xml";
|
private readonly string ClientFileName = "Client.xml";
|
||||||
|
private readonly string ImplementerFileName = "Implementer.xml";
|
||||||
public List<Component> Components { get; private set; }
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Pizza> Pizzas { get; private set; }
|
public List<Pizza> Pizzas { get; private set; }
|
||||||
public List<Client> Clients { get; private set; }
|
public List<Client> Clients { get; private set; }
|
||||||
|
public List<Implementer> Implementers { get; private set; }
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!;
|
Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
|
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||||
}
|
}
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
@ -34,6 +37,7 @@ namespace PizzeriaFileImplement
|
|||||||
public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement);
|
public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||||
|
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||||
|
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName,Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName,Func<XElement, T> selectFunction)
|
||||||
{
|
{
|
||||||
|
@ -31,12 +31,11 @@ namespace PizzeriaFileImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var order = source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id));
|
var order = source.Orders.FirstOrDefault(x =>
|
||||||
if (order == null)
|
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status)
|
||||||
{
|
|| model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId
|
||||||
return null;
|
|| model.Id.HasValue && x.Id == model.Id);
|
||||||
}
|
return order?.GetViewModel != null ? AddData(order.GetViewModel) : null;
|
||||||
return AddData(order.GetViewModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
@ -53,6 +52,11 @@ namespace PizzeriaFileImplement.Implements
|
|||||||
{
|
{
|
||||||
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AddData(x.GetViewModel)).ToList();
|
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AddData(x.GetViewModel)).ToList();
|
||||||
}
|
}
|
||||||
|
if (!model.ImplementerId.HasValue && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders.Where(x => x.ImplementerId == model.ImplementerId).Select(x => x.GetViewModel).ToList();
|
||||||
|
|
||||||
|
}
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +64,7 @@ namespace PizzeriaFileImplement.Implements
|
|||||||
{
|
{
|
||||||
return source.Orders.Select(x => AddData(x.GetViewModel)).ToList();
|
return source.Orders.Select(x => AddData(x.GetViewModel)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||||
|
@ -12,7 +12,7 @@ namespace PizzeriaFileImplement.Models
|
|||||||
public int PizzaId { get; private set; }
|
public int PizzaId { get; private set; }
|
||||||
|
|
||||||
public int ClientId { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
|
public int? ImplementerId { get; set; }
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
@ -33,6 +33,7 @@ namespace PizzeriaFileImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
PizzaId = model.PizzaId,
|
PizzaId = model.PizzaId,
|
||||||
|
ImplementerId = model.ImplementerId,
|
||||||
ClientId = model.ClientId,
|
ClientId = model.ClientId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
@ -51,6 +52,7 @@ namespace PizzeriaFileImplement.Models
|
|||||||
{
|
{
|
||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
PizzaId = Convert.ToInt32(element.Element("PizzaId")!.Value),
|
PizzaId = Convert.ToInt32(element.Element("PizzaId")!.Value),
|
||||||
|
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
|
||||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
@ -74,6 +76,7 @@ namespace PizzeriaFileImplement.Models
|
|||||||
Id = Id,
|
Id = Id,
|
||||||
PizzaId = PizzaId,
|
PizzaId = PizzaId,
|
||||||
ClientId = ClientId,
|
ClientId = ClientId,
|
||||||
|
ImplementerId = ImplementerId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
@ -85,6 +88,7 @@ namespace PizzeriaFileImplement.Models
|
|||||||
new XAttribute("Id", Id),
|
new XAttribute("Id", Id),
|
||||||
new XElement("PizzaId", PizzaId),
|
new XElement("PizzaId", PizzaId),
|
||||||
new XElement("ClientId", ClientId),
|
new XElement("ClientId", ClientId),
|
||||||
|
new XElement("ImplementerId", ImplementerId),
|
||||||
new XElement("Count", Count.ToString()),
|
new XElement("Count", Count.ToString()),
|
||||||
new XElement("Sum", Sum.ToString()),
|
new XElement("Sum", Sum.ToString()),
|
||||||
new XElement("Status", Status.ToString()),
|
new XElement("Status", Status.ToString()),
|
||||||
|
@ -9,11 +9,14 @@ namespace PizzeriaListImplement
|
|||||||
public List<Order> Orders { get; set; }
|
public List<Order> Orders { get; set; }
|
||||||
public List<Pizza> Pizzas { get; set; }
|
public List<Pizza> Pizzas { get; set; }
|
||||||
public List<Client> Clients { get; set; }
|
public List<Client> Clients { get; set; }
|
||||||
|
public List<Implementer> Implementers { get; set; }
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Pizzas = new List<Pizza>();
|
Pizzas = new List<Pizza>();
|
||||||
|
Clients = new List<Client>();
|
||||||
|
Implementers = new List<Implementer>();
|
||||||
}
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
public int PizzaId { get; private set; }
|
public int PizzaId { get; private set; }
|
||||||
|
|
||||||
public int ClientId { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
|
public int? ImplementerId { get; private set; }
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
@ -33,6 +34,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
PizzaId = model.PizzaId,
|
PizzaId = model.PizzaId,
|
||||||
ClientId = model.ClientId,
|
ClientId = model.ClientId,
|
||||||
|
ImplementerId = model.ImplementerId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -55,6 +57,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
Id = Id,
|
Id = Id,
|
||||||
PizzaId = PizzaId,
|
PizzaId = PizzaId,
|
||||||
ClientId = ClientId,
|
ClientId = ClientId,
|
||||||
|
ImplementerId = ImplementerId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
|
Loading…
Reference in New Issue
Block a user