какой-то странненький контроллер и коммит для переброса данных на комп

This commit is contained in:
dasha 2023-04-06 15:09:15 +04:00
parent ab2ad8041c
commit 12caf0349f
3 changed files with 111 additions and 2 deletions

View File

@ -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 = "Справочники";

View File

@ -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<MainController> logger, IShopLogic shop)
{
_logger = logger;
_shop = shop;
}
[HttpGet]
public List<ShopViewModel>? 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<ShopSearchModel, ISushiModel, int> model)
{
try
{
_shop.AddSushiInShop(model.Item1, model.Item2, model.Item3);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка добавления суши в магазин");
throw;
}
}
}
}

View File

@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<ISushiStorage, SushiStorage>();
builder.Services.AddTransient<IShopStorage, ShopStorage>();
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<ISushiLogic, SushiLogic>();
builder.Services.AddTransient<IShopLogic, ShopLogic>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle