50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using Contracts.BindingModels;
|
|
using Contracts.ViewModels;
|
|
using DataModels.Enums;
|
|
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
|
|
{
|
|
public class Purchase : IPurchase
|
|
{
|
|
public Guid Id { get; set; }
|
|
[Required]
|
|
public DateTime DatePurchase { get; set; }
|
|
[Required]
|
|
public PurchaseStatus Status { get; private set; } = PurchaseStatus.Unknown;
|
|
public PurchaseBindingModel GetBindingModel() => new()
|
|
{
|
|
Id = Id,
|
|
DatePurchase = DatePurchase
|
|
};
|
|
|
|
public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new()
|
|
{
|
|
Id = model.Id,
|
|
DatePurchase = model.DatePurchase
|
|
};
|
|
|
|
public static Purchase ToPurchaseFromBinding(PurchaseBindingModel model, Purchase purchase) => new()
|
|
{
|
|
Id = model.Id,
|
|
DatePurchase = model.DatePurchase,
|
|
};
|
|
|
|
public void Update(PurchaseBindingModel model, Purchase purchase)
|
|
{
|
|
if (model is null)
|
|
{
|
|
throw new ArgumentNullException("Update purchase: binding model is null");
|
|
}
|
|
|
|
DatePurchase = purchase.DatePurchase;
|
|
}
|
|
}
|
|
}
|