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