2024-04-25 01:10:50 +04:00
|
|
|
|
using ComputerShopContracts.BindingModels;
|
|
|
|
|
using ComputerShopContracts.ViewModels;
|
|
|
|
|
using ComputerShopDataModels.Enums;
|
|
|
|
|
using ComputerShopDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-04-25 17:44:09 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-04-25 01:10:50 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public int UserId { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
2024-04-25 17:44:09 +04:00
|
|
|
|
[ForeignKey("OrderId")]
|
2024-04-27 19:31:00 +04:00
|
|
|
|
public virtual List<RequestOrder> Requests { get; set; } = new();
|
2024-04-25 17:44:09 +04:00
|
|
|
|
|
|
|
|
|
[ForeignKey("OrderId")]
|
2024-04-27 19:31:00 +04:00
|
|
|
|
public virtual List<ShipmentOrder> Shipments { get; set; } = new();
|
2024-04-25 17:44:09 +04:00
|
|
|
|
|
2024-04-25 01:10:50 +04:00
|
|
|
|
public static Order? Create(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
UserId = model.UserId,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-30 00:02:09 +04:00
|
|
|
|
//DateCreate не обновляю, потому что странно менять дату оформления заказа после его создания
|
2024-04-25 01:10:50 +04:00
|
|
|
|
Status = model.Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
UserId = UserId,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
Status = Status,
|
|
|
|
|
Sum = Sum
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|