PIAPS_CW/DatabaseImplement/Models/Sell.cs

67 lines
1.4 KiB
C#

using Contracts.BindingModels;
using Contracts.Converters;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Sell : ISell
{
public Guid Id { get; set; }
public DateTime DateSell { get; set; }
public Guid? SupplyDocId { get; set; }
public virtual SupplyDoc? SupplyDoc { get; set; }
public static Sell Create(Database context, SellBindingModel model)
{
return new Sell()
{
Id = model.Id,
DateSell = model.DateSell,
SupplyDocId = model.SupplyDocId,
};
}
public SellBindingModel GetBindingModel() => new()
{
Id = Id,
DateSell = DateSell,
SupplyDocId = SupplyDocId,
};
public SellViewModel GetViewModel() => new()
{
Id = Id,
DateSell = DateSell,
SupplyDocId = SupplyDocId,
};
public static Sell ToSellFromView(SellViewModel model, Sell sell) => new()
{
Id = model.Id,
DateSell = model.DateSell
};
public static Sell ToSellFromBinding(SellBindingModel model, Sell sell) => new()
{
Id = model.Id,
DateSell = model.DateSell,
};
public void Update(SellBindingModel model)
{
if (model is null)
{
throw new ArgumentNullException("Update user: binding model is null");
}
DateSell = model.DateSell;
SupplyDocId = model.SupplyDocId;
}
}
}