lab 6 in process
This commit is contained in:
parent
c84c2beeeb
commit
bb8974a2f6
@ -39,12 +39,14 @@ namespace Pizzeria
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IPizzaStorage, PizzaStorage>();
|
||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IPizzaLogic, PizzaLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
@ -60,6 +62,8 @@ namespace Pizzeria
|
||||
services.AddTransient<FormClients>();
|
||||
services.AddTransient<FormReportPizzaComponents>();
|
||||
services.AddTransient<FormReportOrders>();
|
||||
services.AddTransient<FormImplementers>();
|
||||
services.AddTransient<FormImplementer>();
|
||||
}
|
||||
}
|
||||
}
|
@ -38,11 +38,31 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||
model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id);
|
||||
var element = _orderStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id);
|
||||
_logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||
model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
@ -92,6 +112,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
}
|
||||
model.Status = status;
|
||||
|
||||
if (order.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = order.ImplementerId;
|
||||
}
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
@ -132,6 +156,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate)
|
||||
{
|
||||
throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}");
|
||||
}
|
||||
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PizzaId: {PizzaId}. PizzaCount: {Count}", model.Id, model.Sum, model.PizzaId, model.Count);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ namespace PizzeriaContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int PizzaId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
@ -12,5 +12,6 @@ namespace PizzeriaContracts.BusinessLogicsContracts
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
namespace PizzeriaContracts.SearchModels
|
||||
using PizzeriaDataModels.Enums;
|
||||
|
||||
namespace PizzeriaContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public OrderStatus? Status { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ namespace PizzeriaContracts.ViewModels
|
||||
[DisplayName("ФИО клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
[DisplayName("Исполнитель")]
|
||||
public string? ImplementerFIO { get; set; } = null;
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
||||
|
@ -7,6 +7,7 @@ namespace PizzeriaDataModels.Models
|
||||
{
|
||||
int PizzaId { get; }
|
||||
int ClientId { get; }
|
||||
int? ImplementerId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
@ -14,7 +14,12 @@ namespace PizzeriaDatabaseImplement.Implements
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Orders.Include(x => x.Pizza).Include(x => x.Client).Select(x => x.GetViewModel).ToList();
|
||||
return context.Orders
|
||||
.Include(x => x.Pizza)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
|
@ -22,6 +22,9 @@ namespace PizzeriaDatabaseImplement.Models
|
||||
|
||||
public virtual Pizza Pizza { get; set; } = new();
|
||||
|
||||
public int? ImplementerId { get; private set; }
|
||||
public virtual Implementer? Implementer { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -45,6 +48,8 @@ namespace PizzeriaDatabaseImplement.Models
|
||||
Client = context.Clients.First(x => x.Id == model.ClientId),
|
||||
PizzaId = model.PizzaId,
|
||||
Pizza = context.Pizzas.First(x => x.Id == model.PizzaId),
|
||||
ImplementerId = model.ImplementerId,
|
||||
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -53,7 +58,7 @@ namespace PizzeriaDatabaseImplement.Models
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
public void Update(PizzeriaDatabase context, OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -61,6 +66,8 @@ namespace PizzeriaDatabaseImplement.Models
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
@ -70,6 +77,8 @@ namespace PizzeriaDatabaseImplement.Models
|
||||
ClientFIO = Client.ClientFIO,
|
||||
PizzaId = PizzaId,
|
||||
PizzaName = Pizza.PizzaName,
|
||||
ImplementerId = ImplementerId,
|
||||
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config");
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IPizzaStorage, PizzaStorage>();
|
||||
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IPizzaLogic, PizzaLogic>();
|
||||
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
Loading…
Reference in New Issue
Block a user