diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs index 96fb8fc..36a69e7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs @@ -212,5 +212,17 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { return _storeStorage.SellManufacture(manufacture, count); } + public List ReadManufacturesInStore(StoreSearchModel? model) + { + if (model != null) + { + var result = _storeStorage.GetManufacturesInStore(model); + return result; + } + else + { + return new(); + } + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/FillingStoreBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/FillingStoreBindingModel.cs new file mode 100644 index 0000000..12ee286 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/FillingStoreBindingModel.cs @@ -0,0 +1,9 @@ +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class FillingStoreBindingModel + { + public int Store { get; set; } + public int Manufacture { get; set; } + public int Count { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IStoreLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IStoreLogic.cs index 63d3cc8..f6ca23c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IStoreLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IStoreLogic.cs @@ -23,5 +23,6 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts int GetFreePlace(int count); bool FillStore(IManufactureModel manufacture, int count); public bool SellManufactures(IManufactureModel manufacture, int needCount); + public List ReadManufacturesInStore(StoreSearchModel? model); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs index 503d958..5fc0aa2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs @@ -28,5 +28,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts /// bool SellManufacture(IManufactureModel manufacture, int count); int GetPlaceLeft(IStoreModel store); + List GetManufacturesInStore(StoreSearchModel model); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureInStoreViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureInStoreViewModel.cs new file mode 100644 index 0000000..1ee3de2 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureInStoreViewModel.cs @@ -0,0 +1,8 @@ +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ManufactureInStoreViewModel + { + public string ManufactureName { get; set; } = string.Empty; + public int Count { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/StoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/StoreStorage.cs index ede6823..e77ea11 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/StoreStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/StoreStorage.cs @@ -99,7 +99,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return null; } store.Update(model); - store.UpdateManufactures(context, model); + if (model.Manufactures.Count != 0) + { + store.UpdateManufactures(context, model); + } context.SaveChanges(); return store.GetViewModel; } @@ -149,5 +152,12 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } return selectedStore.MaxManufactures - selectedStore.Manufactures.Select(x => x.Value.Item2).Sum(); } + + public List GetManufacturesInStore(StoreSearchModel model) + { + var store = GetElement(model); + List result = store?.Manufactures.Select(x => new ManufactureInStoreViewModel() { ManufactureName = x.Value.Item1.ManufactureName, Count = x.Value.Item2}).ToList() ?? new(); + return result; + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/StoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/StoreStorage.cs index 4d8b744..c8fc367 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/StoreStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/StoreStorage.cs @@ -122,5 +122,11 @@ namespace BlacksmithWorkshopFileImplement.Implements } return store.MaxManufactures - store.Manufactures.Select(x => x.Value.Item2).Sum(); } + public List GetManufacturesInStore(StoreSearchModel model) + { + var store = GetElement(model); + List result = store?.Manufactures.Select(x => new ManufactureInStoreViewModel() { ManufactureName = x.Value.Item1.ManufactureName, Count = x.Value.Item2 }).ToList() ?? new(); + return result; + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs index 078650a..c2c45ac 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs @@ -113,5 +113,11 @@ namespace BlacksmithWorkshopListImplement.Implements { throw new NotImplementedException("Не применяется в данной реализации"); } + public List GetManufacturesInStore(StoreSearchModel model) + { + var store = GetElement(model); + List result = store?.Manufactures.Select(x => new ManufactureInStoreViewModel() { ManufactureName = x.Value.Item1.ManufactureName, Count = x.Value.Item2 }).ToList() ?? new(); + return result; + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs index b9bff64..e4a47f9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/MainController.cs @@ -29,7 +29,7 @@ namespace BlacksmithWorkshopRestAPI.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка продуктов"); + _logger.LogError(ex, "Ошибка получения списка изделий"); throw; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/StoreController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/StoreController.cs index 4679ba0..605577a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/StoreController.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/StoreController.cs @@ -1,6 +1,8 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; using Microsoft.AspNetCore.Mvc; namespace BlacksmithWorkshopRestAPI.Controllers @@ -23,6 +25,12 @@ namespace BlacksmithWorkshopRestAPI.Controllers var result = _logic.ReadList(null); return result ?? new(); } + [HttpGet] + public StoreViewModel GetStore(int id) + { + StoreViewModel? result = _logic.ReadElement(new() { Id = id }); + return result ?? new(); + } [HttpPost] public void CreateStore(StoreBindingModel model) { @@ -63,16 +71,30 @@ namespace BlacksmithWorkshopRestAPI.Controllers } } [HttpPost] - public void FillStore(ManufactureBindingModel model, int count) + public void AddManufacture(FillingStoreBindingModel model) { try { - _logic.FillStore(model, count); + _logic.AddManufacture(new ManufactureBindingModel() { Id = model.Manufacture }, new() { Id = model.Store }, model.Count); } catch (Exception ex) { _logger.LogError(ex, "Ошибка при пополнении магазина"); } } + [HttpGet] + public List GetManufacturesInStore(int id) + { + try + { + var result = _logic.ReadManufacturesInStore(new() { Id = id }); + return result; + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске изделий"); + throw; + } + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/APIClient.cs b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/APIClient.cs index 05ddb3e..fdf7e62 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/APIClient.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/APIClient.cs @@ -29,7 +29,7 @@ namespace BlacksmithWorkshopStoreApp throw new Exception(result); } } - public static void PostRequest(string requestUrl, T model) + public static void PostRequest(string requestUrl, T? model) { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, Encoding.UTF8, "application/json"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Controllers/HomeController.cs b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Controllers/HomeController.cs index 0a41a84..150c107 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Controllers/HomeController.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; using BlacksmithWorkshopStoreApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -26,6 +27,7 @@ namespace BlacksmithWorkshopStoreApp.Controllers [HttpGet] public IActionResult Enter() { + APIClient.AccessGranted = false; return View(); } [HttpPost] @@ -35,15 +37,15 @@ namespace BlacksmithWorkshopStoreApp.Controllers { APIClient.AccessGranted = true; } - else - { - APIClient.AccessGranted = false; - } return Redirect("~/Home/Index"); } [HttpGet] public IActionResult Create() { + if (!APIClient.AccessGranted) + { + return Redirect("~/Home/Enter"); + } return View(); } [HttpPost] @@ -52,6 +54,41 @@ namespace BlacksmithWorkshopStoreApp.Controllers APIClient.PostRequest("/api/store/createstore", model); return Redirect("~/Home/Index"); } + [HttpGet] + public IActionResult Update(int id) + { + StoreViewModel? store = APIClient.GetRequest($"/api/store/getstore?id={id}"); + List? man = APIClient.GetRequest>($"/api/store/getmanufacturesinstore?id={id}"); + ViewBag.Store = store; + ViewBag.Manufactures = man; + return View(); + } + [HttpPost] + public IActionResult Update(StoreViewModel model) + { + APIClient.PostRequest("/api/store/updatestore", model); + return Redirect("~/Home/Index"); + } + public IActionResult Delete(int id) + { + APIClient.PostRequest($"/api/store/deletestore", new StoreBindingModel { Id = id }); + return Redirect("~/Home/Index"); + } + [HttpGet] + public IActionResult FillStore(int id) + { + ViewBag.Store = id; + var manufactures = APIClient.GetRequest>("/api/main/getmanufacturelist"); + ViewBag.Manufactures = manufactures; + return View(); + } + [HttpPost] + public IActionResult FillStore(int store, int manufacture, int count) + { + FillingStoreBindingModel model = new() { Store = store, Manufacture = manufacture, Count = count }; + APIClient.PostRequest($"/api/store/addmanufacture", model); + return Redirect($"~/Home/Update/{store}"); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/FillStore.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/FillStore.cshtml new file mode 100644 index 0000000..d689b5a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/FillStore.cshtml @@ -0,0 +1,12 @@ +@{ + ViewData["Title"] = "Создание магазина"; +} +
+ + @foreach (var manufacture in ViewBag.Manufactures) + { +

@manufacture.ManufactureName

+ } +

Количество

+
+
\ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/Index.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/Index.cshtml index f745bca..c0afd78 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/Index.cshtml +++ b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/Index.cshtml @@ -20,13 +20,13 @@ @foreach (var store in ViewBag.Stores) { - @store.StoreName + @store.StoreName @store.Address - @store.OpeningDate + @store.OpeningDate.ToShortDateString() @store.MaxManufactures - Изменить - Удалить - Поставить изделие + Изменить + Удалить + Поставить изделие } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/Update.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/Update.cshtml new file mode 100644 index 0000000..9843a1c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopStoreApp/Views/Home/Update.cshtml @@ -0,0 +1,31 @@ +@{ + ViewData["Title"] = "Изменение магазина"; +} +
+
+
Название магазина:
+
+
+
+
Адрес:
+
+
+
+
Дата открытия:
+
+
+ +
+ @foreach (var manufacture in ViewBag.Manufactures) + { +

Изделие: @manufacture.ManufactureName

+

Количество: @manufacture.Count

+
+ } +
+
+
+
\ No newline at end of file