2023-03-05 18:39:34 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using JewelryStoreContracts.ViewModels;
|
|
|
|
|
using JewelryStoreContracts.BindingModels;
|
|
|
|
|
using JewelryStoreDataModels.Models;
|
|
|
|
|
using JewelryStoreDataModels.Enums;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace JewelryStoreDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
|
|
|
|
|
public int JewelId { get; private set; }
|
|
|
|
|
|
2023-04-01 21:09:59 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; set; }
|
2023-04-17 18:44:59 +04:00
|
|
|
|
public int? ImplementerId { get; private set; }
|
2023-04-01 21:09:59 +04:00
|
|
|
|
|
2023-03-05 18:39:34 +04:00
|
|
|
|
public string JewelName { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public int Count { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
|
|
|
|
|
|
|
|
|
public virtual Jewel Jewel { get; set; }
|
2023-04-04 14:24:40 +04:00
|
|
|
|
public virtual Client Client { get; set; }
|
2023-04-17 18:44:59 +04:00
|
|
|
|
public Implementer? Implementer { get; set; }
|
2023-03-05 18:39:34 +04:00
|
|
|
|
|
|
|
|
|
public static Order? Create(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
JewelId = model.JewelId,
|
2023-04-01 21:09:59 +04:00
|
|
|
|
ClientId = model.ClientId,
|
2023-04-17 18:44:59 +04:00
|
|
|
|
ImplementerId = model.ImplementerId,
|
2023-03-05 18:39:34 +04:00
|
|
|
|
JewelName = model.JewelName,
|
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateImplement = model.DateImplement
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JewelId = model.JewelId;
|
|
|
|
|
JewelName = model.JewelName;
|
|
|
|
|
Count = model.Count;
|
|
|
|
|
Sum = model.Sum;
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateCreate = model.DateCreate;
|
|
|
|
|
DateImplement = model.DateImplement;
|
2023-04-17 23:38:44 +04:00
|
|
|
|
ImplementerId = model.ImplementerId;
|
|
|
|
|
|
2023-03-05 18:39:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-04 14:24:40 +04:00
|
|
|
|
public OrderViewModel GetViewModel
|
2023-03-05 18:39:34 +04:00
|
|
|
|
{
|
2023-04-04 14:24:40 +04:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
using var context = new JewelryStoreDataBase();
|
|
|
|
|
return new OrderViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
JewelId = JewelId,
|
|
|
|
|
ClientId = ClientId,
|
2023-04-17 18:44:59 +04:00
|
|
|
|
ImplementerId = ImplementerId,
|
2023-04-04 14:24:40 +04:00
|
|
|
|
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
|
2023-04-15 19:27:19 +04:00
|
|
|
|
JewelName = context.Jewels.FirstOrDefault(x => x.Id == JewelId)?.JewelName ?? string.Empty,
|
2023-04-04 14:24:40 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
2023-04-17 18:44:59 +04:00
|
|
|
|
DateImplement = DateImplement,
|
|
|
|
|
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
|
2023-04-04 14:24:40 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-05 18:39:34 +04:00
|
|
|
|
}
|
2023-04-04 14:24:40 +04:00
|
|
|
|
}
|