PIbd-31_Malafeev.L.S._COP_25/Cop_25/DatabaseImplement/Models/Delivery.cs

62 lines
1.6 KiB
C#

using Contracts.BindlingModels;
using Contracts.ViewModels;
using Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Delivery : IDeliveryModel
{
public int Id { get; private set; }
[Required]
public string FCs { get; private set; } = string.Empty;
[Required]
public string DeliveryType { get; private set; } = string.Empty;
[Required]
public string Wishes { get; private set; } = string.Empty;
public string? DeliveryDate { get; private set; }
public static Delivery? Create(DeliveryBindingModel model)
{
if (model == null) return null;
return new Delivery
{
Id = model.Id,
FCs = model.FCs,
DeliveryDate = model.DeliveryDate,
DeliveryType = model.DeliveryType,
Wishes = model.Wishes,
};
}
public void Update(DeliveryBindingModel model)
{
if (model == null) return;
FCs = model.FCs;
DeliveryDate = model.DeliveryDate;
Wishes = model.Wishes;
DeliveryType = model.DeliveryType;
}
public DeliveryViewModel GetViewModel => new()
{
Id = Id,
FCs = FCs,
DeliveryDate = DeliveryDate,
Wishes = Wishes,
DeliveryType = DeliveryType,
};
}
}