конец
This commit is contained in:
parent
0da9e0b8db
commit
79bb717315
@ -9,9 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaContracts", "Pizzer
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaBusinessLogic", "PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj", "{D8EAAB67-47C6-443D-83FC-E1337F105F67}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaBusinessLogic", "PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj", "{D8EAAB67-47C6-443D-83FC-E1337F105F67}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{922551CE-15B0-42C8-AA1A-368C8399CAD6}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{922551CE-15B0-42C8-AA1A-368C8399CAD6}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaView", "PizzeriaView\PizzeriaView.csproj", "{25FCC09C-88AE-4515-9235-FB9C17972034}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaView", "PizzeriaView\PizzeriaView.csproj", "{25FCC09C-88AE-4515-9235-FB9C17972034}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -17,14 +17,74 @@ namespace PizzeriaBusinessLogic
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (model.Status != OrderStatus.Неизвестен) return false;
|
||||||
|
model.Status = OrderStatus.Принят;
|
||||||
|
if (_orderStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||||
|
{
|
||||||
|
Id = model.Id
|
||||||
|
});
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Read operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (element.Status != OrderStatus.Готов)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status change operation failed");
|
||||||
|
throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!");
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Выдан;
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
_orderStorage.Update(model);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||||
|
{
|
||||||
|
Id = model.Id
|
||||||
|
});
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Read operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (element.Status != OrderStatus.Выполняется)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status change operation failed");
|
||||||
|
throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!");
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Готов;
|
||||||
|
_orderStorage.Update(model);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
@ -34,31 +94,29 @@ namespace PizzeriaBusinessLogic
|
|||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model);
|
|
||||||
if (model.Status != OrderStatus.Неизвестен)
|
|
||||||
return false;
|
|
||||||
model.Status = OrderStatus.Принят;
|
|
||||||
if (_orderStorage.Insert(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Insert operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
CheckModel(model, false);
|
||||||
}
|
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||||
public bool FinishOrder(OrderBindingModel model)
|
{
|
||||||
{
|
Id = model.Id
|
||||||
return ChangeStatus(model, OrderStatus.Готов);
|
});
|
||||||
}
|
if (element == null)
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
{
|
||||||
{
|
_logger.LogWarning("Read operation failed");
|
||||||
return ChangeStatus(model, OrderStatus.Выдан);
|
return false;
|
||||||
|
}
|
||||||
|
if (element.Status != OrderStatus.Принят)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status change operation failed");
|
||||||
|
throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!");
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Выполняется;
|
||||||
|
_orderStorage.Update(model);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -69,52 +127,23 @@ namespace PizzeriaBusinessLogic
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (model.Count <= 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Количество пиццы в заказе не может быть меньше 1", nameof(model.Count));
|
|
||||||
}
|
|
||||||
if (model.Sum <= 0)
|
if (model.Sum <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum));
|
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||||
}
|
}
|
||||||
if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate)
|
if (model.Count <= 0)
|
||||||
{
|
{
|
||||||
throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}");
|
throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Pizza. PizzaId:{PizzaId}.Count:{Count}.Sum:{Sum}Id:{Id}",
|
_logger.LogInformation("Order. Sum:{Sum}. Id:{Id}", model.Sum, model.Id);
|
||||||
model.ProductId, model.Count, model.Sum, model.Id);
|
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||||
}
|
|
||||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
|
||||||
{
|
|
||||||
CheckModel(model, false);
|
|
||||||
var element = _orderStorage.GetElement(new OrderSearchModel()
|
|
||||||
{
|
{
|
||||||
Id = model.Id
|
Id = model.Id
|
||||||
});
|
});
|
||||||
if (element == null)
|
if (element != null && element.Id != model.Id)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(element));
|
throw new InvalidOperationException("Заказ с таким ID уже существует");
|
||||||
}
|
}
|
||||||
model.DateCreate = element.DateCreate;
|
|
||||||
model.ProductId = element.ProductId;
|
|
||||||
model.DateImplement = element.DateImplement;
|
|
||||||
model.Status = element.Status;
|
|
||||||
model.Count = element.Count;
|
|
||||||
model.Sum = element.Sum;
|
|
||||||
if (requiredStatus - model.Status == 1)
|
|
||||||
{
|
|
||||||
model.Status = requiredStatus;
|
|
||||||
if (model.Status == OrderStatus.Выдан)
|
|
||||||
model.DateImplement = DateTime.Now;
|
|
||||||
if (_orderStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Update operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
|
||||||
throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace PizzeriaBusinessLogic
|
|||||||
}
|
}
|
||||||
public List<PizzaViewModel>? ReadList(PizzaSearchModel? model)
|
public List<PizzaViewModel>? ReadList(PizzaSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. PizzaName:{PizzaName}.Id:{ Id}", model?.ProductName, model?.Id);
|
_logger.LogInformation("ReadList. PizzaName:{PizzaName}.Id:{ Id}", model?.PizzaName, model?.Id);
|
||||||
var list = model == null ? _PizzaStorage.GetFullList() : _PizzaStorage.GetFilteredList(model);
|
var list = model == null ? _PizzaStorage.GetFullList() : _PizzaStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
@ -39,7 +39,7 @@ namespace PizzeriaBusinessLogic
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadElement. PizzaName:{PizzaName}.Id:{ Id}", model.ProductName, model.Id);
|
_logger.LogInformation("ReadElement. PizzaName:{PizzaName}.Id:{ Id}", model.PizzaName, model.Id);
|
||||||
var element = _PizzaStorage.GetElement(model);
|
var element = _PizzaStorage.GetElement(model);
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
@ -90,22 +90,22 @@ namespace PizzeriaBusinessLogic
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.ProductName))
|
if (string.IsNullOrEmpty(model.PizzaName))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет названия пиццы", nameof(model.ProductName));
|
throw new ArgumentNullException("Нет названия пиццы", nameof(model.PizzaName));
|
||||||
}
|
}
|
||||||
if (model.Price <= 0)
|
if (model.Price <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price));
|
throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price));
|
||||||
}
|
}
|
||||||
if (model.ProductComponents == null || model.ProductComponents.Count == 0)
|
if (model.PizzaComponents == null || model.PizzaComponents.Count == 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Перечень ингредиентов не может быть пустым", nameof(model.ProductComponents));
|
throw new ArgumentNullException("Перечень ингредиентов не может быть пустым", nameof(model.PizzaComponents));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Pizza. PizzaName:{PizzaName}.Price:{Price}.Id: { Id}", model.ProductName, model.Price, model.Id);
|
_logger.LogInformation("Pizza. PizzaName:{PizzaName}.Price:{Price}.Id: { Id}", model.PizzaName, model.Price, model.Id);
|
||||||
var element = _PizzaStorage.GetElement(new PizzaSearchModel
|
var element = _PizzaStorage.GetElement(new PizzaSearchModel
|
||||||
{
|
{
|
||||||
ProductName = model.ProductName
|
PizzaName = model.PizzaName
|
||||||
});
|
});
|
||||||
if (element != null && element.Id != model.Id)
|
if (element != null && element.Id != model.Id)
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ namespace PizzeriaContracts.BindingModels
|
|||||||
public class OrderBindingModel : IOrderModel
|
public class OrderBindingModel : IOrderModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int ProductId { get; set; }
|
public int PizzaId { 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.Неизвестен;
|
||||||
|
@ -10,9 +10,9 @@ namespace PizzeriaContracts.BindingModels
|
|||||||
public class PizzaBindingModel : IPizzaModel
|
public class PizzaBindingModel : IPizzaModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string ProductName { get; set; } = string.Empty;
|
public string PizzaName { get; set; } = string.Empty;
|
||||||
public double Price { get; set; }
|
public double Price { get; set; }
|
||||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
public Dictionary<int, (IComponentModel, int)> PizzaComponents
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -9,7 +9,7 @@ namespace PizzeriaContracts.SearchModels
|
|||||||
public class PizzaSearchModel
|
public class PizzaSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? ProductName { get; set; }
|
public string? PizzaName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@ namespace PizzeriaContracts.ViewModels
|
|||||||
{
|
{
|
||||||
[DisplayName("Номер")]
|
[DisplayName("Номер")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int ProductId { get; set; }
|
public int PizzaId { get; set; }
|
||||||
[DisplayName("Изделие")]
|
[DisplayName("Изделие")]
|
||||||
public string ProductName { get; set; } = string.Empty;
|
public string PizzaName { get; set; } = string.Empty;
|
||||||
[DisplayName("Количество")]
|
[DisplayName("Количество")]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
[DisplayName("Сумма")]
|
[DisplayName("Сумма")]
|
||||||
|
@ -12,10 +12,10 @@ namespace PizzeriaContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Название изделия")]
|
[DisplayName("Название изделия")]
|
||||||
public string ProductName { get; set; } = string.Empty;
|
public string PizzaName { get; set; } = string.Empty;
|
||||||
[DisplayName("Цена")]
|
[DisplayName("Цена")]
|
||||||
public double Price { get; set; }
|
public double Price { get; set; }
|
||||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
public Dictionary<int, (IComponentModel, int)> PizzaComponents
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -8,7 +8,7 @@ namespace PizzeriaDataModels
|
|||||||
{
|
{
|
||||||
public interface IOrderModel : IId
|
public interface IOrderModel : IId
|
||||||
{
|
{
|
||||||
int ProductId { get; }
|
int PizzaId { get; }
|
||||||
int Count { get; }
|
int Count { get; }
|
||||||
double Sum { get; }
|
double Sum { get; }
|
||||||
OrderStatus Status { get; }
|
OrderStatus Status { get; }
|
||||||
|
@ -8,8 +8,8 @@ namespace PizzeriaDataModels
|
|||||||
{
|
{
|
||||||
public interface IPizzaModel : IId
|
public interface IPizzaModel : IId
|
||||||
{
|
{
|
||||||
string ProductName { get; }
|
string PizzaName { get; }
|
||||||
double Price { get; }
|
double Price { get; }
|
||||||
Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
|
Dictionary<int, (IComponentModel, int)> PizzaComponents { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,12 @@ namespace PizzeriaListImplement
|
|||||||
private static DataListSingleton? _instance;
|
private static DataListSingleton? _instance;
|
||||||
public List<Component> Components { get; set; }
|
public List<Component> Components { get; set; }
|
||||||
public List<Order> Orders { get; set; }
|
public List<Order> Orders { get; set; }
|
||||||
public List<Pizza> Products { get; set; }
|
public List<Pizza> Pizzas { get; set; }
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Products = new List<Pizza>();
|
Pizzas = new List<Pizza>();
|
||||||
}
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
@ -105,11 +105,11 @@ namespace PizzeriaListImplement.Implements
|
|||||||
}
|
}
|
||||||
private OrderViewModel AttachPizzaName(OrderViewModel model)
|
private OrderViewModel AttachPizzaName(OrderViewModel model)
|
||||||
{
|
{
|
||||||
foreach (var pizza in _source.Products)
|
foreach (var pizza in _source.Pizzas)
|
||||||
{
|
{
|
||||||
if (pizza.Id == model.ProductId)
|
if (pizza.Id == model.PizzaId)
|
||||||
{
|
{
|
||||||
model.ProductName = pizza.ProductName;
|
model.PizzaName = pizza.PizzaName;
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ namespace PizzeriaListImplement.Implements
|
|||||||
public List<PizzaViewModel> GetFullList()
|
public List<PizzaViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
var result = new List<PizzaViewModel>();
|
var result = new List<PizzaViewModel>();
|
||||||
foreach (var pizzas in _source.Products)
|
foreach (var pizzas in _source.Pizzas)
|
||||||
{
|
{
|
||||||
result.Add(pizzas.GetViewModel);
|
result.Add(pizzas.GetViewModel);
|
||||||
}
|
}
|
||||||
@ -30,13 +30,13 @@ namespace PizzeriaListImplement.Implements
|
|||||||
public List<PizzaViewModel> GetFilteredList(PizzaSearchModel model)
|
public List<PizzaViewModel> GetFilteredList(PizzaSearchModel model)
|
||||||
{
|
{
|
||||||
var result = new List<PizzaViewModel>();
|
var result = new List<PizzaViewModel>();
|
||||||
if (string.IsNullOrEmpty(model.ProductName))
|
if (string.IsNullOrEmpty(model.PizzaName))
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
foreach (var pizzas in _source.Products)
|
foreach (var pizzas in _source.Pizzas)
|
||||||
{
|
{
|
||||||
if (pizzas.ProductName.Contains(model.ProductName))
|
if (pizzas.PizzaName.Contains(model.PizzaName))
|
||||||
{
|
{
|
||||||
result.Add(pizzas.GetViewModel);
|
result.Add(pizzas.GetViewModel);
|
||||||
}
|
}
|
||||||
@ -45,13 +45,13 @@ namespace PizzeriaListImplement.Implements
|
|||||||
}
|
}
|
||||||
public PizzaViewModel? GetElement(PizzaSearchModel model)
|
public PizzaViewModel? GetElement(PizzaSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue)
|
if (string.IsNullOrEmpty(model.PizzaName) && !model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
foreach (var pizzas in _source.Products)
|
foreach (var pizzas in _source.Pizzas)
|
||||||
{
|
{
|
||||||
if ((!string.IsNullOrEmpty(model.ProductName) && pizzas.ProductName == model.ProductName) ||
|
if ((!string.IsNullOrEmpty(model.PizzaName) && pizzas.PizzaName == model.PizzaName) ||
|
||||||
(model.Id.HasValue && pizzas.Id == model.Id))
|
(model.Id.HasValue && pizzas.Id == model.Id))
|
||||||
{
|
{
|
||||||
return pizzas.GetViewModel;
|
return pizzas.GetViewModel;
|
||||||
@ -62,7 +62,7 @@ namespace PizzeriaListImplement.Implements
|
|||||||
public PizzaViewModel? Insert(PizzaBindingModel model)
|
public PizzaViewModel? Insert(PizzaBindingModel model)
|
||||||
{
|
{
|
||||||
model.Id = 1;
|
model.Id = 1;
|
||||||
foreach (var pizzas in _source.Products)
|
foreach (var pizzas in _source.Pizzas)
|
||||||
{
|
{
|
||||||
if (model.Id <= pizzas.Id)
|
if (model.Id <= pizzas.Id)
|
||||||
{
|
{
|
||||||
@ -74,12 +74,12 @@ namespace PizzeriaListImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
_source.Products.Add(newPizzas);
|
_source.Pizzas.Add(newPizzas);
|
||||||
return newPizzas.GetViewModel;
|
return newPizzas.GetViewModel;
|
||||||
}
|
}
|
||||||
public PizzaViewModel? Update(PizzaBindingModel model)
|
public PizzaViewModel? Update(PizzaBindingModel model)
|
||||||
{
|
{
|
||||||
foreach (var pizzas in _source.Products)
|
foreach (var pizzas in _source.Pizzas)
|
||||||
{
|
{
|
||||||
if (pizzas.Id == model.Id)
|
if (pizzas.Id == model.Id)
|
||||||
{
|
{
|
||||||
@ -91,12 +91,12 @@ namespace PizzeriaListImplement.Implements
|
|||||||
}
|
}
|
||||||
public PizzaViewModel? Delete(PizzaBindingModel model)
|
public PizzaViewModel? Delete(PizzaBindingModel model)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _source.Products.Count; ++i)
|
for (int i = 0; i < _source.Pizzas.Count; ++i)
|
||||||
{
|
{
|
||||||
if (_source.Products[i].Id == model.Id)
|
if (_source.Pizzas[i].Id == model.Id)
|
||||||
{
|
{
|
||||||
var element = _source.Products[i];
|
var element = _source.Pizzas[i];
|
||||||
_source.Products.RemoveAt(i);
|
_source.Pizzas.RemoveAt(i);
|
||||||
return element.GetViewModel;
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
public class Order : IOrderModel
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int ProductId { get; private set; }
|
public int PizzaId { 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; }
|
||||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
@ -27,7 +27,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
ProductId = model.ProductId,
|
PizzaId = model.PizzaId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -42,11 +42,12 @@ namespace PizzeriaListImplement.Models
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
|
if (model.DateImplement.HasValue) DateImplement = model.DateImplement;
|
||||||
}
|
}
|
||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
ProductId = ProductId,
|
PizzaId = PizzaId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
|
@ -12,9 +12,9 @@ namespace PizzeriaListImplement.Models
|
|||||||
public class Pizza : IPizzaModel
|
public class Pizza : IPizzaModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public string ProductName { get; private set; } = string.Empty;
|
public string PizzaName { get; private set; } = string.Empty;
|
||||||
public double Price { get; private set; }
|
public double Price { get; private set; }
|
||||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
public Dictionary<int, (IComponentModel, int)> PizzaComponents
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
@ -28,9 +28,9 @@ namespace PizzeriaListImplement.Models
|
|||||||
return new Pizza()
|
return new Pizza()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
ProductName = model.ProductName,
|
PizzaName = model.PizzaName,
|
||||||
Price = model.Price,
|
Price = model.Price,
|
||||||
ProductComponents = model.ProductComponents
|
PizzaComponents = model.PizzaComponents
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(PizzaBindingModel? model)
|
public void Update(PizzaBindingModel? model)
|
||||||
@ -39,16 +39,16 @@ namespace PizzeriaListImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ProductName = model.ProductName;
|
PizzaName = model.PizzaName;
|
||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
ProductComponents = model.ProductComponents;
|
PizzaComponents = model.PizzaComponents;
|
||||||
}
|
}
|
||||||
public PizzaViewModel GetViewModel => new()
|
public PizzaViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
ProductName = ProductName,
|
PizzaName = PizzaName,
|
||||||
Price = Price,
|
Price = Price,
|
||||||
ProductComponents = ProductComponents
|
PizzaComponents = PizzaComponents
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,14 +21,14 @@ namespace PizzeriaView
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IPizzaLogic _logic;
|
private readonly IPizzaLogic _logic;
|
||||||
private int? _id;
|
private int? _id;
|
||||||
private Dictionary<int, (IComponentModel, int)> _ProductComponents;
|
private Dictionary<int, (IComponentModel, int)> _PizzaComponents;
|
||||||
public int Id { set { _id = value; } }
|
public int Id { set { _id = value; } }
|
||||||
public FormPizza(ILogger<FormPizza> logger, IPizzaLogic logic)
|
public FormPizza(ILogger<FormPizza> logger, IPizzaLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
_ProductComponents = new Dictionary<int, (IComponentModel, int)>();
|
_PizzaComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||||
}
|
}
|
||||||
private void FormPizza_Load(object sender, EventArgs e)
|
private void FormPizza_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -43,9 +43,9 @@ namespace PizzeriaView
|
|||||||
});
|
});
|
||||||
if (view != null)
|
if (view != null)
|
||||||
{
|
{
|
||||||
textBoxName.Text = view.ProductName;
|
textBoxName.Text = view.PizzaName;
|
||||||
textBoxPrice.Text = view.Price.ToString();
|
textBoxPrice.Text = view.Price.ToString();
|
||||||
_ProductComponents = view.ProductComponents ?? new
|
_PizzaComponents = view.PizzaComponents ?? new
|
||||||
Dictionary<int, (IComponentModel, int)>();
|
Dictionary<int, (IComponentModel, int)>();
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
@ -63,10 +63,10 @@ namespace PizzeriaView
|
|||||||
_logger.LogInformation("Загрузка ингредиент пиццы");
|
_logger.LogInformation("Загрузка ингредиент пиццы");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_ProductComponents != null)
|
if (_PizzaComponents != null)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Clear();
|
dataGridView.Rows.Clear();
|
||||||
foreach (var pc in _ProductComponents)
|
foreach (var pc in _PizzaComponents)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||||
}
|
}
|
||||||
@ -92,13 +92,13 @@ namespace PizzeriaView
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Добавление нового ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
|
_logger.LogInformation("Добавление нового ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
|
||||||
if (_ProductComponents.ContainsKey(form.Id))
|
if (_PizzaComponents.ContainsKey(form.Id))
|
||||||
{
|
{
|
||||||
_ProductComponents[form.Id] = (form.ComponentModel,form.Count);
|
_PizzaComponents[form.Id] = (form.ComponentModel,form.Count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_ProductComponents.Add(form.Id, (form.ComponentModel,form.Count));
|
_PizzaComponents.Add(form.Id, (form.ComponentModel,form.Count));
|
||||||
}
|
}
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ namespace PizzeriaView
|
|||||||
{
|
{
|
||||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||||
form.Id = id;
|
form.Id = id;
|
||||||
form.Count = _ProductComponents[id].Item2;
|
form.Count = _PizzaComponents[id].Item2;
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (form.ComponentModel == null)
|
if (form.ComponentModel == null)
|
||||||
@ -121,7 +121,7 @@ namespace PizzeriaView
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Изменение ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
|
_logger.LogInformation("Изменение ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count);
|
||||||
_ProductComponents[form.Id] = (form.ComponentModel, form.Count);
|
_PizzaComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ namespace PizzeriaView
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Удаление ингредиента:{ ComponentName}-{ Count}", dataGridView.SelectedRows[0].Cells[1].Value);
|
_logger.LogInformation("Удаление ингредиента:{ ComponentName}-{ Count}", dataGridView.SelectedRows[0].Cells[1].Value);
|
||||||
_ProductComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
_PizzaComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -163,7 +163,7 @@ namespace PizzeriaView
|
|||||||
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_ProductComponents == null || _ProductComponents.Count == 0)
|
if (_PizzaComponents == null || _PizzaComponents.Count == 0)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
@ -174,9 +174,9 @@ namespace PizzeriaView
|
|||||||
var model = new PizzaBindingModel
|
var model = new PizzaBindingModel
|
||||||
{
|
{
|
||||||
Id = _id ?? 0,
|
Id = _id ?? 0,
|
||||||
ProductName = textBoxName.Text,
|
PizzaName = textBoxName.Text,
|
||||||
Price = Convert.ToDouble(textBoxPrice.Text),
|
Price = Convert.ToDouble(textBoxPrice.Text),
|
||||||
ProductComponents = _ProductComponents
|
PizzaComponents = _PizzaComponents
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||||
_logic.Create(model);
|
_logic.Create(model);
|
||||||
@ -202,7 +202,7 @@ namespace PizzeriaView
|
|||||||
private double CalcPrice()
|
private double CalcPrice()
|
||||||
{
|
{
|
||||||
double price = 0;
|
double price = 0;
|
||||||
foreach (var elem in _ProductComponents)
|
foreach (var elem in _PizzaComponents)
|
||||||
{
|
{
|
||||||
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using PizzeriaDataModels.Models;
|
using Microsoft.VisualBasic.Logging;
|
||||||
using Microsoft.VisualBasic.Logging;
|
|
||||||
using PizzeriaContracts.BusinessLogicsContracts;
|
using PizzeriaContracts.BusinessLogicsContracts;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
using System;
|
using System;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
using PizzeriaBusinessLogic;
|
using PizzeriaBusinessLogic;
|
||||||
using PizzeriaContracts.BusinessLogicsContracts;
|
using PizzeriaContracts.BusinessLogicsContracts;
|
||||||
using PizzeriaContracts.StorageContracts;
|
using PizzeriaContracts.StorageContracts;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
autoReload="true" internalLogLevel="Info">
|
autoReload="true" internalLogLevel="Info">
|
||||||
|
|
||||||
<targets>
|
<targets>
|
||||||
<target xsi:type="File" name="tofile" fileName="${basedir}/carlog-${shortdate}.log" />
|
<target xsi:type="File" name="tofile" fileName="${basedir}/${shortdate}.log" />
|
||||||
</targets>
|
</targets>
|
||||||
|
|
||||||
<rules>
|
<rules>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user