Gaurantor: ReportsByData.

This commit is contained in:
Yuee Shiness 2023-04-09 03:17:58 +04:00
parent 769979a406
commit c9c4bd00aa
13 changed files with 119 additions and 136 deletions

View File

@ -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<ReportPCByDateViewModel> 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<ReportProductByDateViewModel> 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!
}
}
}

View File

@ -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<ReportRequestComponentViewModel> GetPCs()
{
var pcs = _pcStorage.GetFullList();
var list = new List<ReportRequestComponentViewModel>();
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<ReportProductComponentViewModel> GetProducts()
{
var products = _productStorage.GetFullList();
var list = new List<ReportProductComponentViewModel>();
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<int>(),
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!
}
}
}

View File

@ -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<ReportProductByDateViewModel> GetProducts(ReportBindingModel model);
List<ReportPCByDateViewModel> GetPCs(ReportBindingModel model);
void SaveProductsToPdfFile(ReportBindingModel model);
void SavePCsToPdfFile(ReportBindingModel model);
}
}

View File

@ -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<ReportProductComponentViewModel> GetProducts();
List<ReportRequestComponentViewModel> GetPCs();
void SaveProductsToExcelFile(ReportBindingModel model);
void SavePCsToExcelFile(ReportBindingModel model);
}
}

View File

@ -11,6 +11,8 @@ namespace ComputerStoreContracts.SearchModels
public int? ID { get; set; } public int? ID { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public int? RequestID { 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;}
} }
} }

View File

@ -11,5 +11,7 @@ namespace ComputerStoreContracts.SearchModels
public int? ID { get; set; } public int? ID { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public int? EmployeeID { get; set; } public int? EmployeeID { get; set; }
public DateTime? DateTo { get; set; }
public DateTime? DateFrom { get; set; }
} }
} }

View File

@ -6,11 +6,11 @@ using System.Threading.Tasks;
namespace ComputerStoreContracts.ViewModels namespace ComputerStoreContracts.ViewModels
{ {
public class ReportRequestComponentViewModel public class ReportPCByDateViewModel
{ {
public string PCName { get; set; } = string.Empty; 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 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;
} }
} }

View File

@ -6,12 +6,9 @@ using System.Threading.Tasks;
namespace ComputerStoreContracts.ViewModels namespace ComputerStoreContracts.ViewModels
{ {
public class ReportProductComponentViewModel public class ReportProductByDateViewModel
{ {
public string ProductName { get; set; } = string.Empty; 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<(string Component, int count)> Components { get; set; } = new List<(string Component, int count)>();
public List<int> Consignments { get; set; } = new List<int>();
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -8,6 +9,7 @@ namespace ComputerStoreDataModels.Models
{ {
public interface IComponentModel : IID public interface IComponentModel : IID
{ {
[MaxLength(255)]
string Name { get;} string Name { get;}
double Price { get;} double Price { get;}
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -8,10 +9,15 @@ namespace ComputerStoreDataModels.Models
{ {
public interface IEmployeeModel : IID public interface IEmployeeModel : IID
{ {
string Username { get; } [MaxLength(15)]
string Password { get; } string Username { get; }
string? FirstName { get; } [MaxLength(20)]
string? LastName { get; } string Password { get; }
[MaxLength(255)]
string? FirstName { get; }
[MaxLength(255)]
string? LastName { get; }
[MaxLength(255)]
string? MiddleName { get; } string? MiddleName { get; }
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -8,6 +9,7 @@ namespace ComputerStoreDataModels.Models
{ {
public interface IPCModel : IID public interface IPCModel : IID
{ {
[MaxLength(255)]
public string Name { get; } public string Name { get; }
public double Price { get; } public double Price { get; }
public int EmployeeID { get; } public int EmployeeID { get; }

View File

@ -26,16 +26,17 @@ namespace ComputerStoreDatabaseImplement.Implements
public List<PCViewModel> GetFilteredList(PCSearchModel model) public List<PCViewModel> 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(); return new();
} }
using var context = new ComputerStoreDatabase(); using var context = new ComputerStoreDatabase();
if(model.EmployeeID.HasValue) 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.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<PCViewModel> GetFullList() public List<PCViewModel> GetFullList()

View File

@ -14,18 +14,17 @@ namespace ComputerStoreDatabaseImplement.Implements
{ {
public class ProductStorage : IProductStorage public class ProductStorage : IProductStorage
{ {
public ProductViewModel? GetElement(ProductSearchModel model) public ProductViewModel? GetElement(ProductSearchModel model)
{ {
if(string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) { return null; } if(string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) { return null; }
using var context = new ComputerStoreDatabase(); 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<ProductViewModel> GetFilteredList(ProductSearchModel model) public List<ProductViewModel> 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(); 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.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<ProductViewModel> GetFullList() public List<ProductViewModel> GetFullList()
@ -54,8 +53,6 @@ namespace ComputerStoreDatabaseImplement.Implements
context.Products.Add(newProduct); context.Products.Add(newProduct);
context.SaveChanges(); context.SaveChanges();
return newProduct.GetViewModel; return newProduct.GetViewModel;
} }
public ProductViewModel? Update(ProductBindingModel model) public ProductViewModel? Update(ProductBindingModel model)