PIbd-23. Ivanov V.N. Lab Work 05 base #13

Closed
Vyacheslav wants to merge 6 commits from LabWork5 into LabWork4
8 changed files with 158 additions and 158 deletions
Showing only changes of commit 3b425b3f6f - Show all commits

View File

@ -10,8 +10,8 @@ namespace PizzeriaDataModels.Models
public interface IOrderModel : IId
{
int PizzaId { get; }
int ClientId { get; }
int Count { get; }
int ClientId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
DateTime DateCreate { get; }

View File

@ -8,71 +8,71 @@ namespace PizzeriaDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int Id { get; private set; }
[Required]
public int ClientId { get; private set; }
[Required]
public int ClientId { get; private set; }
public virtual Client Client { get; private set; } = new();
public virtual Client Client { get; private set; } = new();
[Required]
public int PizzaId { get; private set; }
[Required]
public int PizzaId { get; private set; }
public virtual Pizza Pizza { get; set; } = new();
public virtual Pizza Pizza { get; set; } = new();
[Required]
public int Count { get; private set; }
[Required]
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order Create(PizzeriaDatabase context, OrderBindingModel model)
{
return new Order()
{
Id = model.Id,
ClientId = model.ClientId,
Client = context.Clients.First(x => x.Id == model.ClientId),
PizzaId = model.PizzaId,
Pizza = context.Pizzas.First(x => x.Id == model.PizzaId),
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
}
public static Order Create(PizzeriaDatabase context, OrderBindingModel model)
{
return new Order()
{
Id = model.Id,
ClientId = model.ClientId,
Client = context.Clients.First(x => x.Id == model.ClientId),
PizzaId = model.PizzaId,
Pizza = context.Pizzas.First(x => x.Id == model.PizzaId),
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
PizzaId = PizzaId,
PizzaName = Pizza.PizzaName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
PizzaId = PizzaId,
PizzaName = Pizza.PizzaName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
}
}

View File

@ -14,13 +14,13 @@ namespace PizzeriaFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string PizzaFileName = "Pizza.xml";
private readonly string ClientFileName = "Client.xml";
public List<Component> Components { get; private set; }
private readonly string ClientFileName = "Client.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { 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 static DataFileSingleton GetInstance()
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
@ -32,15 +32,15 @@ namespace PizzeriaFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", 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 SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
private DataFileSingleton()
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.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)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{

View File

@ -19,23 +19,23 @@ namespace PizzeriaFileImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model.DateFrom.HasValue)
if (model.DateFrom.HasValue)
{
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x)).ToList();
}
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x)).ToList();
}
if (model.ClientId.HasValue && !model.Id.HasValue)
if (model.ClientId.HasValue && !model.Id.HasValue)
{
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
}
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
}
if (model.Id.HasValue)
if (model.Id.HasValue)
{
return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
}
return new();
}
return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
}
return new();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
@ -46,25 +46,25 @@ namespace PizzeriaFileImplement.Implements
return AttachPizzaName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var pizza = source.Pizzas.FirstOrDefault(x => x.Id == order.PizzaId);
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
var pizza = source.Pizzas.FirstOrDefault(x => x.Id == order.PizzaId);
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
if (pizza != null)
{
viewModel.PizzaName = pizza.PizzaName;
}
if (client != null)
if (client != null)
{
viewModel.ClientFIO = client.ClientFIO;
}
return viewModel;
}
viewModel.ClientFIO = client.ClientFIO;
}
return viewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model);

View File

@ -13,15 +13,15 @@ namespace PizzeriaListImplement
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Pizza> Pizzas { get; set; }
public List<Client> Clients { get; set; }
public List<Client> Clients { get; set; }
private DataListSingleton()
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Pizzas = new List<Pizza>();
Clients = new List<Client>();
}
Clients = new List<Client>();
}
public static DataListSingleton GetInstance()
{

View File

@ -33,62 +33,62 @@ namespace PizzeriaListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (model.DateFrom.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.ClientId.HasValue && !model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.ClientId == model.ClientId)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
result.Add(GetViewModel(order));
}
}
}
return result;
if (model.DateFrom.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.ClientId.HasValue && !model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.ClientId == model.ClientId)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
result.Add(GetViewModel(order));
}
}
}
return result;
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach (var package in _source.Pizzas)
{
if (package.Id == order.PizzaId)
{
viewModel.PizzaName = package.PizzaName;
break;
}
}
foreach (var client in _source.Clients)
{
if (client.Id == order.ClientId)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
}
return viewModel;
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach (var package in _source.Pizzas)
{
if (package.Id == order.PizzaId)
{
viewModel.PizzaName = package.PizzaName;
break;
}
}
foreach (var client in _source.Clients)
{
if (client.Id == order.ClientId)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
}
return viewModel;
}
public OrderViewModel? GetElement(OrderSearchModel model)
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{

View File

@ -14,8 +14,8 @@ namespace PizzeriaListImplement.Models
{
public int Id { get; private set; }
public int PizzaId { get; private set; }
public int ClientId { get; private set; }
public int Count { get; private set; }
public int ClientId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
@ -31,8 +31,8 @@ namespace PizzeriaListImplement.Models
{
Id = model.Id,
PizzaId = model.PizzaId,
ClientId = model.ClientId,
Count = model.Count,
ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
@ -54,8 +54,8 @@ namespace PizzeriaListImplement.Models
{
Id = Id,
PizzaId = PizzaId,
ClientId = ClientId,
Count = Count,
ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,

View File

@ -39,14 +39,14 @@ namespace Pizzeria
option.AddNLog("nlog.config");
});
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IPizzaStorage, PizzaStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IPizzaLogic, PizzaLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
@ -63,8 +63,8 @@ namespace Pizzeria
services.AddTransient<FormPizzas>();
services.AddTransient<FormReportPizzaComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormClients>();
services.AddTransient<EntityFrameworkDesignServicesBuilder>();
}
services.AddTransient<FormClients>();
services.AddTransient<EntityFrameworkDesignServicesBuilder>();
}
}
}