add client in order
This commit is contained in:
parent
deea03b6a8
commit
13c7187a2d
@ -116,6 +116,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (model.ClientId <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Некорректный идентификатор клиента", nameof(model.ClientId));
|
||||||
|
}
|
||||||
if (model.PizzaId <= 0)
|
if (model.PizzaId <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Некорректный идентификатор пиццы", nameof(model.PizzaId));
|
throw new ArgumentNullException("Некорректный идентификатор пиццы", nameof(model.PizzaId));
|
||||||
|
@ -7,6 +7,7 @@ namespace PizzeriaContracts.BindingModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int PizzaId { get; set; }
|
public int PizzaId { get; set; }
|
||||||
|
public int ClientId { get; set; }
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
public class OrderSearchModel
|
public class OrderSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
public int? ClientId { get; set; }
|
||||||
public DateTime? DateFrom { get; set; }
|
public DateTime? DateFrom { get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
public DateTime? DateTo { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,10 @@ namespace PizzeriaContracts.ViewModels
|
|||||||
|
|
||||||
[DisplayName("Пицца")]
|
[DisplayName("Пицца")]
|
||||||
public string PizzaName { get; set; } = string.Empty;
|
public string PizzaName { get; set; } = string.Empty;
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("ФИО клиента")]
|
||||||
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Количество")]
|
[DisplayName("Количество")]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
@ -5,6 +5,7 @@ namespace PizzeriaDataModels.Models
|
|||||||
public interface IOrderModel : IId
|
public interface IOrderModel : IId
|
||||||
{
|
{
|
||||||
int PizzaId { get; }
|
int PizzaId { get; }
|
||||||
|
int ClientId { get; }
|
||||||
int Count { get; }
|
int Count { get; }
|
||||||
double Sum { get; }
|
double Sum { get; }
|
||||||
OrderStatus Status { get; }
|
OrderStatus Status { get; }
|
||||||
|
@ -16,29 +16,57 @@ namespace PizzeriaDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new PizzeriaDatabase();
|
using var context = new PizzeriaDatabase();
|
||||||
return context.Orders.Include(x => x.Pizza).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue && !model.DateFrom.HasValue)
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new PizzeriaDatabase();
|
using var context = new PizzeriaDatabase();
|
||||||
if (model.DateFrom.HasValue)
|
if (model.Id.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)
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.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.DateFrom != null && model.DateTo != null)
|
||||||
|
{
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.ClientId.HasValue)
|
||||||
|
{
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Where(x => x.ClientId == model.ClientId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new PizzeriaDatabase();
|
using var context = new PizzeriaDatabase();
|
||||||
return context.Orders.Include(x => x.Pizza).Select(x => x.GetViewModel).ToList();
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
var newOrder = Order.Create(model);
|
var newOrder = Order.Create(model);
|
||||||
@ -49,20 +77,28 @@ namespace PizzeriaDatabaseImplement.Implements
|
|||||||
using var context = new PizzeriaDatabase();
|
using var context = new PizzeriaDatabase();
|
||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return context.Orders.Include(x => x.Pizza).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
return context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new PizzeriaDatabase();
|
using var context = new PizzeriaDatabase();
|
||||||
var component = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (component == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
component.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
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)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -70,9 +106,14 @@ namespace PizzeriaDatabaseImplement.Implements
|
|||||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
|
var deletedElement = context.Orders
|
||||||
|
.Include(x => x.Pizza)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return element.GetViewModel;
|
return deletedElement;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ namespace PizzeriaDatabaseImplement.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public int PizzaId { get; private set; }
|
public int PizzaId { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
[Required]
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
@ -21,6 +23,7 @@ namespace PizzeriaDatabaseImplement.Models
|
|||||||
public DateTime DateCreate { get; private set; }
|
public DateTime DateCreate { get; private set; }
|
||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
public virtual Pizza Pizza { get; set; }
|
public virtual Pizza Pizza { get; set; }
|
||||||
|
public virtual Client Client { get; set; }
|
||||||
public static Order? Create(OrderBindingModel? model)
|
public static Order? Create(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -31,6 +34,7 @@ namespace PizzeriaDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
PizzaId = model.PizzaId,
|
PizzaId = model.PizzaId,
|
||||||
|
ClientId = model.ClientId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -52,6 +56,7 @@ namespace PizzeriaDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
PizzaId = PizzaId,
|
PizzaId = PizzaId,
|
||||||
|
ClientId = ClientId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
|
@ -21,7 +21,7 @@ namespace PizzeriaFileImplement.Implements
|
|||||||
{
|
{
|
||||||
source.Orders.Remove(element);
|
source.Orders.Remove(element);
|
||||||
source.SaveOrders();
|
source.SaveOrders();
|
||||||
return AddPizzaName(element.GetViewModel);
|
return AddData(element.GetViewModel);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -36,25 +36,29 @@ namespace PizzeriaFileImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return AddPizzaName(order.GetViewModel);
|
return AddData(order.GetViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
if (model.Id.HasValue)
|
||||||
{
|
{
|
||||||
|
return source.Orders.Where(x => x.Id == model.Id).Select(x => AddData(x.GetViewModel)).ToList();
|
||||||
|
}
|
||||||
|
else if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => AddData(x.GetViewModel)).ToList();
|
||||||
|
}
|
||||||
|
else if (model.ClientId.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AddData(x.GetViewModel)).ToList();
|
||||||
|
}
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
if (model.DateFrom.HasValue)
|
|
||||||
{
|
|
||||||
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => AddPizzaName(x.GetViewModel)).ToList();
|
|
||||||
}
|
|
||||||
return source.Orders.Where(x => x.Id == model.Id).Select(x => AddPizzaName(x.GetViewModel)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
return source.Orders.Select(x => AddPizzaName(x.GetViewModel)).ToList();
|
return source.Orders.Select(x => AddData(x.GetViewModel)).ToList();
|
||||||
}
|
}
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -66,7 +70,7 @@ namespace PizzeriaFileImplement.Implements
|
|||||||
}
|
}
|
||||||
source.Orders.Add(newOrder);
|
source.Orders.Add(newOrder);
|
||||||
source.SaveOrders();
|
source.SaveOrders();
|
||||||
return AddPizzaName(newOrder.GetViewModel);
|
return AddData(newOrder.GetViewModel);
|
||||||
}
|
}
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -77,13 +81,15 @@ namespace PizzeriaFileImplement.Implements
|
|||||||
}
|
}
|
||||||
order.Update(model);
|
order.Update(model);
|
||||||
source.SaveOrders();
|
source.SaveOrders();
|
||||||
return AddPizzaName(order.GetViewModel);
|
return AddData(order.GetViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OrderViewModel AddPizzaName(OrderViewModel model)
|
private OrderViewModel AddData(OrderViewModel model)
|
||||||
{
|
{
|
||||||
var selectedPizza = source.Pizzas.FirstOrDefault(x => x.Id == model.PizzaId);
|
var selectedPizza = source.Pizzas.FirstOrDefault(x => x.Id == model.PizzaId);
|
||||||
model.PizzaName = selectedPizza?.PizzaName;
|
model.PizzaName = selectedPizza?.PizzaName;
|
||||||
|
var selectedClient = source.Clients.FirstOrDefault(x => x.Id == model.ClientId);
|
||||||
|
model.ClientFIO = selectedClient?.ClientFIO ?? string.Empty;
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ namespace PizzeriaFileImplement.Models
|
|||||||
|
|
||||||
public int PizzaId { get; private set; }
|
public int PizzaId { get; private set; }
|
||||||
|
|
||||||
|
public int ClientId { 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; }
|
||||||
@ -31,6 +33,7 @@ namespace PizzeriaFileImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
PizzaId = model.PizzaId,
|
PizzaId = model.PizzaId,
|
||||||
|
ClientId = model.ClientId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -48,6 +51,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),
|
||||||
|
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),
|
||||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||||
@ -69,6 +73,7 @@ namespace PizzeriaFileImplement.Models
|
|||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
PizzaId = PizzaId,
|
PizzaId = PizzaId,
|
||||||
|
ClientId = ClientId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
@ -79,6 +84,7 @@ namespace PizzeriaFileImplement.Models
|
|||||||
public XElement GetXElement => new("Order",
|
public XElement GetXElement => new("Order",
|
||||||
new XAttribute("Id", Id),
|
new XAttribute("Id", Id),
|
||||||
new XElement("PizzaId", PizzaId),
|
new XElement("PizzaId", PizzaId),
|
||||||
|
new XElement("ClientId", ClientId),
|
||||||
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()),
|
||||||
|
@ -11,6 +11,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
|
|
||||||
public int PizzaId { get; private set; }
|
public int PizzaId { get; private set; }
|
||||||
|
|
||||||
|
public int ClientId { 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; }
|
||||||
@ -31,6 +32,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
PizzaId = model.PizzaId,
|
PizzaId = model.PizzaId,
|
||||||
|
ClientId = model.ClientId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -52,6 +54,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
PizzaId = PizzaId,
|
PizzaId = PizzaId,
|
||||||
|
ClientId = ClientId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
|
Loading…
Reference in New Issue
Block a user