diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderInfoLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderInfoLogic.cs index 85cec77..e9fbe65 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderInfoLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderInfoLogic.cs @@ -49,15 +49,16 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } - public bool Create(OrderInfoBindingModel model) + public OrderInfoViewModel? Create(OrderInfoBindingModel model) { CheckModel(model); - if (_orderInfoStorage.Insert(model) == null) + var order = _orderInfoStorage.Insert(model); + if (order == null) { _logger.LogWarning("Insert operation failed"); - return false; + return null; } - return true; + return order; } public bool Update(OrderInfoBindingModel model) { diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderLogic.cs index 911a9fc..98d5ddd 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderLogic.cs @@ -16,10 +16,14 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IOrderInfoStorage _orderInfoStorage; + private readonly ISetStorage _setStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IOrderInfoStorage orderInfoStorage, ISetStorage setStorage) { _logger = logger; _orderStorage = orderStorage; + _orderInfoStorage = orderInfoStorage; + _setStorage = setStorage; } public List? ReadList(OrderSearchModel? model) { @@ -52,7 +56,41 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics public bool Create(OrderBindingModel model) { CheckModel(model); - if (_orderStorage.Insert(model) == null) + var orderInfo = _orderInfoStorage.GetElement(new OrderInfoSearchModel { Id = model.OrderInfoId }); + var set = _setStorage.GetElement(new SetSearchModel { Id = model.SetId }); + if (orderInfo == null || set == null) + { + return false; + } + _orderInfoStorage.Update(new OrderInfoBindingModel + { + Id = orderInfo.Id, + CustomerName = orderInfo.CustomerName, + Sum = orderInfo.Sum + (set.Cost * model.Count), + DateCreate = orderInfo.DateCreate, + PaymentType = orderInfo.PaymentType, + UserId = orderInfo.UserId + }); + var order = _orderStorage.GetElement(new OrderSearchModel + { + OrderInfoId = new List { model.OrderInfoId }, + SetId = model.SetId + }); + if (order != null) + { + if (_orderStorage.Update(new OrderBindingModel + { + Id = order.Id, + OrderInfoId = order.OrderInfoId, + SetId = order.SetId, + Count = order.Count + model.Count + }) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + } + else if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -72,7 +110,23 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics public bool Delete(OrderBindingModel model) { CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + var orderInfo = _orderInfoStorage.GetElement(new OrderInfoSearchModel { Id = order.OrderInfoId }); + var set = _setStorage.GetElement(new SetSearchModel { Id = order.SetId }); + if (orderInfo == null || set == null) + { + return false; + } + _orderInfoStorage.Update(new OrderInfoBindingModel + { + Id = orderInfo.Id, + CustomerName = orderInfo.CustomerName, + Sum = orderInfo.Sum - (set.Cost * order.Count), + DateCreate = orderInfo.DateCreate, + PaymentType = orderInfo.PaymentType, + UserId = orderInfo.UserId + }); + _logger.LogInformation("Delete. Id:{Id}", model.Id); if (_orderStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportWorkerLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportWorkerLogic.cs index f285943..c3e826c 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportWorkerLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportWorkerLogic.cs @@ -19,11 +19,11 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics private readonly ISetStorage _setStorage; private readonly IOrderInfoStorage _orderInfoStorage; private readonly IOrderStorage _orderStorage; - private readonly AbstractSaveToExcel _saveToExcel; - private readonly AbstractSaveToWord _saveToWord; - private readonly AbstractSaveToPdf _saveToPdf; + private readonly AbstractWorkerSaveToExcel _saveToExcel; + private readonly AbstractWorkerSaveToWord _saveToWord; + private readonly AbstractWorkerSaveToPdf _saveToPdf; public ReportWorkerLogic(ISetStorage setStorage, IFurnitureModuleStorage furnitureModuleStorage, IOrderInfoStorage orderInfoStorage, - IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + IOrderStorage orderStorage, AbstractWorkerSaveToExcel saveToExcel, AbstractWorkerSaveToWord saveToWord, AbstractWorkerSaveToPdf saveToPdf) { _setStorage = setStorage; _furnitureModuleStorage = furnitureModuleStorage; diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToExcel.cs similarity index 98% rename from FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToExcel.cs rename to FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToExcel.cs index bf29ce9..9f2bb99 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToExcel.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyBusinessLogic.OfficePackage { - public abstract class AbstractSaveToExcel + public abstract class AbstractWorkerSaveToExcel { /// /// Создание отчета diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToPdf.cs similarity index 98% rename from FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToPdf.cs rename to FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToPdf.cs index ae54b56..19b9597 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToPdf.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyBusinessLogic.OfficePackage { - public abstract class AbstractSaveToPdf + public abstract class AbstractWorkerSaveToPdf { public void CreateDoc(PdfInfo info) { diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToWord.cs similarity index 98% rename from FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs rename to FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToWord.cs index 6a2bdb5..06d63a1 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractWorkerSaveToWord.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyBusinessLogic.OfficePackage { - public abstract class AbstractSaveToWord + public abstract class AbstractWorkerSaveToWord { public void CreateDoc(WordInfo info) { diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index ab96e3d..6496ff8 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -13,7 +13,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements { - public class SaveToExcel : AbstractSaveToExcel + public class SaveToExcel : AbstractWorkerSaveToExcel { private SpreadsheetDocument? _spreadsheetDocument; private SharedStringTablePart? _shareStringPart; diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index b78be40..67f9825 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements { - public class SaveToPdf : AbstractSaveToPdf + public class SaveToPdf : AbstractWorkerSaveToPdf { private Document? _document; private Section? _section; diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs index dad3b35..eb0fa7e 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements { - public class SaveToWord : AbstractSaveToWord + public class SaveToWord : AbstractWorkerSaveToWord { private WordprocessingDocument? _wordDocument; private Body? _docBody; diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IOrderInfoLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IOrderInfoLogic.cs index ba415a3..d281648 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IOrderInfoLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IOrderInfoLogic.cs @@ -13,7 +13,7 @@ namespace FurnitureAssemblyContracts.BusinessLogicContracts { List? ReadList(OrderInfoSearchModel? model); OrderInfoViewModel? ReadElement(OrderInfoSearchModel model); - bool Create(OrderInfoBindingModel model); + OrderInfoViewModel? Create(OrderInfoBindingModel model); bool Update(OrderInfoBindingModel model); bool Delete(OrderInfoBindingModel model); } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs index 6f21ad4..788b1b5 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs @@ -33,16 +33,27 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + using var context = new FurnitureAssemblyDatabase(); + if (model.Id.HasValue) { - return null; - } - using var context = new FurnitureAssemblyDatabase(); - return context.Orders - .Include(x => x.Set) + return context.Orders + .Include(x => x.Set) .Include(x => x.OrderInfo) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; + ?.GetViewModel; + } + else if (model.OrderInfoId != null && model.OrderInfoId.Count == 1 && model.SetId.HasValue) + { + return context.Orders + .Include(x => x.Set) + .Include(x => x.OrderInfo) + .FirstOrDefault(x => model.OrderInfoId.Contains(x.OrderInfoId) && x.SetId == model.SetId) + ?.GetViewModel; + } + else + { + return null; + } } public List GetFilteredList(OrderSearchModel model) { diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs index 92932f0..6b36e56 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs @@ -58,8 +58,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models PaymentType = OrderInfo.PaymentType, DateCreate = OrderInfo.DateCreate, Sum = OrderInfo.Sum, - UserId = OrderInfo.UserId, - UserName = OrderInfo.User.Name + UserId = OrderInfo.UserId }; } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/OrderInfo.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/OrderInfo.cs index 44e2594..d71e1c3 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/OrderInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/OrderInfo.cs @@ -36,7 +36,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models Id = model.Id, CustomerName = model.CustomerName, PaymentType = model.PaymentType, - Sum = model.Sum, + Sum = 0, DateCreate = DateTime.Now.ToUniversalTime(), UserId = model.UserId }; @@ -50,6 +50,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models CustomerName = model.CustomerName; PaymentType = model.PaymentType; UserId = model.UserId; + Sum = model.Sum; } public OrderInfoViewModel GetViewModel => new() { diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/FurnitureModuleController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/FurnitureModuleController.cs index 8b6749d..8af05c3 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/FurnitureModuleController.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/FurnitureModuleController.cs @@ -47,6 +47,19 @@ namespace FurnitureAssemblyRestApi.Controllers throw; } } + [HttpGet] + public List? GetFurnitureModuleListByUser(int userId) + { + try + { + return _furnitureModule.ReadList(new FurnitureModuleSearchModel { UserId = userId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка гарнитуров у пользователя по id={userId}", userId); + throw; + } + } [HttpPost] public void AddFurnitureModule(FurnitureModuleBindingModel model) { diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/OrderController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/OrderController.cs index 38526d9..9f45229 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/OrderController.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/OrderController.cs @@ -17,11 +17,16 @@ namespace FurnitureAssemblyRestApi.Controllers private readonly ILogger _logger; private readonly IOrderLogic _order; private readonly IOrderInfoLogic _orderInfo; - public OrderController(ILogger logger, IOrderLogic order, IOrderInfoLogic orderInfo) + private readonly ISetLogic _set; + public OrderController(ILogger logger, + IOrderLogic order, + IOrderInfoLogic orderInfo, + ISetLogic set) { _logger = logger; _order = order; _orderInfo = orderInfo; + _set = set; } [HttpGet] @@ -73,7 +78,45 @@ namespace FurnitureAssemblyRestApi.Controllers throw; } } - [HttpPost] + [HttpGet] + public Tuple, List>? GetOrderWithSets(int orderId) + { + try + { + var orderInfo = _orderInfo.ReadElement(new() { Id = orderId }); + if (orderInfo == null) + { + return null; + } + var orders = _order.ReadList(new OrderSearchModel { OrderInfoId = new List() { orderInfo.Id } }); + var sets = new List(); + var counts = new List(); + if (orders == null) + { + sets = null; + counts = null; + } + else + { + foreach (var order in orders) + { + var el = _set.ReadElement(new SetSearchModel { Id = order.SetId }); + sets.Add(el); + counts.Add(order.Count); + } + } + var tuple = System.Tuple.Create(orderInfo, + sets, + counts); + return tuple; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка гарнитура с мебельными модулями"); + throw; + } + } + [HttpPost] public void AddOrder(OrderBindingModel model) { try @@ -112,5 +155,25 @@ namespace FurnitureAssemblyRestApi.Controllers throw; } } - } + [HttpPost] + public void AddSetInOrder(Tuple orderSetWithCount) + { + try + { + var orderInfo = _orderInfo.ReadElement(orderSetWithCount.Item1); + var set = _set.ReadElement(orderSetWithCount.Item2); + _order.Create(new OrderBindingModel + { + OrderInfoId = orderInfo.Id, + SetId = set.Id, + Count = orderSetWithCount.Item3 + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка добавления поездки в магазин"); + throw; + } + } + } } diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/OrderInfoController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/OrderInfoController.cs index eeedf0a..67d037a 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/OrderInfoController.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/OrderInfoController.cs @@ -47,12 +47,25 @@ namespace FurnitureAssemblyRestApi.Controllers throw; } } - [HttpPost] - public void AddOrderInfo(OrderInfoBindingModel model) + [HttpGet] + public List? GetOrderInfoListByUser(int userId) { try { - _orderInfo.Create(model); + return _orderInfo.ReadList(new OrderInfoSearchModel { UserId = userId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка гарнитуров у пользователя по id={userId}", userId); + throw; + } + } + [HttpPost] + public OrderInfoViewModel? AddOrderInfo(OrderInfoBindingModel model) + { + try + { + return _orderInfo.Create(model); } catch (Exception ex) { diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs index ae7f22d..e08d03d 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs @@ -33,9 +33,9 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/APIClient.cs b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/APIClient.cs index 719ba93..1fc3e84 100644 --- a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/APIClient.cs +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/APIClient.cs @@ -29,11 +29,7 @@ namespace FurnitureAssemblyWorkerClientApp throw new Exception(result); } } - public static void GetBaseRequest(string requestUrl) - { - var response = _client.GetAsync(requestUrl); - } - public static void PostRequest(string requestUrl, T model) + public static T? PostRequest(string requestUrl, T model) { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, Encoding.UTF8, "application/json"); @@ -41,7 +37,10 @@ namespace FurnitureAssemblyWorkerClientApp var response = _client.PostAsync(requestUrl, data); var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } else { throw new Exception(result); } diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Controllers/HomeController.cs b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Controllers/HomeController.cs index e83e602..4b084b3 100644 --- a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Controllers/HomeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Controllers/HomeController.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using FurnitureAssemblyDataModels.Models; using System; using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyDataModels.Enums; namespace FurnitureAssemblyWorkerClientApp.Controllers { @@ -160,7 +161,7 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers furnitureModuleTable += ""; furnitureModuleTable += $"{furnitureModule.Name}"; furnitureModuleTable += $"{furnitureModule.Cost}"; - furnitureModuleTable += $"{furnitureModule.DateCreate}"; + furnitureModuleTable += $"{furnitureModule.DateCreate.Date}"; furnitureModuleTable += $"{count}"; furnitureModuleTable += ""; } @@ -173,7 +174,7 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/set/getsetlist")); + return View(APIClient.GetRequest>($"api/set/getsetlistbyuser?userId={APIClient.User.Id}")); } [HttpPost] public void UpdateSet(int set, string name, double cost, DateTime dateCreate) @@ -208,7 +209,7 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/set/getsetlist")); + return View(APIClient.GetRequest>($"api/set/getsetlistbyuser?userId={APIClient.User.Id}")); } [HttpPost] public void DeleteSet(int set) @@ -230,7 +231,7 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers { return Redirect("~/Home/Enter"); } - return View(Tuple.Create(APIClient.GetRequest>("api/set/getsetlist"), APIClient.GetRequest>("api/furnituremodule/getfurnituremodulelist"))); + return View(Tuple.Create(APIClient.GetRequest>($"api/set/getsetlistbyuser?userId={APIClient.User.Id}"), APIClient.GetRequest>($"api/furnituremodule/getfurnituremodulelistbyuser?userId={APIClient.User.Id}"))); } [HttpPost] public void AddFurnitureModuleInSet(int set, int furnitureModule, int count) @@ -257,7 +258,7 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/set/getsetlist")); + return View(APIClient.GetRequest>($"api/set/getsetlistbyuser?userId={APIClient.User.Id}")); } [HttpPost] public void ListSetsFurnitureModulesToFile(int[] setIds, string type) @@ -306,5 +307,301 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers { return new PhysicalFileResult("C:\\temp\\excel_worker.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); } - } + [HttpGet] + public IActionResult FurnitureModules() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/furnituremodule/getfurnituremodulelistbyuser?userId={APIClient.User.Id}")); + } + [HttpGet] + public IActionResult CreateFurnitureModule() + { + return View(); + } + [HttpPost] + public void CreateFurnitureModule(string name, double cost) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название мебельного модуля не указано"); + } + if (cost <= 0) + { + throw new Exception("Стоимость мебельного модуля не корректна"); + } + APIClient.PostRequest("api/furnituremodule/addfurnituremodule", new FurnitureModuleBindingModel + { + Name = name, + Cost = cost, + UserId = APIClient.User.Id + }); + Response.Redirect("FurnitureModules"); + } + [HttpGet] + public IActionResult UpdateFurnitureModule() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/furnituremodule/getfurnituremodulelistbyuser?userId={APIClient.User.Id}")); + } + [HttpPost] + public void UpdateFurnitureModule(int furnitureModule, string name, double cost, DateTime dateCreate) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название мебельного модуля не указано"); + } + if (cost <= 0) + { + throw new Exception("Стоимость мебельного модуля не корректна"); + } + APIClient.PostRequest("api/furnituremodule/updatefurnituremodule", new FurnitureModuleBindingModel + { + Id = furnitureModule, + Name = name, + Cost = cost, + DateCreate = dateCreate.Date + }); + Response.Redirect("FurnitureModules"); + } + [HttpGet] + public IActionResult DeleteFurnitureModule() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/furnituremodule/getfurnituremodulelistbyuser?userId={APIClient.User.Id}")); + } + [HttpPost] + public void DeleteFurnitureModule(int furnitureModule) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/furnituremodule/deletefurnituremodule", new FurnitureModuleBindingModel + { + Id = furnitureModule, + }); + Response.Redirect("FurnitureModules"); + } + [HttpGet] + public FurnitureModuleViewModel? GetFurnitureModule(int furnitureModuleId) + { + var result = APIClient.GetRequest + ($"api/furnitureModule/getfurnituremodule?Id={furnitureModuleId}"); + if (result == null) + { + return default; + } + return result; + } + [HttpGet] + public IActionResult AddFurnitureModulesInSet() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(Tuple.Create(APIClient.GetRequest>($"api/set/getsetlistbyuser?userId={APIClient.User.Id}"), APIClient.GetRequest>($"api/furnituremodule/getfurnituremodulelistbyuser?userId={APIClient.User.Id}"))); + } + [HttpPost] + public void AddFurnitureModulesInSet(int set, int[] furnitureModuleIds, int[] counts) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (furnitureModuleIds.Length != counts.Length) + { + throw new Exception("Массивы не совпадают"); + } + for (int i = 0; i < furnitureModuleIds.Length; i++) + { + APIClient.PostRequest("api/set/addfurnituremoduleinset", Tuple.Create( + new SetSearchModel() { Id = set }, + new FurnitureModuleViewModel() { Id = furnitureModuleIds[i] }, + counts[i] + )); + } + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult Orders() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/orderinfo/getorderinfolistbyuser?userId={APIClient.User.Id}")); + } + [HttpGet] + public IActionResult CreateOrder() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/set/getsetlistbyuser?userId={APIClient.User.Id}")); + } + [HttpPost] + public void CreateOrder(string name, PaymentType paymentType, int[] setIds, int[] counts) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Имя не должно быть пустым"); + } + var orderInfo = APIClient.PostRequest("api/orderinfo/addorderinfo", new OrderInfoBindingModel + { + CustomerName = name, + PaymentType = paymentType, + UserId = APIClient.User.Id + }); + if (orderInfo == null) + { + throw new Exception("Ошибка создания заказа"); + } + if (setIds != null && setIds.Length > 0 && counts != null && setIds.Length == counts.Length) + { + for (int i = 0; i < counts.Length; i++) + { + APIClient.PostRequest("api/order/addorder", new OrderBindingModel + { + OrderInfoId = orderInfo.Id, + SetId = setIds[i], + Count = counts[i] + }); + } + } + Response.Redirect("Orders"); + } + [HttpGet] + public Tuple? GetOrderWithSets(int orderId) + { + var result = APIClient.GetRequest, List>> + ($"api/order/getorderwithsets?orderId={orderId}"); + if (result == null) + { + return default; + } + string setTable = ""; + for (int i = 0; i < result.Item2.Count; i++) + { + var set = result.Item2[i]; + var count = result.Item3[i]; + setTable += ""; + setTable += $"{set.Name}"; + setTable += $"{set.Cost}"; + setTable += $"{set.DateCreate.Date}"; + setTable += $"{count}"; + setTable += ""; + } + return Tuple.Create(result.Item1, setTable); + } + [HttpGet] + public IActionResult UpdateOrder() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/orderinfo/getorderinfolistbyuser?userId={APIClient.User.Id}")); + } + [HttpPost] + public void UpdateOrder(int order, string name, DateTime dateCreate, PaymentType paymentType, double sum) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название гарнитура не указано"); + } + APIClient.PostRequest("api/orderinfo/updateorderinfo", new OrderInfoBindingModel + { + Id = order, + CustomerName = name, + DateCreate = dateCreate.Date, + PaymentType = paymentType, + UserId = APIClient.User.Id, + Sum = sum + }); + Response.Redirect("Orders"); + } + [HttpGet] + public IActionResult DeleteOrder() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/orderinfo/getorderinfolistbyuser?userId={APIClient.User.Id}")); + } + [HttpPost] + public void DeleteOrder(int order) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/orderinfo/deleteorderinfo", new OrderInfoBindingModel + { + Id = order, + }); + Response.Redirect("Orders"); + } + [HttpGet] + public IActionResult AddSetInOrder() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(Tuple.Create(APIClient.GetRequest>($"api/orderinfo/getorderinfolistbyuser?userId={APIClient.User.Id}"), APIClient.GetRequest>($"api/set/getsetlistbyuser?userId={APIClient.User.Id}"))); + } + [HttpPost] + public void AddSetInOrder(int order, int[] setIds, int[] counts) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (setIds != null && counts != null && counts.Length > 0 && counts.Length == setIds.Length) + { + for (int i = 0; i < counts.Length; i++) + { + if (counts[i] <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + APIClient.PostRequest("api/order/addsetinorder", Tuple.Create( + new OrderInfoSearchModel() { Id = order }, + new SetSearchModel() { Id = setIds[i] }, + counts[i] + )); + } + } + + Response.Redirect("Orders"); + } + } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/AddFurnitureModulesInSet.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/AddFurnitureModulesInSet.cshtml new file mode 100644 index 0000000..e6ba817 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/AddFurnitureModulesInSet.cshtml @@ -0,0 +1,79 @@ +@using FurnitureAssemblyContracts.ViewModels; +@using FurnitureAssemblyDataModels.Models; + +@model Tuple, List> + +@{ + ViewData["Title"] = "Добавление мебельных модулей в гарнитур"; +} +
+

Добавление мебельных модулей в гарнитур

+
+
+
+
Гарнитур:
+
+ +
+ +
+
+
Мебельные модули:
+
+ + + + + + + + + + + + @foreach (var furnitureModule in Model.Item2) + { + + + + + + + + } + +
+ + + Название + + Стоимость + + Дата создания + + Количество +
+ + + @Html.DisplayFor(modelItem => furnitureModule.Name) + + @Html.DisplayFor(modelItem => furnitureModule.Cost) + + @Html.DisplayFor(modelItem => furnitureModule.DateCreate) + + +
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/AddSetInOrder.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/AddSetInOrder.cshtml new file mode 100644 index 0000000..ac76e9f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/AddSetInOrder.cshtml @@ -0,0 +1,79 @@ +@using FurnitureAssemblyContracts.ViewModels; +@using FurnitureAssemblyDataModels.Models; + +@model Tuple, List> + +@{ + ViewData["Title"] = "Добавление гарнитур в заказ"; +} +
+

Добавление гарнитур в заказ

+
+
+
+
Заказ:
+
+ +
+ +
+
+
Гарнитуры:
+
+ + + + + + + + + + + + @foreach (var set in Model.Item2) + { + + + + + + + + } + +
+ + + Название + + Стоимость + + Дата создания + + Количество +
+ + + @Html.DisplayFor(modelItem => set.Name) + + @Html.DisplayFor(modelItem => set.Cost) + + @Html.DisplayFor(modelItem => set.DateCreate) + + +
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/CreateFurnitureModule.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/CreateFurnitureModule.cshtml new file mode 100644 index 0000000..56a2ba7 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/CreateFurnitureModule.cshtml @@ -0,0 +1,20 @@ +@{ + ViewData["Title"] = "Создание мебельного модуля"; +} +
+

Создание мебельного модуля

+
+
+
+
Название:
+
+
+
+
Стоимость:
+
+
+
+
+
+
+
diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/CreateOrder.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/CreateOrder.cshtml new file mode 100644 index 0000000..630602e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/CreateOrder.cshtml @@ -0,0 +1,74 @@ +@using FurnitureAssemblyContracts.ViewModels; +@using FurnitureAssemblyDataModels.Enums; + +@model List + +@{ + ViewData["Title"] = "Создание заказа"; +} +
+

Создание заказа

+
+
+
+
Имя заказчика:
+
+
+
+
Тип оплаты:
+
+ +
+
+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
+ + + Название + + Стоимость + + Дата создания + + Количество +
+ + + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Cost) + + @Html.DisplayFor(modelItem => item.DateCreate) + + +
+
+
+
+
+
diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/DeleteFurnitureModule.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/DeleteFurnitureModule.cshtml new file mode 100644 index 0000000..0dbab14 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/DeleteFurnitureModule.cshtml @@ -0,0 +1,27 @@ +@using FurnitureAssemblyContracts.ViewModels; +@{ + ViewData["Title"] = "Удаление мебельного модуля"; +} +@model List +
+

Удаление мебельного модуля

+
+
+
+
Выбранный мебельного модуля:
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/DeleteOrder.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/DeleteOrder.cshtml new file mode 100644 index 0000000..c3066b6 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/DeleteOrder.cshtml @@ -0,0 +1,27 @@ +@using FurnitureAssemblyContracts.ViewModels; +@{ + ViewData["Title"] = "Удаление заказа"; +} +@model List +
+

Удаление заказа

+
+
+
+
Выбранный заказ:
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/FurnitureModules.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/FurnitureModules.cshtml new file mode 100644 index 0000000..9308d86 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/FurnitureModules.cshtml @@ -0,0 +1,64 @@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Формирование мебельнго модуля"; +} + +
+

Мебельные модули

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Номер + + Название + + Стоимость + + Дата создания +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Cost) + + @Html.DisplayFor(modelItem => item.DateCreate) +
+ } +
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/Orders.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/Orders.cshtml new file mode 100644 index 0000000..97a798a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/Orders.cshtml @@ -0,0 +1,71 @@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Формирование заказов"; +} + +
+

Заказы

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
+ Номер + + Имя заказчика + + Дата создания + + Тип оплаты + + Сумма +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.CustomerName) + + @Html.DisplayFor(modelItem => item.DateCreate) + + @Html.DisplayFor(modelItem => item.PaymentType) + + @Html.DisplayFor(modelItem => item.Sum) +
+ } +
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateFurnitureModule.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateFurnitureModule.cshtml new file mode 100644 index 0000000..da30334 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateFurnitureModule.cshtml @@ -0,0 +1,65 @@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Изменение мебельного модуля"; +} +
+

Изменение мебельного модуля

+
+
+
+
Мебельный модуль:
+
+ +
+
+
+
Название:
+
+
+
+
Стоимость:
+
+
+
+
Дата создания:
+
+
+
+
+
+
+
+ +@section Scripts { + +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateOrder.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateOrder.cshtml new file mode 100644 index 0000000..f8d54ed --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateOrder.cshtml @@ -0,0 +1,93 @@ +@using FurnitureAssemblyContracts.ViewModels +@using FurnitureAssemblyDataModels.Enums; + +@model List + +@{ + ViewData["Title"] = "Изменение заказа"; +} +
+

Изменение заказа

+
+
+
+
Заказ:
+
+ +
+
+
+
Имя клиента:
+
+
+
+
Тип оплаты:
+
+ +
+
+
+
Дата создания:
+
+
+ + + + + + + + + + + +
+ Название гарнитура + + Стоимость + + Количество +
+
+
+
+
+
+ +@section Scripts { + +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateSet.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateSet.cshtml index fa2b05a..f141392 100644 --- a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateSet.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/UpdateSet.cshtml @@ -64,13 +64,13 @@ if (set) { $.ajax({ method: "GET", - url: "/Home/GetShopWithManufactures", + url: "/Home/GetSetWithFurnitureModules", data: { setId: set }, success: function (result) { if (result != null) { $('#name').val(result.item1.name); $('#cost').val(result.item1.cost); - $('#dateCreate').val(result.item1.dateCreate); + $('#dateCreate').val(new Date(result.item1.dateCreate).toISOString().split(".")[0].substr(0, 16)); $('#furnitureModules-table').html(result.item2); } } diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Shared/_Layout.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Shared/_Layout.cshtml index 76e2ea4..2e1f308 100644 --- a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Shared/_Layout.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Shared/_Layout.cshtml @@ -6,10 +6,9 @@ @ViewData["Title"] - FurnitureAssemblyWorkerClientApp - + - @await RenderSectionAsync("Scripts", required: false)