2024-04-19 01:04:50 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using TravelCompanyContracts.BindingModels;
|
2024-03-09 00:39:32 +04:00
|
|
|
|
using TravelCompanyContracts.ViewModels;
|
|
|
|
|
using TravelCompanyDataModels.Enums;
|
|
|
|
|
using TravelCompanyDataModels.Models;
|
|
|
|
|
|
|
|
|
|
namespace TravelCompanyDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
2024-04-19 01:04:50 +04:00
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public int TravelId { get; private set; }
|
|
|
|
|
|
|
|
|
|
public virtual Travel Travel { get; set; } = new();
|
|
|
|
|
|
2024-03-09 00:39:32 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int Count { get; private set; }
|
2024-04-19 01:04:50 +04:00
|
|
|
|
|
2024-03-09 00:39:32 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; private set; }
|
2024-04-19 01:04:50 +04:00
|
|
|
|
|
2024-03-09 00:39:32 +04:00
|
|
|
|
[Required]
|
2024-04-19 01:04:50 +04:00
|
|
|
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
|
|
|
|
|
2024-03-09 00:39:32 +04:00
|
|
|
|
[Required]
|
2024-04-19 01:04:50 +04:00
|
|
|
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
|
|
|
|
2024-03-09 00:39:32 +04:00
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
|
|
|
|
|
2024-04-19 01:04:50 +04:00
|
|
|
|
public static Order Create(TravelCompanyDataBase context, OrderBindingModel model)
|
2024-03-09 00:39:32 +04:00
|
|
|
|
{
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2024-04-19 01:04:50 +04:00
|
|
|
|
TravelId = model.TravelId,
|
|
|
|
|
Travel = context.Travels.First(x => x.Id == model.TravelId),
|
2024-03-09 00:39:32 +04:00
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateImplement = model.DateImplement,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
2024-04-19 01:04:50 +04:00
|
|
|
|
Id = Id,
|
2024-03-09 00:39:32 +04:00
|
|
|
|
TravelId = TravelId,
|
2024-04-19 01:04:50 +04:00
|
|
|
|
TravelName = Travel.TravelName,
|
2024-03-09 00:39:32 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|