PIbd-31_MasenkinMS_COP_22/Components/DatabaseImplement/Models/Order.cs
2024-09-23 05:00:01 +04:00

98 lines
2.5 KiB
C#

using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
/// <summary>
/// Сущность "Счет"
/// </summary>
public class Order : IOrderModel
{
/// <summary>
/// Идентификатор
/// </summary>
public int Id { get; private set; }
/// <summary>
/// ФИО водителя
/// </summary>
[Required]
public string WaiterFullName { get; private set; } = string.Empty;
/// <summary>
/// Информация по счету
/// </summary>
[Required]
public string Info { get; private set; } = string.Empty;
/// <summary>
/// Тип заказа
/// </summary>
[Required]
public string Type { get; private set; } = string.Empty;
/// <summary>
/// Сумма заказа
/// </summary>
public double? Sum { get; private set; }
/// <summary>
/// Создать модель
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
return null;
}
return new Order
{
Id = model.Id,
WaiterFullName = model.WaiterFullName,
Info = model.Info,
Type = model.Type,
Sum = model.Sum,
};
}
/// <summary>
/// Изменить модель
/// </summary>
/// <param name="model"></param>
public void Update(OrderBindingModel model)
{
if (model == null)
{
return;
}
WaiterFullName = model.WaiterFullName;
Info = model.Info;
Type = model.Type;
Sum = model.Sum;
}
/// <summary>
/// Получить модель отображения
/// </summary>
public OrderViewModel GetViewModel => new()
{
Id = Id,
WaiterFullName = WaiterFullName,
Info = Info,
Type = Type,
Sum = Sum.ToString(),
};
}
}