2024-04-07 15:05:57 +04:00
|
|
|
|
using PizzeriaContracts.BindingModels;
|
|
|
|
|
using PizzeriaContracts.ViewModels;
|
|
|
|
|
using PizzeriaDataModels.Enums;
|
|
|
|
|
using PizzeriaDataModels.Models;
|
2024-05-22 02:01:59 +04:00
|
|
|
|
using System;
|
2024-04-07 15:05:57 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-05-22 02:01:59 +04:00
|
|
|
|
using System.Linq;
|
2024-04-07 15:05:57 +04:00
|
|
|
|
|
|
|
|
|
namespace PizzeriaDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
2024-05-22 02:01:59 +04:00
|
|
|
|
|
2024-04-07 15:05:57 +04:00
|
|
|
|
[Required]
|
2024-05-22 02:01:59 +04:00
|
|
|
|
public int ClientId { get; private set; }
|
|
|
|
|
|
|
|
|
|
public virtual Client Client { get; private set; } = new();
|
|
|
|
|
|
2024-04-07 15:05:57 +04:00
|
|
|
|
[Required]
|
2024-05-22 02:01:59 +04:00
|
|
|
|
public int PizzaId { get; private set; }
|
|
|
|
|
|
|
|
|
|
public virtual Pizza Pizza { get; set; } = new();
|
|
|
|
|
|
2024-06-21 14:39:07 +04:00
|
|
|
|
public int? ImplementerId { get; private set; }
|
|
|
|
|
public virtual Implementer? Implementer { get; set; } = new();
|
|
|
|
|
|
2024-05-07 23:20:02 +04:00
|
|
|
|
[Required]
|
2024-04-07 15:05:57 +04:00
|
|
|
|
public int Count { get; private set; }
|
2024-05-22 02:01:59 +04:00
|
|
|
|
|
2024-04-07 15:05:57 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; private set; }
|
2024-05-22 02:01:59 +04:00
|
|
|
|
|
2024-04-07 15:05:57 +04:00
|
|
|
|
[Required]
|
2024-05-22 02:01:59 +04:00
|
|
|
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
|
|
|
|
|
2024-04-07 15:05:57 +04:00
|
|
|
|
[Required]
|
2024-05-22 02:01:59 +04:00
|
|
|
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
|
|
|
|
2024-04-07 15:05:57 +04:00
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
2024-05-22 02:01:59 +04:00
|
|
|
|
|
|
|
|
|
public static Order Create(PizzeriaDatabase context, OrderBindingModel model)
|
2024-04-07 15:05:57 +04:00
|
|
|
|
{
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2024-05-07 23:20:02 +04:00
|
|
|
|
ClientId = model.ClientId,
|
2024-05-22 02:01:59 +04:00
|
|
|
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
|
|
|
|
PizzaId = model.PizzaId,
|
|
|
|
|
Pizza = context.Pizzas.First(x => x.Id == model.PizzaId),
|
2024-06-21 14:39:07 +04:00
|
|
|
|
ImplementerId = model.ImplementerId,
|
|
|
|
|
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null,
|
2024-04-07 15:05:57 +04:00
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
2024-05-22 02:01:59 +04:00
|
|
|
|
DateImplement = model.DateImplement,
|
2024-04-07 15:05:57 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2024-05-22 02:01:59 +04:00
|
|
|
|
|
2024-06-21 14:39:07 +04:00
|
|
|
|
public void Update(PizzeriaDatabase context, OrderBindingModel? model)
|
2024-04-07 15:05:57 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
2024-06-21 14:39:07 +04:00
|
|
|
|
ImplementerId = model.ImplementerId;
|
|
|
|
|
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null;
|
2024-04-07 15:05:57 +04:00
|
|
|
|
}
|
2024-05-22 02:01:59 +04:00
|
|
|
|
|
2024-04-07 15:05:57 +04:00
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
2024-05-07 23:20:02 +04:00
|
|
|
|
ClientId = ClientId,
|
2024-05-22 02:01:59 +04:00
|
|
|
|
ClientFIO = Client.ClientFIO,
|
|
|
|
|
PizzaId = PizzaId,
|
|
|
|
|
PizzaName = Pizza.PizzaName,
|
2024-06-21 14:39:07 +04:00
|
|
|
|
ImplementerId = ImplementerId,
|
|
|
|
|
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null,
|
2024-04-07 15:05:57 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|