Guarantor: ViewModels / Database storages fixes +ReportLogic and following implementation were created.
This commit is contained in:
parent
81673b0767
commit
a31e821be3
78
ComputerStoreBusinessLogic/BusinessLogic/ReportLogic.cs
Normal file
78
ComputerStoreBusinessLogic/BusinessLogic/ReportLogic.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using ComputerStoreContracts.BindingModels;
|
||||||
|
using ComputerStoreContracts.BusinessLogicContracts;
|
||||||
|
using ComputerStoreContracts.StorageContracts;
|
||||||
|
using ComputerStoreContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerStoreBusinessLogic.BusinessLogic
|
||||||
|
{
|
||||||
|
public class ReportLogic : IReportLogic
|
||||||
|
{
|
||||||
|
private readonly IPCStorage _pcStorage;
|
||||||
|
private readonly IProductStorage _productStorage;
|
||||||
|
|
||||||
|
public ReportLogic(IPCStorage pcStorage, IProductStorage productStorage)
|
||||||
|
{
|
||||||
|
_pcStorage = pcStorage;
|
||||||
|
_productStorage = productStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReportRequestComponentViewModel> GetPCs()
|
||||||
|
{
|
||||||
|
var pcs = _pcStorage.GetFullList();
|
||||||
|
var list = new List<ReportRequestComponentViewModel>();
|
||||||
|
foreach (var pc in pcs)
|
||||||
|
{
|
||||||
|
var record = new ReportRequestComponentViewModel
|
||||||
|
{
|
||||||
|
PCName = pc.Name,
|
||||||
|
Components = new List<(string Component, int count)>(),
|
||||||
|
TotalAmount = 0
|
||||||
|
};
|
||||||
|
foreach (var component in pc.PCComponents)
|
||||||
|
{
|
||||||
|
record.Components.Add(new(component.Value.Item1.Name, component.Value.Item2));
|
||||||
|
record.TotalAmount += component.Value.Item2;
|
||||||
|
}
|
||||||
|
list.Add(record);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReportConsignmentComponentViewModel> GetProducts()
|
||||||
|
{
|
||||||
|
var products = _productStorage.GetFullList();
|
||||||
|
var list = new List<ReportConsignmentComponentViewModel>();
|
||||||
|
foreach (var product in products)
|
||||||
|
{
|
||||||
|
var record = new ReportConsignmentComponentViewModel
|
||||||
|
{
|
||||||
|
ProductName = product.Name,
|
||||||
|
Components = new List<(string Component, int count)>(),
|
||||||
|
TotalAmount = 0
|
||||||
|
};
|
||||||
|
foreach (var component in product.ProductComponents)
|
||||||
|
{
|
||||||
|
record.Components.Add(new(component.Value.Item1.Name, component.Value.Item2));
|
||||||
|
record.TotalAmount += component.Value.Item2;
|
||||||
|
}
|
||||||
|
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!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
ComputerStoreContracts/BindingModels/ReportBindingModel.cs
Normal file
15
ComputerStoreContracts/BindingModels/ReportBindingModel.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerStoreContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ReportBindingModel
|
||||||
|
{
|
||||||
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
public DateTime? DateFrom { get; set; }
|
||||||
|
public DateTime? DateTo { get; set;}
|
||||||
|
}
|
||||||
|
}
|
@ -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 IReportLogic
|
||||||
|
{
|
||||||
|
List<ReportConsignmentComponentViewModel> GetProducts();
|
||||||
|
List<ReportRequestComponentViewModel> GetPCs();
|
||||||
|
|
||||||
|
void SaveProductsToExcelFile(ReportBindingModel model);
|
||||||
|
void SavePCsToExcelFile(ReportBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -11,5 +11,6 @@ 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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,6 @@ 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? ConsignmentID { get; set; }
|
public int? ConsignmentID { get; set; }
|
||||||
|
public int? EmployeeID { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerStoreContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ReportConsignmentComponentViewModel
|
||||||
|
{
|
||||||
|
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)>();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ComputerStoreContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ReportRequestComponentViewModel
|
||||||
|
{
|
||||||
|
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)> ();
|
||||||
|
}
|
||||||
|
}
|
@ -8,8 +8,8 @@ namespace ComputerStoreDataModels.Models
|
|||||||
{
|
{
|
||||||
public interface IPCModel : IID
|
public interface IPCModel : IID
|
||||||
{
|
{
|
||||||
string Name { get; }
|
public string Name { get; }
|
||||||
double Price { get; }
|
public double Price { get; }
|
||||||
public int EmployeeID { get; }
|
public int EmployeeID { get; }
|
||||||
public int RequestID { get; }
|
public int RequestID { get; }
|
||||||
Dictionary<int,(IComponentModel,int)> PCComponents { get; }
|
Dictionary<int,(IComponentModel,int)> PCComponents { get; }
|
||||||
|
@ -14,7 +14,7 @@ namespace ComputerStoreDatabaseImplement
|
|||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
if (optionsBuilder.IsConfigured == false)
|
||||||
{
|
{
|
||||||
optionsBuilder.UseSqlServer(@"Server=localhost\SQLEXPRESS;Initial Catalog=DressAtelierDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
optionsBuilder.UseSqlServer(@"Server=localhost\SQLEXPRESS;Initial Catalog=ComputerStoreDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
}
|
}
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
@ -20,17 +20,21 @@ namespace ComputerStoreDatabaseImplement.Implements
|
|||||||
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.PCs.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.PCs.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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PCViewModel> GetFilteredList(PCSearchModel model)
|
public List<PCViewModel> GetFilteredList(PCSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.Name))
|
if (string.IsNullOrEmpty(model.Name) && !model.EmployeeID.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new ComputerStoreDatabase();
|
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(x => x.ID == model.ID).ToList().Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,18 +20,22 @@ namespace ComputerStoreDatabaseImplement.Implements
|
|||||||
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.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.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(model.Name))
|
if(string.IsNullOrEmpty(model.Name) && !model.EmployeeID.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new ComputerStoreDatabase();
|
using var context = new ComputerStoreDatabase();
|
||||||
return context.Products.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.ID ==model.ID).Select(x => x.GetViewModel).ToList();
|
if(model.EmployeeID.HasValue)
|
||||||
|
{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProductViewModel> GetFullList()
|
public List<ProductViewModel> GetFullList()
|
||||||
|
Loading…
Reference in New Issue
Block a user