75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
|
using ComputerShopContracts.BindingModels;
|
|||
|
using ComputerShopContracts.ViewModels;
|
|||
|
using ComputerShopDataModels.Enums;
|
|||
|
using ComputerShopDataModels.Models;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace ComputerShopDatabaseImplement.Models
|
|||
|
{
|
|||
|
internal class Purchase : IPurchaseModel
|
|||
|
{
|
|||
|
public string ComponentName { get; private set; } = String.Empty;
|
|||
|
public int Id { get; private set; }
|
|||
|
[Required]
|
|||
|
public int ComponentId { get; private set; }
|
|||
|
[Required]
|
|||
|
public int Count { get; private set; }
|
|||
|
[Required]
|
|||
|
public double Sum { get; private set; }
|
|||
|
[Required]
|
|||
|
public PurchaseStatus Status { get; private set; } = PurchaseStatus.Неизвестен;
|
|||
|
[Required]
|
|||
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|||
|
|
|||
|
public DateTime? DateImplement { get; private set; }
|
|||
|
public virtual Component Component { get; set; }
|
|||
|
|
|||
|
public static Purchase? Create(PurchaseBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Purchase
|
|||
|
{
|
|||
|
ComponentId = model.ComponentId,
|
|||
|
ComponentName = model.ComponentName,
|
|||
|
Count = model.Count,
|
|||
|
Sum = model.Sum,
|
|||
|
Status = model.Status,
|
|||
|
DateCreate = model.DateCreate,
|
|||
|
DateImplement = model.DateImplement,
|
|||
|
Id = model.Id,
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void Update(PurchaseBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Status = model.Status;
|
|||
|
DateImplement = model.DateImplement;
|
|||
|
}
|
|||
|
|
|||
|
public PurchaseViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
ComponentId = ComponentId,
|
|||
|
Count = Count,
|
|||
|
Sum = Sum,
|
|||
|
DateCreate = DateCreate,
|
|||
|
DateImplement = DateImplement,
|
|||
|
Id = Id,
|
|||
|
Status = Status,
|
|||
|
ComponentName = ComponentName
|
|||
|
};
|
|||
|
}
|
|||
|
}
|