2024-05-13 22:15:56 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-03-17 21:00:26 +04:00
|
|
|
|
using FishFactoryDataModel.Enums;
|
|
|
|
|
using FishFactoryContracts.BindingModels;
|
|
|
|
|
using FishFactoryContracts.ViewModels;
|
2024-03-20 10:57:23 +04:00
|
|
|
|
using FishFactoryDataModel.Models;
|
2024-03-17 21:00:26 +04:00
|
|
|
|
|
|
|
|
|
namespace FishFactoryDatabaseImplement.Models
|
|
|
|
|
{
|
2024-03-20 10:57:23 +04:00
|
|
|
|
public class Order : IOrderModel
|
2024-03-17 21:00:26 +04:00
|
|
|
|
{
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public int Id { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public int CannedId { get; private set; }
|
2024-05-13 22:15:56 +04:00
|
|
|
|
public virtual Canned Canned { get; set; }
|
2024-05-06 22:32:01 +04:00
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; private set; }
|
2024-05-13 22:15:56 +04:00
|
|
|
|
public virtual Client Client { get; set; }
|
2024-05-06 22:32:01 +04:00
|
|
|
|
|
2024-05-13 22:15:56 +04:00
|
|
|
|
public int? ImplementerId { get; private set; }
|
|
|
|
|
public virtual Implementer? Implementer { get; set; } = new();
|
2024-05-12 19:24:51 +04:00
|
|
|
|
|
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public int Count { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public double Sum { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
2024-03-17 21:00:26 +04:00
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
public static Order Create (FishFactoryDatabase context, OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
CannedId = model.CannedId,
|
2024-03-20 10:57:23 +04:00
|
|
|
|
Canned = context.Canneds.First(x => x.Id == model.CannedId),
|
2024-05-06 22:32:01 +04:00
|
|
|
|
ClientId = model.ClientId,
|
|
|
|
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
2024-05-12 19:24:51 +04:00
|
|
|
|
ImplementerId = model.ImplementerId,
|
2024-05-14 19:05:59 +04:00
|
|
|
|
Implementer = model.ImplementerId == null ? null : context.Implementers.First(i => i.Id == model.ImplementerId),
|
|
|
|
|
|
|
|
|
|
Count = model.Count,
|
2024-03-17 21:00:26 +04:00
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateImplement = model.DateImplement,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(OrderBindingModel model)
|
|
|
|
|
{
|
2024-03-19 20:55:45 +04:00
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-13 22:15:56 +04:00
|
|
|
|
using var context = new FishFactoryDatabase();
|
|
|
|
|
|
2024-05-12 19:24:51 +04:00
|
|
|
|
ImplementerId = model.ImplementerId;
|
2024-03-17 21:00:26 +04:00
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
|
|
|
|
}
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
CannedId = CannedId,
|
|
|
|
|
CannedName = Canned.CannedName,
|
2024-05-06 22:32:01 +04:00
|
|
|
|
ClientId = ClientId,
|
|
|
|
|
ClientFIO = Client.ClientFIO,
|
2024-05-12 19:24:51 +04:00
|
|
|
|
ImplementerId = ImplementerId,
|
2024-05-14 19:05:59 +04:00
|
|
|
|
ImplementerFIO = Implementer == null ? string.Empty : Implementer.ImplementerFIO,
|
2024-05-06 22:32:01 +04:00
|
|
|
|
Count = Count,
|
2024-03-17 21:00:26 +04:00
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|