2024-04-21 16:04:37 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BarContracts.BindingModels;
|
|
|
|
|
using BarContracts.ViewModels;
|
|
|
|
|
using BarDataModels.Models;
|
|
|
|
|
using BarDataModels.Enums;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace BarDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
[Required]
|
2024-05-08 23:27:46 +04:00
|
|
|
|
public int ClientId { get; private set; }
|
2024-05-17 23:10:48 +04:00
|
|
|
|
public int? ImplementerId { get; private set; }
|
|
|
|
|
[Required]
|
2024-04-21 16:04:37 +04:00
|
|
|
|
public int CocktailId { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public int Count { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public OrderStatus Status { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
2024-05-08 23:27:46 +04:00
|
|
|
|
public Client Client { get; set; }
|
2024-05-17 23:10:48 +04:00
|
|
|
|
public Implementer? Implementer { get; set; }
|
|
|
|
|
public Cocktail Cocktail { get; set; }
|
|
|
|
|
public static Order? Create(OrderBindingModel model, BarDatabase context)
|
2024-04-21 16:04:37 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2024-05-08 23:27:46 +04:00
|
|
|
|
ClientId = model.ClientId,
|
2024-05-17 23:10:48 +04:00
|
|
|
|
ImplementerId = model.ImplementerId,
|
|
|
|
|
CocktailId = model.CocktailId,
|
2024-04-21 16:04:37 +04:00
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
2024-05-17 23:10:48 +04:00
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId)!,
|
|
|
|
|
Cocktail = context.Cocktails.FirstOrDefault(x => x.Id == model.CocktailId)!,
|
|
|
|
|
};
|
2024-04-21 16:04:37 +04:00
|
|
|
|
}
|
|
|
|
|
public void Update(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
2024-05-17 23:10:48 +04:00
|
|
|
|
ImplementerId = model.ImplementerId;
|
|
|
|
|
}
|
|
|
|
|
public OrderViewModel GetViewModel
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
using var context = new BarDatabase();
|
|
|
|
|
return new OrderViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
CocktailId = CocktailId,
|
|
|
|
|
CocktailName = Cocktail.CocktailName,
|
|
|
|
|
ClientId = ClientId,
|
|
|
|
|
ImplementerId = ImplementerId,
|
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
|
|
|
|
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
|
|
|
|
|
ImplementerFIO = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-21 16:04:37 +04:00
|
|
|
|
}
|
|
|
|
|
|