PIAPS_CW/DatabaseImplement/Models/Purchase.cs

50 lines
1.2 KiB
C#
Raw Permalink Normal View History

2024-06-20 22:32:22 +04:00
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Enums;
2024-06-11 12:18:10 +04:00
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;
2024-06-20 22:32:22 +04:00
public PurchaseBindingModel GetBindingModel() => new()
{
Id = Id,
DatePurchase = DatePurchase
};
2024-06-11 12:18:10 +04:00
2024-06-20 22:32:22 +04:00
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;
}
2024-06-11 12:18:10 +04:00
}
}