PIbd-23-Nasyrov-A.G.-Flower.../FlowerShopDatabaseImplement/Order.cs

85 lines
2.6 KiB
C#
Raw Permalink Normal View History

2024-03-12 21:47:28 +04:00
using FlowerShopDataModels;
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.ViewModels;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FlowerShopDataModels.Enums;
namespace FlowerShopDatabaseImplement.Models
2024-03-12 21:47:28 +04:00
{
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int Count { get; private 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; }
[Required]
public int FlowerId { get; private set; }
2024-04-06 18:45:56 +04:00
[Required]
public int ClientId { get; private set; }
public virtual Client? Client { get; private set; }
public virtual Flower? Flower { get; set; }
2024-04-22 20:37:14 +04:00
public int? ImplementerId { get; private set; } = null;
public virtual Implementer? Implementer { get; private set; }
public static Order? Create(OrderBindingModel model)
2024-03-12 21:47:28 +04:00
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
FlowerId = model.FlowerId,
2024-04-06 18:45:56 +04:00
ClientId = model.ClientId,
2024-04-22 20:37:14 +04:00
ImplementerId = model.ImplementerId,
};
2024-03-12 21:47:28 +04:00
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
2024-04-22 20:37:14 +04:00
ImplementerId = model.ImplementerId;
}
2024-03-12 21:47:28 +04:00
public OrderViewModel GetViewModel => new()
{
FlowerId = FlowerId,
Count = Count,
Sum = Sum,
Status = Status,
2024-04-06 18:45:56 +04:00
ClientId = ClientId,
2024-04-22 20:37:14 +04:00
ImplementerId = ImplementerId,
DateCreate = DateCreate,
2024-03-12 21:47:28 +04:00
DateImplement = DateImplement,
FlowerName = Flower?.FlowerName ?? String.Empty,
2024-03-12 21:47:28 +04:00
Id = Id,
2024-04-09 10:37:23 +04:00
ClientFIO = Client?.ClientFIO ?? String.Empty,
2024-04-22 20:37:14 +04:00
ImplementerFIO = (Implementer != null ? Implementer.ImplementerFIO : string.Empty)
};
2024-03-12 21:47:28 +04:00
}
}