diff --git a/ComputerStoreBusinessLogic/BusinessLogic/EmployeeReportByDateLogic.cs b/ComputerStoreBusinessLogic/BusinessLogic/EmployeeReportByDateLogic.cs new file mode 100644 index 0000000..a396efe --- /dev/null +++ b/ComputerStoreBusinessLogic/BusinessLogic/EmployeeReportByDateLogic.cs @@ -0,0 +1,71 @@ +using ComputerStoreContracts.BindingModels; +using ComputerStoreContracts.BusinessLogicContracts; +using ComputerStoreContracts.SearchModels; +using ComputerStoreContracts.StorageContracts; +using ComputerStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerStoreBusinessLogic.BusinessLogic +{ + public class EmployeeReportByDateLogic : IEmployeeReportByDateLogic + { + private readonly IPCStorage _pcStorage; + private readonly IProductStorage _productStorage; + private readonly IConsignmentStorage _consignmentStorage; + private readonly IRequestStorage _requestStorage; + + public EmployeeReportByDateLogic(IPCStorage pcStorage, IProductStorage productStorage, IConsignmentStorage consignmentStorage, IRequestStorage requestStorage) + { + _pcStorage = pcStorage; + _productStorage = productStorage; + _consignmentStorage = consignmentStorage; + _requestStorage = requestStorage; + } + + public List GetPCs(ReportBindingModel model) + { + return _pcStorage.GetFilteredList(new PCSearchModel + { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }) + .Select(x => new ReportPCByDateViewModel + { + PCName = x.Name, + Components = x.PCComponents.Values.Select(x => (x.Item1.Name, x.Item2)).ToList(), + EmployeeUsername = x.EmployeeUsername + }).ToList(); + } + + public List GetProducts(ReportBindingModel model) + { + return _productStorage.GetFilteredList(new ProductSearchModel + { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }) + .Select(x => new ReportProductByDateViewModel + { + ProductName = x.Name, + Components = x.ProductComponents.Values.Select(x => (x.Item1.Name, x.Item2)).ToList() + + }).ToList(); + + } + + public void SaveProductsToPdfFile(ReportBindingModel model) + { + //will be implemented in the future! + } + + public void SavePCsToPdfFile(ReportBindingModel model) + { + //will be implemented in the future! + } + } +} diff --git a/ComputerStoreBusinessLogic/BusinessLogic/EmployeeReportLogic.cs b/ComputerStoreBusinessLogic/BusinessLogic/EmployeeReportLogic.cs deleted file mode 100644 index 26748da..0000000 --- a/ComputerStoreBusinessLogic/BusinessLogic/EmployeeReportLogic.cs +++ /dev/null @@ -1,97 +0,0 @@ -using ComputerStoreContracts.BindingModels; -using ComputerStoreContracts.BusinessLogicContracts; -using ComputerStoreContracts.StorageContracts; -using ComputerStoreContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace ComputerStoreBusinessLogic.BusinessLogic -{ - public class EmployeeReportLogic : IEmployeeReportLogic - { - private readonly IPCStorage _pcStorage; - private readonly IProductStorage _productStorage; - private readonly IConsignmentStorage _consignmentStorage; - private readonly IRequestStorage _requestStorage; - - public EmployeeReportLogic(IPCStorage pcStorage, IProductStorage productStorage, IConsignmentStorage consignmentStorage, IRequestStorage requestStorage) - { - _pcStorage = pcStorage; - _productStorage = productStorage; - _consignmentStorage = consignmentStorage; - _requestStorage = requestStorage; - } - - public List GetPCs() - { - var pcs = _pcStorage.GetFullList(); - var list = new List(); - var requests = _requestStorage.GetFullList(); - foreach (var pc in pcs) - { - var record = new ReportRequestComponentViewModel - { - PCName = pc.Name, - Components = new List<(string Component, int count)>(), - //Request = requests.Where(x => x.RequestProduct.First(y => y.ID == pc.ID)).Select(x => x.ID) - }; - - - foreach (var component in pc.PCComponents) - { - record.Components.Add(new(component.Value.Item1.Name, component.Value.Item2)); - } - list.Add(record); - } - return list; - } - - public List GetProducts() - { - var products = _productStorage.GetFullList(); - var list = new List(); - var consignments = _consignmentStorage.GetFullList(); - - - foreach (var product in products) - { - var record = new ReportProductComponentViewModel - { - ProductName = product.Name, - Components = new List<(string Component, int count)>(), - Consignments = new List(), - TotalAmount = 0 - }; - - foreach (var consignment in consignments) - { - //record.Consignments.Add(consignment.ConsignmentProducts.FirstOrDefault(x => x.ID == product.ID).Select(x => x.ID)); - } - - foreach (var component in product.ProductComponents) - { - record.Components.Add(new(component.Value.Item1.Name, component.Value.Item2)); - } - record.TotalAmount = record.Consignments.Count; - list.Add(record); - } - - - return list; - } - - public void SaveProductsToExcelFile(ReportBindingModel model) - { - //will be implemented in the future! - } - - public void SavePCsToExcelFile(ReportBindingModel model) - { - //will be implemented in the future! - } - } -} diff --git a/ComputerStoreContracts/BusinessLogicContracts/IEmployeeReportByDateLogic.cs b/ComputerStoreContracts/BusinessLogicContracts/IEmployeeReportByDateLogic.cs new file mode 100644 index 0000000..70a1288 --- /dev/null +++ b/ComputerStoreContracts/BusinessLogicContracts/IEmployeeReportByDateLogic.cs @@ -0,0 +1,19 @@ +using ComputerStoreContracts.BindingModels; +using ComputerStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerStoreContracts.BusinessLogicContracts +{ + public interface IEmployeeReportByDateLogic + { + List GetProducts(ReportBindingModel model); + List GetPCs(ReportBindingModel model); + + void SaveProductsToPdfFile(ReportBindingModel model); + void SavePCsToPdfFile(ReportBindingModel model); + } +} diff --git a/ComputerStoreContracts/BusinessLogicContracts/IEmployeeReportLogic.cs b/ComputerStoreContracts/BusinessLogicContracts/IEmployeeReportLogic.cs deleted file mode 100644 index 375539e..0000000 --- a/ComputerStoreContracts/BusinessLogicContracts/IEmployeeReportLogic.cs +++ /dev/null @@ -1,19 +0,0 @@ -using ComputerStoreContracts.BindingModels; -using ComputerStoreContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputerStoreContracts.BusinessLogicContracts -{ - public interface IEmployeeReportLogic - { - List GetProducts(); - List GetPCs(); - - void SaveProductsToExcelFile(ReportBindingModel model); - void SavePCsToExcelFile(ReportBindingModel model); - } -} diff --git a/ComputerStoreContracts/SearchModels/PCSearchModel.cs b/ComputerStoreContracts/SearchModels/PCSearchModel.cs index 3599813..46a4386 100644 --- a/ComputerStoreContracts/SearchModels/PCSearchModel.cs +++ b/ComputerStoreContracts/SearchModels/PCSearchModel.cs @@ -11,6 +11,8 @@ namespace ComputerStoreContracts.SearchModels public int? ID { get; set; } public string? Name { get; set; } public int? RequestID { get; set; } - public int? EmployeeID { get; set; } + public int? EmployeeID { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set;} } } diff --git a/ComputerStoreContracts/SearchModels/ProductSearchModel.cs b/ComputerStoreContracts/SearchModels/ProductSearchModel.cs index 2a78115..a6c0e75 100644 --- a/ComputerStoreContracts/SearchModels/ProductSearchModel.cs +++ b/ComputerStoreContracts/SearchModels/ProductSearchModel.cs @@ -11,5 +11,7 @@ namespace ComputerStoreContracts.SearchModels public int? ID { get; set; } public string? Name { get; set; } public int? EmployeeID { get; set; } + public DateTime? DateTo { get; set; } + public DateTime? DateFrom { get; set; } } } diff --git a/ComputerStoreContracts/ViewModels/ReportRequestComponentViewModel.cs b/ComputerStoreContracts/ViewModels/ReportPCByDateViewModel.cs similarity index 72% rename from ComputerStoreContracts/ViewModels/ReportRequestComponentViewModel.cs rename to ComputerStoreContracts/ViewModels/ReportPCByDateViewModel.cs index d5b8266..50b0876 100644 --- a/ComputerStoreContracts/ViewModels/ReportRequestComponentViewModel.cs +++ b/ComputerStoreContracts/ViewModels/ReportPCByDateViewModel.cs @@ -6,11 +6,11 @@ using System.Threading.Tasks; namespace ComputerStoreContracts.ViewModels { - public class ReportRequestComponentViewModel + public class ReportPCByDateViewModel { public string PCName { get; set; } = string.Empty; - public int TotalAmount { get; set; } public List<(string Component, int count)> Components { get; set; } = new List<(string Component, int count)> (); - public int Request { get; set; } + + public string EmployeeUsername { get; set; } = string.Empty; } } diff --git a/ComputerStoreContracts/ViewModels/ReportProductComponentViewModel.cs b/ComputerStoreContracts/ViewModels/ReportProductByDateViewModel.cs similarity index 68% rename from ComputerStoreContracts/ViewModels/ReportProductComponentViewModel.cs rename to ComputerStoreContracts/ViewModels/ReportProductByDateViewModel.cs index 10d16f5..79d329d 100644 --- a/ComputerStoreContracts/ViewModels/ReportProductComponentViewModel.cs +++ b/ComputerStoreContracts/ViewModels/ReportProductByDateViewModel.cs @@ -6,12 +6,9 @@ using System.Threading.Tasks; namespace ComputerStoreContracts.ViewModels { - public class ReportProductComponentViewModel + public class ReportProductByDateViewModel { public string ProductName { get; set; } = string.Empty; - public int TotalAmount { get; set; } public List<(string Component, int count)> Components { get; set; } = new List<(string Component, int count)>(); - - public List Consignments { get; set; } = new List(); } } diff --git a/ComputerStoreDataModels/Models/IComponentModel.cs b/ComputerStoreDataModels/Models/IComponentModel.cs index 452edc2..6a60baf 100644 --- a/ComputerStoreDataModels/Models/IComponentModel.cs +++ b/ComputerStoreDataModels/Models/IComponentModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,6 +9,7 @@ namespace ComputerStoreDataModels.Models { public interface IComponentModel : IID { + [MaxLength(255)] string Name { get;} double Price { get;} } diff --git a/ComputerStoreDataModels/Models/IEmployeeModel.cs b/ComputerStoreDataModels/Models/IEmployeeModel.cs index 834a9af..8415399 100644 --- a/ComputerStoreDataModels/Models/IEmployeeModel.cs +++ b/ComputerStoreDataModels/Models/IEmployeeModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,10 +9,15 @@ namespace ComputerStoreDataModels.Models { public interface IEmployeeModel : IID { - string Username { get; } - string Password { get; } - string? FirstName { get; } - string? LastName { get; } + [MaxLength(15)] + string Username { get; } + [MaxLength(20)] + string Password { get; } + [MaxLength(255)] + string? FirstName { get; } + [MaxLength(255)] + string? LastName { get; } + [MaxLength(255)] string? MiddleName { get; } } } diff --git a/ComputerStoreDataModels/Models/IPCModel.cs b/ComputerStoreDataModels/Models/IPCModel.cs index 390e344..1542d14 100644 --- a/ComputerStoreDataModels/Models/IPCModel.cs +++ b/ComputerStoreDataModels/Models/IPCModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,6 +9,7 @@ namespace ComputerStoreDataModels.Models { public interface IPCModel : IID { + [MaxLength(255)] public string Name { get; } public double Price { get; } public int EmployeeID { get; } diff --git a/ComputerStoreDatabaseImplement/Implements/PCStorage.cs b/ComputerStoreDatabaseImplement/Implements/PCStorage.cs index 05c3060..1184a85 100644 --- a/ComputerStoreDatabaseImplement/Implements/PCStorage.cs +++ b/ComputerStoreDatabaseImplement/Implements/PCStorage.cs @@ -26,16 +26,17 @@ namespace ComputerStoreDatabaseImplement.Implements public List GetFilteredList(PCSearchModel model) { - if (string.IsNullOrEmpty(model.Name) && !model.EmployeeID.HasValue) + if (string.IsNullOrEmpty(model.Name) && !model.EmployeeID.HasValue && !model.ID.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) { return new(); } using var context = new ComputerStoreDatabase(); + if(model.EmployeeID.HasValue) { return context.PCs.Include(x => x.Employee).Where(x => x.EmployeeID == model.EmployeeID).Select(x => x.GetViewModel).ToList(); } - return context.PCs.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.ID == model.ID).ToList().Select(x => x.GetViewModel).ToList(); + return context.PCs.Include(x => x.Components).ThenInclude(x => x.Component).Where(p => p.RequestID == context.Requests.First(r => r.OrderID == context.Orders.First(o => o.DateCreate >= model.DateFrom && o.DateImplement <= model.DateTo ).ID).ID).ToList().Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/ComputerStoreDatabaseImplement/Implements/ProductStorage.cs b/ComputerStoreDatabaseImplement/Implements/ProductStorage.cs index 82b04b5..5b422e8 100644 --- a/ComputerStoreDatabaseImplement/Implements/ProductStorage.cs +++ b/ComputerStoreDatabaseImplement/Implements/ProductStorage.cs @@ -14,18 +14,17 @@ namespace ComputerStoreDatabaseImplement.Implements { public class ProductStorage : IProductStorage { - public ProductViewModel? GetElement(ProductSearchModel model) { if(string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) { return null; } using var context = new ComputerStoreDatabase(); - return context.Products.Include(x => x.Employee).Include(x => x.Components).ThenInclude(x => x.Component).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && model.Name.Equals(x.Name)) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel; + return context.Products.Include(x => x.Components).ThenInclude(x => x.Component).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && model.Name.Equals(x.Name)) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel; } public List GetFilteredList(ProductSearchModel model) { - if(string.IsNullOrEmpty(model.Name) && !model.EmployeeID.HasValue) + if(string.IsNullOrEmpty(model.Name) && !model.EmployeeID.HasValue && !model.DateTo.HasValue && !model.DateFrom.HasValue) { return new(); } @@ -35,7 +34,7 @@ namespace ComputerStoreDatabaseImplement.Implements { return context.Products.Include(x => x.Employee).Where(x => x.EmployeeID == model.EmployeeID).Select(x => x.GetViewModel).ToList(); } - return context.Products.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.ID ==model.ID).ToList().Select(x => x.GetViewModel).ToList(); + return context.Products.Include(x => x.Components).ThenInclude(x => x.Component).Where(p => p.ID == context.Consignments.First(r => r.OrderID == context.Orders.First(o => o.DateCreate >= model.DateFrom && o.DateImplement <= model.DateTo).ID).ID).ToList().Select(x => x.GetViewModel).ToList(); } public List GetFullList() @@ -54,8 +53,6 @@ namespace ComputerStoreDatabaseImplement.Implements context.Products.Add(newProduct); context.SaveChanges(); return newProduct.GetViewModel; - - } public ProductViewModel? Update(ProductBindingModel model)