using Contracts.BindingModels; using Contracts.ViewModels; 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 Product : IProduct { [Required] public Guid Id { get; set; } [Required] public string Name { get; set; } = string.Empty; [Required] public double Price { get; set; } [Required] public double Rate { get; set; } [Required] public bool IsBeingSold { get; set; } [Required] public int Amount { get; set; } public ProductBindingModel GetBindingModel() => new() { Id = Id, Name = Name, Price = Price, Rate = Rate, IsBeingSold = IsBeingSold, Amount = Amount }; public static Product ToProductFromView(ProductViewModel model, Product product) => new() { Id = model.Id, Name = model.Name, Price = model.Price, Rate = model.Rating, IsBeingSold = model.IsBeingSold, Amount = model.Amount }; public static Product ToProductFromBinding(ProductBindingModel model, Product product) => new() { Id = model.Id, Name = model.Name, Price = model.Price, Rate = model.Rate, IsBeingSold = model.IsBeingSold, Amount = model.Amount }; public void Update(ProductBindingModel model, Product product) { if (model is null) { throw new ArgumentNullException("Update product: binding model is null"); } Name = model.Name; Price = model.Price; Rate = model.Rate; IsBeingSold = model.IsBeingSold; Amount = model.Amount; } } }