From 05b0fb35d6cda1ef3bd62adaf525fb3ae6814be4 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sun, 23 Jun 2024 00:33:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B4=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Contracts/SearchModels/ProductSearchModel.cs | 6 +- .../Implements/ProductStorage.cs | 72 +++++++++++++++++++ .../Implements/PurchaseStorage.cs | 39 ++++++++++ DatabaseImplement/Implements/SellStorage.cs | 39 ++++++++++ 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 DatabaseImplement/Implements/ProductStorage.cs create mode 100644 DatabaseImplement/Implements/PurchaseStorage.cs create mode 100644 DatabaseImplement/Implements/SellStorage.cs diff --git a/Contracts/SearchModels/ProductSearchModel.cs b/Contracts/SearchModels/ProductSearchModel.cs index a6527dd..c038b81 100644 --- a/Contracts/SearchModels/ProductSearchModel.cs +++ b/Contracts/SearchModels/ProductSearchModel.cs @@ -10,7 +10,9 @@ namespace Contracts.SearchModels { public Guid? Id { get; set; } public string? Name { get; set; } - public double? Price { get; set; } - public double? Rate { get; set; } + public double? PriceFrom { get; set; } + public double? PriceTo { get; set; } + public double? RateFrom { get; set; } + public double? RateTo { get; set; } } } diff --git a/DatabaseImplement/Implements/ProductStorage.cs b/DatabaseImplement/Implements/ProductStorage.cs new file mode 100644 index 0000000..3a1136c --- /dev/null +++ b/DatabaseImplement/Implements/ProductStorage.cs @@ -0,0 +1,72 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Implements +{ + public class ProductStorage : IProductStorage + { + public ProductBindingModel? Delete(ProductSearchModel model) + { + if (model.Id is null && model.Name is null && model.Price is null && model.Rate is null) + { + return null; + } + + var context = new Database(); + var product = context.Products.FirstOrDefault(p => + (model.Id.HasValue && p.Id == model.Id) || (!string.IsNullOrEmpty(p.Name) && p.Name.Contains(model.Name))); + + if (product is null) + { + return null; + } + context.Remove(product); + context.SaveChanges(); + + return product.GetBindingModel(); + } + + public ProductBindingModel? GetElement(ProductSearchModel model) + { + if (model.Id is null && string.IsNullOrWhiteSpace(model.Name)) + { + return null; + } + var context = new Database(); + return context.Products + .FirstOrDefault(prod => (model.Id.HasValue && prod.Id == model.Id) + || (!string.IsNullOrWhiteSpace(model.Name) && prod.Name.Contains(model.Name)))?.GetBindingModel(); + } + + public IEnumerable GetList(ProductSearchModel? model) + { + if (model.Id is null && string.IsNullOrWhiteSpace(model.Name) || model.RateFrom > model.RateTo) + { + return null; + } + var context = new Database(); + return context.Products + .Where(prod => (model.Id.HasValue && prod.Id == model.Id) + || (!string.IsNullOrWhiteSpace(model.Name) && prod.Name.Contains(model.Name)) + || ((model.RateFrom.HasValue && model.RateTo.HasValue) && ((model.RateFrom < prod.Rate && prod.Rate < model.RateTo))) + || ((model.PriceFrom.HasValue && model.PriceTo.HasValue) && ((model.PriceFrom < prod.Price && prod.Price < model.PriceTo)))) + .Select(r => r.GetBindingModel()); ; + } + + public ProductBindingModel? Insert(ProductBindingModel model) + { + throw new NotImplementedException(); + } + + public ProductBindingModel? Update(ProductBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/DatabaseImplement/Implements/PurchaseStorage.cs b/DatabaseImplement/Implements/PurchaseStorage.cs new file mode 100644 index 0000000..2323dd2 --- /dev/null +++ b/DatabaseImplement/Implements/PurchaseStorage.cs @@ -0,0 +1,39 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Implements +{ + public class PurchaseStorage : IPurchaseStorage + { + public PurchaseBindingModel? Delete(PurchaseSearchModel model) + { + throw new NotImplementedException(); + } + + public PurchaseBindingModel? GetElement(PurchaseSearchModel model) + { + throw new NotImplementedException(); + } + + public IEnumerable GetList(PurchaseSearchModel? model) + { + throw new NotImplementedException(); + } + + public PurchaseBindingModel? Insert(PurchaseBindingModel model) + { + throw new NotImplementedException(); + } + + public PurchaseBindingModel? Update(PurchaseBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/DatabaseImplement/Implements/SellStorage.cs b/DatabaseImplement/Implements/SellStorage.cs new file mode 100644 index 0000000..aeac65f --- /dev/null +++ b/DatabaseImplement/Implements/SellStorage.cs @@ -0,0 +1,39 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Implements +{ + public class SellStorage : ISellStorage + { + public SellBindingModel? Delete(SellSearchModel model) + { + + } + + public SellBindingModel? GetElement(SellSearchModel model) + { + throw new NotImplementedException(); + } + + public IEnumerable GetList(SellSearchModel? model) + { + throw new NotImplementedException(); + } + + public SellBindingModel? Insert(SellBindingModel model) + { + throw new NotImplementedException(); + } + + public SellBindingModel? Update(SellBindingModel model) + { + throw new NotImplementedException(); + } + } +}