diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/Purchases.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/Purchases.cshtml
index bbd2655..b45349f 100644
--- a/HardwareShop/HardwareShopClientApp/Views/Worker/Purchases.cshtml
+++ b/HardwareShop/HardwareShopClientApp/Views/Worker/Purchases.cshtml
@@ -24,9 +24,6 @@
Статус
|
-
- Логин пользователя
- |
diff --git a/HardwareShop/HardwareShopClientApp/Views/Worker/listComponents.cshtml b/HardwareShop/HardwareShopClientApp/Views/Worker/listComponents.cshtml
index e296558..34055ca 100644
--- a/HardwareShop/HardwareShopClientApp/Views/Worker/listComponents.cshtml
+++ b/HardwareShop/HardwareShopClientApp/Views/Worker/listComponents.cshtml
@@ -24,9 +24,6 @@
Статус
|
-
- Логин пользователя
- |
diff --git a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs
index d373725..40a72b5 100644
--- a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs
+++ b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs
@@ -13,5 +13,7 @@ namespace HardwareShopContracts.BindingModels
public int UserId { get; set; }
public Dictionary BuildPurchases { get; set; } = new();
+
+ public Dictionary BuildComponents { get; set; } = new();
}
}
diff --git a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs
index ccaaf61..3a52f0f 100644
--- a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs
+++ b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs
@@ -16,5 +16,7 @@ namespace HardwareShopContracts.BindingModels
public int UserId { get; set; }
public Dictionary PurchaseGoods { get; set; } = new();
+
+ public Dictionary PurchaseBuilds { get; set; } = new();
}
}
diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IWorkerReportLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IWorkerReportLogic.cs
new file mode 100644
index 0000000..9702d5d
--- /dev/null
+++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IWorkerReportLogic.cs
@@ -0,0 +1,40 @@
+
+using HardwareShopContracts.BindingModels;
+using HardwareShopContracts.ViewModels;
+
+namespace HardwareShopContracts.BusinessLogicsContracts
+{
+ public interface IWorkerReportLogic
+ {
+ ///
+ /// Получение списка компонент с указанием, в каких покупках используются
+ ///
+ ///
+ List GetPurchaseComponent(List purchaseList);
+
+ ///
+ /// Получение списка покупок за определенный период
+ ///
+ ///
+ ///
+ List GetPurchase(ReportBindingModel model);
+
+ ///
+ /// Сохранение компонент с указаеним покупок в файл-Word
+ ///
+ ///
+ void SaveComponentsToWordFile(ReportBindingModel model);
+
+ ///
+ /// Сохранение компонент с указаеним покупок в файл-Excel
+ ///
+ ///
+ void SaveDishComponentToExcelFile(ReportBindingModel model);
+
+ ///
+ /// Сохранение отчёта по покупкам в файл-Pdf
+ ///
+ ///
+ void SaveOrdersToPdfFile(ReportBindingModel model);
+ }
+}
\ No newline at end of file
diff --git a/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs
index e4caf9b..00897a1 100644
--- a/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs
+++ b/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs
@@ -1,4 +1,5 @@
+using HardwareShopDataModels.Enums;
using System.ComponentModel;
namespace HardwareShopContracts.SearchModels
{
@@ -8,7 +9,10 @@ namespace HardwareShopContracts.SearchModels
public int? UserId { get; set; }
- public DateTime? DatePurchase { get; set; }
+ public PurchaseStatus? PurchaseStatus { get; set; }
+
+ public DateTime? DateFrom { get; set; }
+
public DateTime? DateTo { get; set; }
}
}
diff --git a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs
index cea63fe..b30b0fd 100644
--- a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs
+++ b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs
@@ -12,12 +12,10 @@ namespace HardwareShopContracts.ViewModels
[DisplayName("Название Сборки")]
public string BuildName { get; set; } = string.Empty;
- [DisplayName("Логин пользователя")]
- public string UserLogin { get; set; } = string.Empty;
-
public int UserId { get; set; }
public Dictionary BuildPurchases { get; set; } = new();
+ public Dictionary BuildComponents { get; set; } = new();
}
}
diff --git a/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs
index 6620922..0bcadd6 100644
--- a/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs
+++ b/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs
@@ -16,8 +16,5 @@ namespace HardwareShopContracts.ViewModels
public int BuildId { get; set; }
public int UserId { get; set; }
-
- [DisplayName("Логин пользователя")]
- public string UserLogin { get; set; } = string.Empty;
}
}
diff --git a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs
index ee1be3b..6a16837 100644
--- a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs
+++ b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs
@@ -18,9 +18,8 @@ namespace HardwareShopContracts.ViewModels
public int UserId { get; set; }
- [DisplayName("Логин пользователя")]
- public string UserLogin { get; set; } = string.Empty;
-
public Dictionary PurchaseGoods { get; set; } = new();
+
+ public Dictionary PurchaseBuilds { get; set; } = new();
}
}
diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs
new file mode 100644
index 0000000..1e8661f
--- /dev/null
+++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HardwareShopContracts.ViewModels
+{
+ public class ReportPurchaseComponentViewModel
+ {
+ public int Id { get; set; }
+
+ public List<(string Build, int count, List<(string Component, int count)>)> Builds { get; set; } = new();
+
+ public List<(string Good, int count, List<(string Component, int count)>)> Goods { get; set; } = new();
+
+ public int TotalCount { get; set; }
+
+ public int TotalCost { get; set; }
+
+
+ }
+}
diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs
new file mode 100644
index 0000000..ec1fb2f
--- /dev/null
+++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace HardwareShopContracts.ViewModels
+{
+ public class ReportPurchaseViewModel
+ {
+ public int Id { get; set; }
+
+ public List<(string Build, int count, List, List<(string Component, int count)>)> Builds { get; set; } = new();
+ }
+}
diff --git a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs
index 3e57d64..0327a66 100644
--- a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs
+++ b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs
@@ -16,5 +16,9 @@ namespace HardwareShopDataModels.Models
int UserId { get; }
Dictionary BuildPurchases { get; }
+
+ Dictionary BuildComponents { get; }
+
+ Dictionary BuildComments { get; }
}
}
diff --git a/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs b/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs
index 7897562..34c055c 100644
--- a/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs
+++ b/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs
@@ -12,6 +12,6 @@ namespace HardwareShopDataModels.Models
int BuildId { get; }
- int UserId { get; }
+ int UserId { get; }
}
}
diff --git a/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs b/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs
index 91420cf..a0dbcda 100644
--- a/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs
+++ b/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs
@@ -13,5 +13,7 @@ namespace HardwareShopDataModels.Models
int UserId { get; }
Dictionary PurchaseGoods { get; }
+
+ Dictionary PurchaseBuilds { get; }
}
}
diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs
index cd6992f..34e12c6 100644
--- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs
+++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs
@@ -15,7 +15,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
- .Include(x => x.User)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
@@ -57,7 +56,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
- .Include(x => x.User)
.Where(x => x.Id == model.Id)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) ||
(model.Id.HasValue && x.Id == model.Id))
@@ -77,7 +75,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
- .Include(x => x.User)
.Where(x => x.UserId == model.Id)
.FirstOrDefault(x => x.Id == newBuild.Id)
?.GetViewModel;
@@ -92,7 +89,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var build = context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
- .Include(x => x.User)
.Where(x => x.UserId == model.UserId)
.FirstOrDefault(x => x.Id == model.Id);
if (build == null)
@@ -118,7 +114,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var element = context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
- .Include(x => x.User)
.Where(x => x.UserId == model.Id)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/CommentStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/CommentStorage.cs
index 9812184..cf3df50 100644
--- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/CommentStorage.cs
+++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/CommentStorage.cs
@@ -14,7 +14,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase();
return context.Comments
.Include(x => x.Build)
- .Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
@@ -30,14 +29,12 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
{
return context.Comments
.Include(x => x.Build)
- .Include(x => x.User)
.Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Comments
.Include(x => x.Build)
- .Include(x => x.User)
.Where(x => x.BuildId == model.BuildId)
.Select(x => x.GetViewModel)
.ToList();
@@ -52,7 +49,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase();
return context.Comments
.Include(x => x.Build)
- .Include(x => x.User)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
@@ -75,7 +71,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase();
var comment = context.Comments
.Include(x => x.Build)
- .Include(x => x.User)
.FirstOrDefault(x => x.Id == model.Id);
if (comment == null)
{
@@ -91,7 +86,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase();
var element = context.Comments
.Include(x => x.Build)
- .Include(x => x.User)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs
index cee197b..055bce1 100644
--- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs
+++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs
@@ -17,7 +17,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
- .Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
}
@@ -25,16 +24,20 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List GetFilteredList(PurchaseSearchModel model)
{
using var context = new HardwareShopDatabase();
- if (!model.UserId.HasValue && !model.DatePurchase.HasValue)
+ if (!model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
- return new();
+ return context.Purchases
+ .Include(x => x.Goods)
+ .ThenInclude(x => x.Good)
+ .Where(x => x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo)
+ .Select(x => x.GetViewModel)
+ .ToList();
}
if (model.UserId.HasValue)
{
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
- .Include(x => x.User)
.Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel)
.ToList();
@@ -42,8 +45,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
- .Include(x => x.User)
- .Where(x => x.DatePurchase == model.DatePurchase)
+ .Where(x => x.PurchaseStatus == model.PurchaseStatus)
.Select(x => x.GetViewModel)
.ToList();
}
@@ -58,7 +60,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
- .Include(x => x.User)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
@@ -76,7 +77,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
- .Include(x => x.User)
.FirstOrDefault(x => x.Id == newPurchase.Id)
?.GetViewModel;
}
@@ -90,7 +90,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var purchase = context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
- .Include(x => x.User)
.FirstOrDefault(x => x.Id == model.Id);
if (purchase == null)
{
@@ -115,7 +114,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var element = context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
- .Include(x => x.User)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs
index a319b23..8efd262 100644
--- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs
+++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs
@@ -33,7 +33,37 @@ namespace HardwareShopDatabaseImplement.Models.Worker
[ForeignKey("BuildId")]
public virtual List Purchases { get; set; } = new();
- public Dictionary? _buildPurchases = null;
+ private Dictionary _buildComments = null;
+
+ [NotMapped]
+ public Dictionary BuildComments
+ {
+ get
+ {
+ if (_buildComments == null)
+ {
+ _buildComments = Comments.ToDictionary(recBC=> recBC.Id, recBC => recBC as ICommentModel);
+ }
+ return _buildComments;
+ }
+ }
+
+ private Dictionary? _buildComponents = null;
+
+ [NotMapped]
+ public Dictionary BuildComponents
+ {
+ get
+ {
+ if (_buildComponents == null)
+ {
+ _buildComponents = Components.ToDictionary(recBC => recBC.ComponentId, recBC => (recBC.Component as IComponentModel, recBC.Count));
+ }
+ return _buildComponents;
+ }
+ }
+
+ private Dictionary? _buildPurchases = null;
[NotMapped]
public Dictionary BuildPurchases
@@ -70,7 +100,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
Id = Id,
BuildName = BuildName,
Price = Price,
- UserLogin = User.Login,
UserId = UserId,
BuildPurchases = BuildPurchases,
};
@@ -91,7 +120,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
context.SaveChanges();
}
var build = context.Builds.First(x => x.Id == Id);
- //добавляем в бд элементы которые есть в модели, но ещё нет в бд
+ //добавляем в бд сборки которые есть в модели, но ещё нет в бд
foreach (var bp in model.BuildPurchases)
{
context.PurchasesBuilds.Add(new PurchaseBuild
@@ -117,7 +146,5 @@ namespace HardwareShopDatabaseImplement.Models.Worker
var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
}
-
-
}
}
diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs
index 64b74b6..cd529a9 100644
--- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs
+++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs
@@ -52,7 +52,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
BuildId = BuildId,
BuildName = Build.BuildName,
UserId = UserId,
- UserLogin = User.Login,
};
}
}
diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs
index 35a163f..352f3e1 100644
--- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs
+++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs
@@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
[ForeignKey("PurchaseId")]
public virtual List Goods { get; set; } = new();
- public Dictionary? _purchaseGoods = null;
+ private Dictionary? _purchaseGoods = null;
[NotMapped]
public Dictionary PurchaseGoods
@@ -47,6 +47,21 @@ namespace HardwareShopDatabaseImplement.Models.Worker
}
}
+ private Dictionary? _purchaseBuilds = null;
+
+ [NotMapped]
+ public Dictionary PurchaseBuilds
+ {
+ get
+ {
+ if (_purchaseBuilds == null)
+ {
+ _purchaseBuilds = Builds.ToDictionary(recPG => recPG.BuildId, recPG => (recPG.Build as IBuildModel, recPG.Count));
+ }
+ return _purchaseBuilds;
+ }
+ }
+
public static Purchase Create(HardwareShopDatabase context, PurchaseBindingModel model)
{
return new Purchase()
@@ -78,7 +93,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
PurchaseStatus = PurchaseStatus,
DatePurchase = DatePurchase,
UserId = UserId,
- UserLogin = User.Login,
PurchaseGoods = PurchaseGoods
};
@@ -98,7 +112,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
context.SaveChanges();
}
var purchase = context.Purchases.First(x => x.Id == Id);
- //добавляем в бд блюда которые есть в моделе, но ещё нет в бд
+ //добавляем в бд товары которые есть в моделе, но ещё нет в бд
foreach (var dc in model.PurchaseGoods)
{
context.PurchasesGoods.Add(new PurchaseGood