2023-03-06 10:20:01 +04:00
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
using ConfectioneryDataModels.Enums;
|
|
|
|
|
using ConfectioneryDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
2023-05-14 00:56:36 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
2023-03-06 10:20:01 +04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ConfectioneryDataBaseImplement.Models
|
|
|
|
|
{
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataContract]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
public int Id { get; private set; }
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int PastryId { get; private set; }
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
[Required]
|
2023-04-03 10:49:52 +04:00
|
|
|
|
public int ClientId { get; set; }
|
|
|
|
|
public virtual Client Client { get; set; } = new();
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-04-27 22:54:15 +04:00
|
|
|
|
public int? ImplementerId { get; set; }
|
|
|
|
|
public virtual Implementer? Implementer { get; set; } = new();
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-04-03 10:49:52 +04:00
|
|
|
|
[Required]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
public int Count { get; private set; }
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; private set; }
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public OrderStatus Status { get; private set; }
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public DateTime DateCreate { get; private set; }
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
2023-04-03 10:49:52 +04:00
|
|
|
|
public static Order? Create(ConfectioneryDatabase context, OrderBindingModel? model)
|
2023-03-06 10:20:01 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
PastryId = model.PastryId,
|
2023-04-03 10:49:52 +04:00
|
|
|
|
ClientId = model.ClientId,
|
|
|
|
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
2023-03-06 10:20:01 +04:00
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
2023-04-27 22:54:15 +04:00
|
|
|
|
DateImplement = model.DateImplement,
|
|
|
|
|
ImplementerId = model.ImplementerId,
|
|
|
|
|
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null,
|
2023-03-06 10:20:01 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2023-04-27 22:54:15 +04:00
|
|
|
|
public void Update(ConfectioneryDatabase context, OrderBindingModel? model)
|
2023-03-06 10:20:01 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
2023-04-27 22:54:15 +04:00
|
|
|
|
if (model.ImplementerId.HasValue) ImplementerId = model.ImplementerId;
|
|
|
|
|
if (model.ImplementerId.HasValue) Implementer = context.Implementers.First(x => x.Id == model.ImplementerId);
|
2023-03-06 10:20:01 +04:00
|
|
|
|
if (model.DateImplement.HasValue) DateImplement = model.DateImplement;
|
|
|
|
|
}
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
PastryId = PastryId,
|
2023-04-03 10:49:52 +04:00
|
|
|
|
ClientId = ClientId,
|
|
|
|
|
ClientFIO = Client.ClientFIO,
|
2023-04-28 11:06:27 +04:00
|
|
|
|
ClientEmail = Client.Email,
|
2023-03-06 10:20:01 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
2023-04-27 22:54:15 +04:00
|
|
|
|
DateImplement = DateImplement,
|
|
|
|
|
ImplementerId = ImplementerId,
|
|
|
|
|
ImplementerFIO = Implementer?.ImplementerFIO
|
2023-03-06 10:20:01 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|