65 lines
1.6 KiB
C#
65 lines
1.6 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 Category Category { get; private set; }
|
|||
|
|
|||
|
[Required]
|
|||
|
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,
|
|||
|
Name = Name,
|
|||
|
Description = Description,
|
|||
|
Category = Category,
|
|||
|
CountOnStorage = CountOnStorage,
|
|||
|
};
|
|||
|
}
|
|||
|
}
|