80 lines
1.9 KiB
C#
80 lines
1.9 KiB
C#
using ComputerShopContracts.BindingModels;
|
||
using ComputerShopContracts.ViewModels;
|
||
using ComputerShopDataModels.Enums;
|
||
using ComputerShopDataModels.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel.DataAnnotations;
|
||
using System.ComponentModel.DataAnnotations.Schema;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace ComputerShopDatabaseImplement.Models
|
||
{
|
||
//!!!ДЛЯ СВЯЗИ МНОГИЕ-КО-МНОГИМ ДОБАВИТЬ ПО АНАЛОГИИ С Textile СЛОВАРИ КАСАТЕЛЬНО ПАРТИЙ И ЗАЯВОК
|
||
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; }
|
||
|
||
|
||
//!!!ПРОВЕРМТЬ, ЧТО ПАРВИЛЬНЫЕ ВНЕШНИЕ КЛЮЧИ
|
||
|
||
[ForeignKey("OrderId")]
|
||
public virtual List<RequestOrder> Requests { get; set; } = new();
|
||
|
||
//!!!было ShipmentOrders
|
||
[ForeignKey("OrderId")]
|
||
public virtual List<ShipmentOrder> Shipments { get; set; } = new();
|
||
|
||
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;
|
||
}
|
||
using var context = new ComputerShopDatabase();
|
||
Status = model.Status;
|
||
context.SaveChanges();
|
||
}
|
||
|
||
//!!!МБ НАДО БУДЕТ ДОБАВИТЬ В OrderViewModel ЕЩЁ ЧТО-ТО, И ТУТ ТОЖЕ
|
||
public OrderViewModel GetViewModel => new()
|
||
{
|
||
Id = Id,
|
||
UserId = UserId,
|
||
DateCreate = DateCreate,
|
||
Status = Status,
|
||
Sum = Sum
|
||
};
|
||
}
|
||
}
|