diff --git a/IceCreamShop/IceCreamShopRestApi/Controllers/ClientController.cs b/IceCreamShop/IceCreamShopRestApi/Controllers/ClientController.cs deleted file mode 100644 index 153e1af..0000000 --- a/IceCreamShop/IceCreamShopRestApi/Controllers/ClientController.cs +++ /dev/null @@ -1,64 +0,0 @@ -using IceCreamShopContracts.BindingModels; -using IceCreamShopContracts.BusinessLogicsContracts; -using IceCreamShopContracts.SearchModels; -using IceCreamShopContracts.ViewModels; -using Microsoft.AspNetCore.Mvc; -namespace IceCreamShopRestApi.Controllers -{ - [Route("api/[controller]/[action]")] - [ApiController] - public class ClientController : Controller - { - private readonly ILogger _logger; - private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger - logger) - { - _logger = logger; - _logic = logic; - } - [HttpGet] - public ClientViewModel? Login(string login, string password) - { - try - { - return _logic.ReadElement(new ClientSearchModel - { - Email = login, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } - [HttpPost] - public void Register(ClientBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); - throw; - } - } - [HttpPost] - public void UpdateData(ClientBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } - } - } -} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopRestApi/Controllers/HomeController.cs b/IceCreamShop/IceCreamShopRestApi/Controllers/HomeController.cs new file mode 100644 index 0000000..970c9a6 --- /dev/null +++ b/IceCreamShop/IceCreamShopRestApi/Controllers/HomeController.cs @@ -0,0 +1,83 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace IceCreamShopRestApi.Controllers +{ + public class HomeController : Controller + { + // GET: HomeController + public ActionResult Index() + { + return View(); + } + + // GET: HomeController/Details/5 + public ActionResult Details(int id) + { + return View(); + } + + // GET: HomeController/Create + public ActionResult Create() + { + return View(); + } + + // POST: HomeController/Create + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Create(IFormCollection collection) + { + try + { + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + + // GET: HomeController/Edit/5 + public ActionResult Edit(int id) + { + return View(); + } + + // POST: HomeController/Edit/5 + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Edit(int id, IFormCollection collection) + { + try + { + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + + // GET: HomeController/Delete/5 + public ActionResult Delete(int id) + { + return View(); + } + + // POST: HomeController/Delete/5 + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Delete(int id, IFormCollection collection) + { + try + { + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } + } +} diff --git a/IceCreamShop/IceCreamShopRestApi/Controllers/ShopController.cs b/IceCreamShop/IceCreamShopRestApi/Controllers/ShopController.cs new file mode 100644 index 0000000..e46c0a1 --- /dev/null +++ b/IceCreamShop/IceCreamShopRestApi/Controllers/ShopController.cs @@ -0,0 +1,105 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; +using IceCreamShopContracts.ViewModels; +using IceCreamShopDataModels.Models; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace IceCreamShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ShopController : ControllerBase + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public ShopController(IShopLogic logic, ILogger + logger) + { + _logger = logger; + _logic = logic; + } + [HttpGet] + public ShopViewModel GetShop(ShopSearchModel model) + { + try + { + return _logic.ReadElement(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка магазинов"); + throw; + } + } + [HttpGet] + public List GetShops() + { + try + { + return _logic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка магазинов"); + throw; + } + } + [HttpPost] + public bool CreateShop(ShopBindingModel model) + { + try + { + return _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать магазин"); + throw; + } + } + + [HttpPost] + public bool UpdateShop(ShopBindingModel model) + { + try + { + return _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить магазин"); + throw; + } + } + + [HttpPost] + public bool DeleteShop(ShopBindingModel model) + { + try + { + return _logic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось удалить магазин"); + throw; + } + } + + [HttpPost] + public bool MakeSupply(ShopSearchModel model, IIceCreamModel iceCream, int count) + { + try + { + return _logic.MakeSupply(model, iceCream, count); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось сделать поставку в магазин"); + throw; + } + } + } +} diff --git a/IceCreamShop/IceCreamShopRestApi/Program.cs b/IceCreamShop/IceCreamShopRestApi/Program.cs index a03fe2d..53d5eba 100644 --- a/IceCreamShop/IceCreamShopRestApi/Program.cs +++ b/IceCreamShop/IceCreamShopRestApi/Program.cs @@ -8,9 +8,11 @@ builder.Logging.SetMinimumLevel(LogLevel.Trace); builder.Logging.AddLog4Net("log4net.config"); // Add services to the container. 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();