SUBD_PIbd-21_Balberova_D.N./BeautySaloon/BeautySaloonDatabaseImplement/Order.cs

94 lines
2.3 KiB
C#

using BeautySaloonContracts.BindingModels;
using BeautySaloonContracts.ViewModels;
using BeautySaloonDataModels;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Numerics;
namespace BeautySaloonDatabaseImplement;
/// <summary>
/// Сущность заказы
/// </summary>
public partial class Order : IOrderModel
{
/// <summary>
/// Уникальный идентификатор
/// </summary>
public int Id { get; set; }
/// <summary>
/// Дата
/// </summary>
public DateOnly Date { get; set; }
/// <summary>
/// Сумма
/// </summary>
public decimal Sum { get; set; }
/// <summary>
/// Идентификатор клиента
/// </summary>
public int ClientId { get; set; }
/// <summary>
/// Идентификатор сотрудника
/// </summary>
public int EmployeeId { get; set; }
public virtual Client Client { get; set; } = null!;
public virtual Employee Employee { get; set; } = null!;
public virtual ServiceOrder? ServiceOrder { get; set; }
public Dictionary<int, (TimeOnly, IServiceModel, IEmployeeModel)> _orderServices = null;
public virtual List<ServiceOrder> Services { get; set; } = new();
public Dictionary<int, (TimeOnly, IServiceModel, IEmployeeModel)> OrderServices
{
get
{
if (ServiceOrder != null)
{
_orderServices = Services
.ToDictionary(x => x.ServiceId,
x => (x.Date, x.Service as IServiceModel, x.Employee as IEmployeeModel));
}
return _orderServices;
}
}
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
Date = model.Date,
Sum = model.Sum,
ClientId = model.ClientId,
EmployeeId = model.EmployeeId
};
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
Date = Date,
Sum = Sum,
ClientId = ClientId,
EmployeeId = EmployeeId,
ClientName = Client.Name,
EmployeeName = Employee.Name,
ClientPhone = Client.Phone,
EmployeePhone = Employee.Phone
};
}