PIbd21_Makarov_DV_FlowerShop/FlowerShop/FlowerShopDatabaseImplement/Models/Order.cs

67 lines
2.0 KiB
C#
Raw Normal View History

2024-03-09 17:32:17 +04:00
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Enums;
using FlowerShopDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace FlowerShopDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
2024-05-17 15:02:32 +04:00
[Required]
2024-03-09 17:32:17 +04:00
public int FlowerId { get; private set; }
2024-05-17 15:02:32 +04:00
public virtual Flower Flower { get; set; }
[Required]
2024-04-04 18:22:29 +04:00
public int ClientId { get; private set; }
2024-05-17 15:02:32 +04:00
public virtual Client Client { get; set; }
2024-03-09 17:32:17 +04:00
[Required]
public int Count { get; set; }
[Required]
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
FlowerId = model.FlowerId,
2024-04-04 18:22:29 +04:00
ClientId = model.ClientId,
2024-03-09 17:32:17 +04:00
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 OrderViewModel GetViewModel => new()
{
Id = Id,
FlowerId = FlowerId,
2024-04-04 18:22:29 +04:00
ClientId = ClientId,
2024-03-09 17:32:17 +04:00
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}