2024-11-14 20:27:58 +04:00

65 lines
1.7 KiB
C#

using Contracts.BindingModels;
using Contracts.ViewModels;
using Models.Enums;
using Models.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Product : IProductModel
{
public int Id { get; private set; }
[Required]
public string Name { get; private set; } = string.Empty;
[Required]
public string Description { get; private set; } = string.Empty;
[Required]
public string Category { get; private set; }
public int? CountOnStorage { get; private set; }
public static Product? Create(ProductBindingModel model)
{
if (model == null) return null;
return new Product
{
Id = model.Id,
Name = model.Name,
Description = model.Description,
Category = model.Category,
CountOnStorage = model.CountOnStorage,
};
}
public void Update(ProductBindingModel model)
{
if (model == null) return;
Name = model.Name;
Description = model.Description;
Category = model.Category;
CountOnStorage = model.CountOnStorage;
}
public ProductViewModel GetViewModel => new()
{
Id = Id.ToString(),
Name = Name,
Description = Description,
Category = Category,
CountOnStorage = CountOnStorage,
CountOnStorageS = CountOnStorage != null ? CountOnStorage.ToString() : "Нет в наличии",
};
}
}