2024-03-20 10:21:07 +04:00
|
|
|
|
using GarmentFactoryContracts.BindingModels;
|
|
|
|
|
using GarmentFactoryContracts.ViewModels;
|
|
|
|
|
using GarmentFactoryDataModels.Enums;
|
|
|
|
|
using GarmentFactoryDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace GarmentFactoryDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
2024-04-11 13:43:22 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; private set; }
|
|
|
|
|
|
2024-03-20 10:21:07 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int TextileId { get; private set; }
|
|
|
|
|
|
2024-04-17 10:42:00 +04:00
|
|
|
|
public int? ImplementerId { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
2024-03-20 10:21:07 +04:00
|
|
|
|
public int Count { get; 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? DateComplete { get; private set; }
|
|
|
|
|
|
|
|
|
|
// Для передачи названия изделия
|
|
|
|
|
public virtual Textile Textile { get; set; }
|
|
|
|
|
|
2024-04-11 13:43:22 +04:00
|
|
|
|
// Для передачи ФИО клиента
|
|
|
|
|
public virtual Client Client { get; set; }
|
|
|
|
|
|
2024-04-17 10:42:00 +04:00
|
|
|
|
public virtual Implementer? Implementer { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
public static Order? Create(OrderBindingModel model)
|
2024-03-20 10:21:07 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-04-17 10:42:00 +04:00
|
|
|
|
using var context = new GarmentFactoryDatabase();
|
|
|
|
|
return new Order()
|
2024-03-20 10:21:07 +04:00
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2024-04-11 13:43:22 +04:00
|
|
|
|
ClientId = model.ClientId,
|
2024-03-20 10:21:07 +04:00
|
|
|
|
TextileId = model.TextileId,
|
2024-04-17 10:42:00 +04:00
|
|
|
|
ImplementerId = model.ImplementerId,
|
|
|
|
|
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null,
|
|
|
|
|
Count = model.Count,
|
2024-03-20 10:21:07 +04:00
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateComplete = model.DateComplete,
|
2024-04-17 10:42:00 +04:00
|
|
|
|
};
|
2024-03-20 10:21:07 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-17 10:42:00 +04:00
|
|
|
|
using var context = new GarmentFactoryDatabase();
|
|
|
|
|
ImplementerId = model.ImplementerId;
|
|
|
|
|
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null;
|
|
|
|
|
Status = model.Status;
|
2024-03-20 10:21:07 +04:00
|
|
|
|
DateComplete = model.DateComplete;
|
2024-04-17 10:42:00 +04:00
|
|
|
|
context.SaveChanges();
|
2024-03-20 10:21:07 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
2024-04-11 13:43:22 +04:00
|
|
|
|
ClientId = ClientId,
|
2024-03-20 10:21:07 +04:00
|
|
|
|
TextileId = TextileId,
|
2024-04-17 10:42:00 +04:00
|
|
|
|
ImplementerId = ImplementerId,
|
|
|
|
|
Count = Count,
|
2024-03-20 10:21:07 +04:00
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateComplete = DateComplete,
|
2024-04-11 13:43:22 +04:00
|
|
|
|
TextileName = Textile.TextileName,
|
2024-04-17 10:42:00 +04:00
|
|
|
|
ClientFIO = Client.ClientFIO,
|
|
|
|
|
ImplementerFIO = Implementer?.ImplementerFIO,
|
2024-04-11 13:43:22 +04:00
|
|
|
|
};
|
2024-03-20 10:21:07 +04:00
|
|
|
|
}
|
|
|
|
|
}
|