From 12caf0349f116b14394107646c4d3711aab9cdd9 Mon Sep 17 00:00:00 2001 From: dasha Date: Thu, 6 Apr 2023 15:09:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=B0=D0=BA=D0=BE=D0=B9-=D1=82=D0=BE=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=BD=D0=B5=D0=BD=D1=8C=D0=BA?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB?= =?UTF-8?q?=D0=B5=D1=80=20=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B1=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D0=B0=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.Designer.cs | 3 +- .../Controllers/ShopController.cs | 108 ++++++++++++++++++ SushiBar/SushiBarRestApi/Program.cs | 2 + 3 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 SushiBar/SushiBarRestApi/Controllers/ShopController.cs diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index 3625a45..1da5714 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -70,9 +70,8 @@ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ингредиентыToolStripMenuItem, this.сушиToolStripMenuItem, + this.клиентыToolStripMenuItem, this.shopsToolStripMenuItem}); - this.сушиToolStripMenuItem, - this.клиентыToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; diff --git a/SushiBar/SushiBarRestApi/Controllers/ShopController.cs b/SushiBar/SushiBarRestApi/Controllers/ShopController.cs new file mode 100644 index 0000000..8149aaa --- /dev/null +++ b/SushiBar/SushiBarRestApi/Controllers/ShopController.cs @@ -0,0 +1,108 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; +using SushiBarDataModels.Models; + +namespace SushiBarRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ShopCOntroller : Controller + { + private readonly ILogger _logger; + + private readonly IShopLogic _shop; + + public ShopCOntroller(ILogger logger, IShopLogic shop) + { + _logger = logger; + _shop = shop; + } + + [HttpGet] + public List? GetShops() + { + try + { + return _shop.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка магазинов"); + throw; + } + } + + [HttpGet] + public ShopViewModel? GetShop(int shopId) + { + try + { + return _shop.ReadElement(new ShopSearchModel { Id = shopId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения магазина по id={Id}", shopId); + throw; + } + } + + [HttpPost] + public void CreateShop(ShopBindingModel model) + { + try + { + _shop.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания магазина"); + throw; + } + } + + [HttpPost] + public void UpdateData(ShopBindingModel model) + { + try + { + _shop.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + + [HttpPost] + public void DeleteShop(ShopBindingModel model) + { + try + { + _shop.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + throw; + } + } + + [HttpPost] + public void AddSushiInShop(Tuple model) + { + try + { + _shop.AddSushiInShop(model.Item1, model.Item2, model.Item3); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка добавления суши в магазин"); + throw; + } + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarRestApi/Program.cs b/SushiBar/SushiBarRestApi/Program.cs index 73886b2..f1cfc49 100644 --- a/SushiBar/SushiBarRestApi/Program.cs +++ b/SushiBar/SushiBarRestApi/Program.cs @@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config"); 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