fixes
This commit is contained in:
parent
c2abb00ba3
commit
172c61b682
@ -27,7 +27,7 @@ namespace DiningRoomBusinessLogic.BusinessLogics
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
//model.UserId = -1 для swagger, чтобы можно было считать все заказы всех пользователей
|
||||
|
||||
var list = (model == null || model.UserId == -1) ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
|
@ -0,0 +1,44 @@
|
||||
using DiningRoomContracts.BindingModels;
|
||||
using DiningRoomContracts.BusinessLogicContracts;
|
||||
using DiningRoomContracts.SearchModels;
|
||||
using DiningRoomContracts.StorageContracts;
|
||||
using DiningRoomContracts.ViewModels;
|
||||
|
||||
namespace DiningRoomBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportGuarantorLogic : IReportGuarantorLogic
|
||||
{
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
|
||||
public ReportGuarantorLogic(IComponentStorage ComponentStorage)
|
||||
{
|
||||
_componentStorage = ComponentStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение отчёта для Word или Excel
|
||||
/// </summary>
|
||||
public List<ReportComponentOrderViewModel> GetReportComponentsWithShipments(List<ComponentSearchModel> SelectedComponents)
|
||||
{
|
||||
return _componentStorage.GetComponentsOrders(SelectedComponents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение отчёта для отправки на почту
|
||||
/// </summary>
|
||||
public List<ReportComponentByDateViewModel> GetReportComponentsByRequestDate(UserSearchModel CurrentUser, ReportBindingModel Report)
|
||||
{
|
||||
return _componentStorage.GetComponentsByDate(Report, CurrentUser);
|
||||
}
|
||||
|
||||
public void SaveReportToWordFile(ReportBindingModel Model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveReportToExcelFile(ReportBindingModel Model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -11,13 +11,10 @@ namespace DiningRoomContracts.BindingModels
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
|
@ -7,8 +7,9 @@ namespace DiningRoomContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int? OrderId { get; set; }
|
||||
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
public double Cost { get; set; }
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DiningRoomContracts.BindingModels
|
||||
{
|
||||
public class ReportBindingModel
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using DiningRoomContracts.BindingModels;
|
||||
using DiningRoomContracts.SearchModels;
|
||||
using DiningRoomContracts.ViewModels;
|
||||
|
||||
namespace DiningRoomContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IReportGuarantorLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение отчёта для Word или Excel
|
||||
/// </summary>
|
||||
List<ReportComponentOrderViewModel> GetReportComponentsWithShipments(List<ComponentSearchModel> SelectedComponents);
|
||||
|
||||
/// <summary>
|
||||
/// Получение отчёта для отправки на почту
|
||||
/// </summary>
|
||||
List<ReportComponentByDateViewModel> GetReportComponentsByRequestDate(UserSearchModel CurrentUser, ReportBindingModel Report);
|
||||
|
||||
void SaveReportToWordFile(ReportBindingModel Model);
|
||||
|
||||
void SaveReportToExcelFile(ReportBindingModel Model);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
public int? OrderId { get; set; }
|
||||
|
||||
public string? ProductName { get; set; }
|
||||
}
|
||||
|
@ -17,5 +17,8 @@ namespace DiningRoomContracts.StorageContracts
|
||||
ComponentViewModel? Update(ComponentBindingModel Model);
|
||||
|
||||
ComponentViewModel? Delete(ComponentBindingModel Model);
|
||||
}
|
||||
List<ReportComponentOrderViewModel> GetComponentsOrders(List<ComponentSearchModel> Models);
|
||||
|
||||
List<ReportComponentByDateViewModel> GetComponentsByDate(ReportBindingModel ReportModel, UserSearchModel UserModel);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace DiningRoomContracts.ViewModels
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[DisplayName("Стоимость")]
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Стоимость")]
|
||||
public double Sum { get; set; }
|
||||
|
@ -8,6 +8,7 @@ namespace DiningRoomContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int? OrderId { get; set; }
|
||||
|
||||
[DisplayName("Название товара")]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
@ -0,0 +1,20 @@
|
||||
namespace DiningRoomContracts.ViewModels
|
||||
{
|
||||
public class ReportComponentByDateViewModel
|
||||
{
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
public double ComponentCost { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
public double ProductPrice { get; set; }
|
||||
|
||||
public int CardId { get; set; }
|
||||
public string CardName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
namespace DiningRoomContracts.ViewModels
|
||||
{
|
||||
public class ReportComponentOrderViewModel
|
||||
{
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
public double ComponentCost { get; set; }
|
||||
|
||||
public List<(int Count, string ProductName, double ProductPrice, DateTime OrderDate)> Orders { get; set; } = new();
|
||||
}
|
||||
}
|
@ -14,5 +14,6 @@
|
||||
/// Название карты
|
||||
/// </summary>
|
||||
string CardName { get; }
|
||||
}
|
||||
DateTime DateCardCreate { get; }
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ namespace DiningRoomDataModels.Models
|
||||
/// Дата создания заказа
|
||||
/// </summary>
|
||||
DateTime DateCreate { get; }
|
||||
|
||||
int ProductId { get; }
|
||||
string ProductName { get; }
|
||||
/// <summary>
|
||||
/// Статус заказа
|
||||
/// </summary>
|
||||
|
@ -16,7 +16,7 @@
|
||||
string ProductName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Стоимость товара
|
||||
/// Стоимость блюда
|
||||
/// </summary>
|
||||
double Cost { get; }
|
||||
|
||||
@ -24,5 +24,9 @@
|
||||
/// Список продуктов
|
||||
/// </summary>
|
||||
Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Привязка блюда к заказу
|
||||
/// </summary>
|
||||
int? OrderId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using DiningRoomContracts.SearchModels;
|
||||
using DiningRoomContracts.StorageContracts;
|
||||
using DiningRoomContracts.ViewModels;
|
||||
using DiningRoomDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DiningRoomDatabaseImplement.Implements
|
||||
{
|
||||
@ -30,56 +31,119 @@ namespace DiningRoomDatabaseImplement.Implements
|
||||
.ToList();
|
||||
}
|
||||
//
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
using var Context = new DiningRoomDatabase();
|
||||
|
||||
// ComponentName is unique
|
||||
if (!string.IsNullOrEmpty(Model.ComponentName))
|
||||
{
|
||||
return null;
|
||||
return Context.Components
|
||||
.FirstOrDefault(x => x.ComponentName == Model.ComponentName)?
|
||||
.GetViewModel;
|
||||
}
|
||||
using var context = new DiningRoomDatabase();
|
||||
return context.Components
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
|
||||
return Context.Components
|
||||
.FirstOrDefault(x => x.Id == Model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
//
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new DiningRoomDatabase();
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
using var Context = new DiningRoomDatabase();
|
||||
|
||||
var NewComponent = Component.Create(model);
|
||||
Context.Components.Add(NewComponent);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new DiningRoomDatabase();
|
||||
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
using var Context = new DiningRoomDatabase();
|
||||
|
||||
var ExistingComponent = Context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (ExistingComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
|
||||
ExistingComponent.Update(model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return ExistingComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new DiningRoomDatabase();
|
||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
using var Context = new DiningRoomDatabase();
|
||||
|
||||
var ExistingComponent = Context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (ExistingComponent == null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
Context.Components.Remove(ExistingComponent);
|
||||
Context.SaveChanges();
|
||||
|
||||
return ExistingComponent.GetViewModel;
|
||||
}
|
||||
public List<ReportComponentOrderViewModel> GetComponentsOrders(List<ComponentSearchModel> Models)
|
||||
{
|
||||
using var Context = new DiningRoomDatabase();
|
||||
|
||||
return Context.Components
|
||||
.Include(x => x.ProductComponents)
|
||||
.ThenInclude(x => x.Product)
|
||||
.ThenInclude(x => x.Order)
|
||||
.Where(x =>
|
||||
Models.Select(x => x.Id).Contains(x.Id) // Компонент, указанный пользователем,
|
||||
&& x.ProductComponents.Any(y => y.Product.Order != null))
|
||||
.ToList()
|
||||
.Select(x => new ReportComponentOrderViewModel
|
||||
{
|
||||
ComponentId = x.Id,
|
||||
ComponentName = x.ComponentName,
|
||||
ComponentCost = x.Cost,
|
||||
Orders = x.ProductComponents
|
||||
.Select(y => (y.Count, y.Product.ProductName, y.Product.Cost, y.Product.Order.DateCreate))
|
||||
.ToList(),
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ReportComponentByDateViewModel> GetComponentsByDate(ReportBindingModel ReportModel, UserSearchModel UserModel)
|
||||
{
|
||||
using var Context = new DiningRoomDatabase();
|
||||
|
||||
return Context.Components
|
||||
.Where(c => c.UserId == UserModel.Id)
|
||||
.Include(x => x.ProductComponents)
|
||||
.ThenInclude(pc => pc.Product)
|
||||
.Include(c => c.DrinkComponents)
|
||||
.ThenInclude(ac => ac.Drink)
|
||||
.ThenInclude(a => a.Cards.Where(r => r.DateCardCreate >= ReportModel.DateFrom && r.DateCardCreate <= ReportModel.DateTo))
|
||||
.ToList()
|
||||
.SelectMany(c => c.DrinkComponents
|
||||
.SelectMany(ac => ac.Drink.Cards, (ac, r) => new { ac, r })
|
||||
.SelectMany(temp => c.ProductComponents, (temp, pc) => new { temp.ac, temp.r, pc })
|
||||
.Select(temp => new ReportComponentByDateViewModel
|
||||
{
|
||||
ComponentId = c.Id,
|
||||
ComponentName = c.ComponentName,
|
||||
ComponentCost = c.Cost,
|
||||
ProductId = temp.pc.Product.Id,
|
||||
ProductName = temp.pc.Product.ProductName,
|
||||
ProductPrice = temp.pc.Product.Cost,
|
||||
CardId = temp.r.Id,
|
||||
CardName = temp.r.CardName,
|
||||
}))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -9,49 +9,67 @@ namespace DiningRoomDatabaseImplement.Implements
|
||||
{
|
||||
public class ProductStorage : IProductStorage
|
||||
{
|
||||
public List<ProductViewModel> GetFullList()
|
||||
{
|
||||
using var context = new DiningRoomDatabase();
|
||||
return context.Products
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ProductViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new DiningRoomDatabase();
|
||||
|
||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ProductName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new DiningRoomDatabase();
|
||||
return context.Products
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.ProductName.Contains(model.ProductName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return Context.Products
|
||||
.Include(x => x.Order)
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new DiningRoomDatabase();
|
||||
return context.Products
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
using var context = new DiningRoomDatabase();
|
||||
|
||||
// Optional search by order
|
||||
if (model.OrderId.HasValue)
|
||||
{
|
||||
return context.Products
|
||||
.Include(x => x.Order)
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.UserId == model.UserId && x.OrderId == model.OrderId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProductViewModel? Insert(ProductBindingModel model)
|
||||
return context.Products
|
||||
.Include(x => x.Order)
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProductViewModel? GetElement(ProductSearchModel Model)
|
||||
{
|
||||
using var Context = new DiningRoomDatabase();
|
||||
|
||||
// ProductName is unique
|
||||
if (!string.IsNullOrEmpty(Model.ProductName))
|
||||
{
|
||||
return Context.Products
|
||||
.Include(x => x.Order)
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => x.ProductName == Model.ProductName)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
return Context.Products
|
||||
.Include(x => x.Order)
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => x.Id == Model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public ProductViewModel? Insert(ProductBindingModel model)
|
||||
{
|
||||
using var context = new DiningRoomDatabase();
|
||||
var newProduct = Product.Create(context, model);
|
||||
|
@ -7,6 +7,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -17,6 +18,11 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
public int Id { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public string CardName { get; set; } = string.Empty;
|
||||
public int? DrinkId { get; set; }
|
||||
|
||||
public virtual Drink? Drink { get; set; } = new();
|
||||
[Required]
|
||||
public DateTime DateCardCreate { get; set; }
|
||||
public static Card Create(DiningRoomDatabase context, CardBindingModel model)
|
||||
{
|
||||
return new Card()
|
||||
|
@ -15,6 +15,7 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Unit { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
@ -25,9 +26,13 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
|
||||
|
||||
public static Component Create(ComponentBindingModel Model)
|
||||
public static Component? Create(ComponentBindingModel Model)
|
||||
{
|
||||
return new()
|
||||
if (Model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = Model.Id,
|
||||
UserId = Model.UserId,
|
||||
@ -36,10 +41,24 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
Unit = Model.Unit,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel Model)
|
||||
public static Component Create(ComponentViewModel Model)
|
||||
{
|
||||
return new Component
|
||||
{
|
||||
Id = Model.Id,
|
||||
UserId = Model.UserId,
|
||||
ComponentName = Model.ComponentName,
|
||||
Cost = Model.Cost,
|
||||
Unit = Model.Unit,
|
||||
};
|
||||
}
|
||||
public void Update(ComponentBindingModel Model)
|
||||
{
|
||||
ComponentName = Model.ComponentName;
|
||||
if (Model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = Model.ComponentName;
|
||||
Cost = Model.Cost;
|
||||
Unit = Model.Unit;
|
||||
}
|
||||
|
@ -21,8 +21,10 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
public double Cost { get; private set; }
|
||||
|
||||
public int CardId { get; private set; }
|
||||
[ForeignKey("DrinkId")]
|
||||
public virtual List<Card> Cards { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
[Required]
|
||||
public string Category { get; private set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
|
@ -14,24 +14,22 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[ForeignKey("ProductId")]
|
||||
public int ProductId { get; set; }
|
||||
[ForeignKey("UserId")]
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int ProductId { get; set; }
|
||||
[Required]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
[Required]
|
||||
public OrderStatus Status { get; set; }
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; }
|
||||
public virtual Product Product { get; set; }
|
||||
[Required]
|
||||
public int UserId { get; private set; }
|
||||
public User User { get; set; }
|
||||
public virtual Product Product { get; set; }
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
{
|
||||
@ -43,6 +41,7 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
ProductId = model.ProductId,
|
||||
ProductName = model.ProductName,
|
||||
UserId = model.UserId,
|
||||
DateCreate = model.DateCreate,
|
||||
Status = model.Status,
|
||||
@ -51,7 +50,7 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel model)
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
|
@ -16,39 +16,41 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
|
||||
[Required]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public int? OrderId { get; set; }
|
||||
|
||||
[Required]
|
||||
public virtual Order? Order { get; set; }
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _productComponents;
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<ProductComponent> Components { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _productComponents;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_productComponents == null)
|
||||
{
|
||||
_productComponents = Components.ToDictionary(
|
||||
ProdComp => ProdComp.ComponentId,
|
||||
ProdComp => (ProdComp.Component as IComponentModel, ProdComp.Count)
|
||||
);
|
||||
}
|
||||
|
||||
return _productComponents;
|
||||
}
|
||||
}
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_productComponents == null)
|
||||
{
|
||||
_productComponents = Components.ToDictionary(
|
||||
ProdComp => ProdComp.ComponentId,
|
||||
ProdComp => (ProdComp.Component as IComponentModel, ProdComp.Count)
|
||||
);
|
||||
}
|
||||
|
||||
return _productComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ProductId")]
|
||||
public virtual List<ProductComponent> Components { get; set; } = new();
|
||||
[ForeignKey("ProductId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Product Create(DiningRoomDatabase Context, ProductBindingModel Model)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = Model.Id,
|
||||
UserId = Model.UserId,
|
||||
ProductName = Model.ProductName,
|
||||
OrderId = Model.OrderId,
|
||||
ProductName = Model.ProductName,
|
||||
Cost = Model.Cost,
|
||||
Components = Model.ProductComponents.Select(x => new ProductComponent
|
||||
{
|
||||
@ -59,12 +61,15 @@ namespace DiningRoomDatabaseImplement.Models
|
||||
}
|
||||
public void Update(ProductBindingModel model)
|
||||
{
|
||||
OrderId = model.OrderId;
|
||||
ProductName = model.ProductName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ProductViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
UserId = UserId,
|
||||
OrderId = OrderId,
|
||||
ProductName = ProductName,
|
||||
Cost = Cost,
|
||||
ProductComponents = ProductComponents
|
||||
|
Loading…
Reference in New Issue
Block a user