diff --git a/Contracts/BindingModels/SellBindingModel.cs b/Contracts/BindingModels/SellBindingModel.cs index 7f2c663..e0c32ed 100644 --- a/Contracts/BindingModels/SellBindingModel.cs +++ b/Contracts/BindingModels/SellBindingModel.cs @@ -8,6 +8,7 @@ namespace Contracts.BindingModels { public class SellBindingModel { + public Guid Id { get; set; } public DateTime DateSell { get; set; } } } diff --git a/Contracts/ViewModels/MediaFileViewModel.cs b/Contracts/ViewModels/MediaFileViewModel.cs index d2ca0f6..6acc484 100644 --- a/Contracts/ViewModels/MediaFileViewModel.cs +++ b/Contracts/ViewModels/MediaFileViewModel.cs @@ -1,4 +1,6 @@ -using System; +using Contracts.BindingModels; +using DataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,5 +12,18 @@ namespace Contracts.ViewModels { public Guid Id { get; set; } public string Location { get; set; } = string.Empty; - } + public string Name { get; set; } = string.Empty; + public Guid ProductId { get; set; } + public MediaFileBindingModel GetBindingModel() + { + return new MediaFileBindingModel + { + Id = Id, + Name = Name, + Location = Location, + ProductId = ProductId + }; + } + + } } diff --git a/Contracts/ViewModels/ProductViewModel.cs b/Contracts/ViewModels/ProductViewModel.cs index 4a5d4fd..1424a09 100644 --- a/Contracts/ViewModels/ProductViewModel.cs +++ b/Contracts/ViewModels/ProductViewModel.cs @@ -12,6 +12,9 @@ namespace Contracts.ViewModels public Guid Id { get; set; } public string Name { get; set; } = string.Empty; public int Price { get; set; } + public double Rating { get; set; } + public bool IsBeingSold { get; set; } + public int Amount { get; set; } public List MediaFiles { get; set; } = new(); } } diff --git a/Contracts/ViewModels/PurchaseViewModel.cs b/Contracts/ViewModels/PurchaseViewModel.cs index f777858..b14933c 100644 --- a/Contracts/ViewModels/PurchaseViewModel.cs +++ b/Contracts/ViewModels/PurchaseViewModel.cs @@ -11,7 +11,7 @@ namespace Contracts.ViewModels public class PurchaseViewModel { public Guid Id { get; set; } - public DateTime PurchaseDate { get; set; } + public DateTime DatePurchase { get; set; } public required IUser User { get; set; } public required List Products { get; set; } public PurchaseStatus Status { get; set; } diff --git a/Contracts/ViewModels/SellViewModel.cs b/Contracts/ViewModels/SellViewModel.cs index 54a40bd..285d63f 100644 --- a/Contracts/ViewModels/SellViewModel.cs +++ b/Contracts/ViewModels/SellViewModel.cs @@ -10,7 +10,7 @@ namespace Contracts.ViewModels public class SellViewModel { public Guid Id { get; set; } - public DateTime SellDate { get; set; } + public DateTime DateSell { get; set; } public ISupplyDoc? SupplyDoc { get; set; } } } diff --git a/DatabaseImplement/Database.cs b/DatabaseImplement/Database.cs index 7bb94c7..69e2127 100644 --- a/DatabaseImplement/Database.cs +++ b/DatabaseImplement/Database.cs @@ -21,5 +21,9 @@ namespace DatabaseImplement public virtual DbSet Roles { get; set; } = null!; public virtual DbSet Users { get; set; } = null!; + public virtual DbSet Sells { get; set; } = null!; + public virtual DbSet Purchases { get; set; } = null!; + public virtual DbSet Products { get; set; } = null!; + public virtual DbSet MediaFiles { get; set; } = null!; } } \ No newline at end of file diff --git a/DatabaseImplement/Models/MediaFile.cs b/DatabaseImplement/Models/MediaFile.cs index 71eec3c..bc3c9ec 100644 --- a/DatabaseImplement/Models/MediaFile.cs +++ b/DatabaseImplement/Models/MediaFile.cs @@ -1,4 +1,6 @@ -using DataModels.Models; +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -13,10 +15,56 @@ namespace DatabaseImplement.Models [Required] public Guid Id { get; set; } [Required] - public string Name { get; set; } + public string Name { get; set; } = string.Empty; [Required] - public string Location { get; set; } + public string Location { get; set; } = string.Empty; [Required] public Guid ProductId { get; set; } + + public MediaFileBindingModel GetBindingModel() + { + return new MediaFileBindingModel + { + Id = Id, + Name = Name, + Location = Location, + ProductId = ProductId + }; + } + + public static MediaFile ToMediaFileFromView(MediaFileViewModel model, MediaFile mediaFile) + { + return new MediaFile + { + Id = model.Id, + Name = model.Name, + Location = model.Location, + ProductId = model.ProductId + }; + } + + public static MediaFile ToMediaFileFromBinding(MediaFileBindingModel model, MediaFile mediaFile) + { + return new MediaFile + { + Id = model.Id, + Name = model.Name, + Location = model.Location, + ProductId = model.ProductId + }; + } + + public void Update(MediaFileBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + // Обновление свойств на основе модели привязки + Name = model.Name; + Location = model.Location; + ProductId = model.ProductId; + } } } diff --git a/DatabaseImplement/Models/Product.cs b/DatabaseImplement/Models/Product.cs index a615734..bc14d3e 100644 --- a/DatabaseImplement/Models/Product.cs +++ b/DatabaseImplement/Models/Product.cs @@ -1,4 +1,6 @@ -using DataModels.Models; +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -22,5 +24,49 @@ namespace DatabaseImplement.Models 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; + } } } diff --git a/DatabaseImplement/Models/Purchase.cs b/DatabaseImplement/Models/Purchase.cs index ecb1efc..5430b34 100644 --- a/DatabaseImplement/Models/Purchase.cs +++ b/DatabaseImplement/Models/Purchase.cs @@ -1,4 +1,6 @@ -using DataModels.Enums; +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Enums; using DataModels.Models; using System; using System.Collections.Generic; @@ -16,6 +18,32 @@ namespace DatabaseImplement.Models public DateTime DatePurchase { get; set; } [Required] public PurchaseStatus Status { get; private set; } = PurchaseStatus.Unknown; + public PurchaseBindingModel GetBindingModel() => new() + { + Id = Id, + DatePurchase = DatePurchase + }; + public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new() + { + Id = model.Id, + DatePurchase = model.DatePurchase + }; + + public static Purchase ToPurchaseFromBinding(PurchaseBindingModel model, Purchase purchase) => new() + { + Id = model.Id, + DatePurchase = model.DatePurchase, + }; + + public void Update(PurchaseBindingModel model, Purchase purchase) + { + if (model is null) + { + throw new ArgumentNullException("Update purchase: binding model is null"); + } + + DatePurchase = purchase.DatePurchase; + } } } diff --git a/DatabaseImplement/Models/Sell.cs b/DatabaseImplement/Models/Sell.cs index 3376e82..03a7f26 100644 --- a/DatabaseImplement/Models/Sell.cs +++ b/DatabaseImplement/Models/Sell.cs @@ -1,4 +1,7 @@ -using System; +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +9,36 @@ using System.Threading.Tasks; namespace DatabaseImplement.Models { - internal class Sell + public class Sell : ISell { + public Guid Id { get; set; } + public DateTime DateSell { get; set; } + + public SellBindingModel GetBindingModel() => new() + { + Id = Id, + DateSell = DateSell + }; + 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, Sell sell) + { + if (model is null) + { + throw new ArgumentNullException("Update user: binding model is null"); + } + + DateSell = sell.DateSell; + } } }