2024-03-04 19:46:39 +04:00
|
|
|
|
using IceCreamShopContracts.BindingModels;
|
|
|
|
|
using IceCreamShopContracts.ViewModels;
|
|
|
|
|
using IceCreamShopDataModels.Enums;
|
|
|
|
|
using IceCreamShopDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace IceCreamShopDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
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 IceCreamId { get; private set; }
|
2024-03-18 17:16:29 +04:00
|
|
|
|
public virtual IceCream IceCream { get; private set; }
|
2024-04-01 20:04:44 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; private set; }
|
|
|
|
|
public virtual Client Client { get; private set; }
|
2024-03-18 17:16:29 +04:00
|
|
|
|
public static Order? Create(IceCreamShopDataBase context, OrderBindingModel model)
|
2024-03-04 19:46:39 +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,
|
|
|
|
|
IceCreamId = model.IceCreamId,
|
2024-04-01 20:04:44 +04:00
|
|
|
|
IceCream = context.IceCreams.FirstOrDefault(x => x.Id == model.IceCreamId),
|
2024-04-02 11:13:02 +04:00
|
|
|
|
ClientId = model.ClientId,
|
|
|
|
|
Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId),
|
|
|
|
|
};
|
2024-03-04 19:46:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
IceCreamId = IceCreamId,
|
2024-04-01 20:04:44 +04:00
|
|
|
|
ClientId = ClientId,
|
2024-03-04 19:46:39 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
2024-03-18 17:16:29 +04:00
|
|
|
|
IceCreamName = IceCream.IceCreamName,
|
2024-03-04 19:46:39 +04:00
|
|
|
|
Id = Id,
|
2024-04-01 20:04:44 +04:00
|
|
|
|
ClientFIO = Client.ClientFIO
|
2024-03-04 19:46:39 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|