| | | 1 | | using Microsoft.AspNetCore.Mvc; |
| | | 2 | | using OzonDomains.Models; |
| | | 3 | | using Services.DataServices; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | using Services.ApiServices; |
| | | 6 | | |
| | | 7 | | namespace OzonOrdersWeb.Areas.Studio2.Controllers |
| | | 8 | | { |
| | | 9 | | [Area("Studio2")] |
| | | 10 | | public class ExcludedBitrixWarehouseController : Controller |
| | | 11 | | { |
| | | 12 | | private readonly ExcludedBitrixWarehouseDataServices _dataService; |
| | | 13 | | private readonly OneCDataManager _oneCDataManager; |
| | | 14 | | |
| | 0 | 15 | | public ExcludedBitrixWarehouseController(ExcludedBitrixWarehouseDataServices dataService, |
| | 0 | 16 | | OneCDataManager oneCDataManager) |
| | | 17 | | { |
| | 0 | 18 | | _dataService = dataService; |
| | 0 | 19 | | _oneCDataManager = oneCDataManager; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | public async Task<IActionResult> Index() |
| | | 23 | | { |
| | 0 | 24 | | var items = await _dataService.GetExcludedBitrixWarehouses(); |
| | 0 | 25 | | return View(items); |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | [HttpGet] |
| | | 29 | | public async Task<IActionResult> Create() |
| | | 30 | | { |
| | 0 | 31 | | var warehouses = await _oneCDataManager.GetWarehouseListAsync(); |
| | | 32 | | |
| | 0 | 33 | | ViewBag.BitrixWarehouses = warehouses |
| | 0 | 34 | | .Select(x => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem |
| | 0 | 35 | | { |
| | 0 | 36 | | Text = x.Name, |
| | 0 | 37 | | Value = x.Name |
| | 0 | 38 | | }).ToList(); |
| | | 39 | | |
| | 0 | 40 | | ViewBag.OzonWarehouses = warehouses |
| | 0 | 41 | | .Select(x => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem |
| | 0 | 42 | | { |
| | 0 | 43 | | Text = x.Name, |
| | 0 | 44 | | Value = x.Name |
| | 0 | 45 | | }).ToList(); |
| | | 46 | | |
| | 0 | 47 | | return View(new ExcludedBitrixWarehouse()); |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | [HttpPost] |
| | | 51 | | [ValidateAntiForgeryToken] |
| | | 52 | | public async Task<IActionResult> Create(ExcludedBitrixWarehouse model) |
| | | 53 | | { |
| | 0 | 54 | | if (!ModelState.IsValid) |
| | 0 | 55 | | return View(model); |
| | | 56 | | |
| | 0 | 57 | | await _dataService.AddExcludedBitrixWarehouse(model); |
| | 0 | 58 | | TempData["SuccessMessage"] = $"Склад '{model.Name}' успешно добавлен в исключения."; |
| | 0 | 59 | | return RedirectToAction(nameof(Index)); |
| | 0 | 60 | | } |
| | | 61 | | |
| | | 62 | | [HttpGet] |
| | | 63 | | public async Task<IActionResult> Delete(int id) |
| | | 64 | | { |
| | 0 | 65 | | var item = await _dataService.GetExcludedBitrixWarehouseAsync(id); |
| | 0 | 66 | | if (item == null) |
| | 0 | 67 | | return NotFound(); |
| | | 68 | | |
| | 0 | 69 | | return View(item); |
| | 0 | 70 | | } |
| | | 71 | | |
| | | 72 | | [HttpPost, ActionName("Delete")] |
| | | 73 | | [ValidateAntiForgeryToken] |
| | | 74 | | public async Task<IActionResult> DeleteConfirmed(int id) |
| | | 75 | | { |
| | 0 | 76 | | var item = await _dataService.GetExcludedBitrixWarehouseAsync(id); |
| | 0 | 77 | | if (item != null) |
| | | 78 | | { |
| | 0 | 79 | | await _dataService.DeleteExcludedBitrixWarehouse(item); |
| | 0 | 80 | | TempData["SuccessMessage"] = $"Склад '{item.Name}' удалён из исключений."; |
| | | 81 | | } |
| | | 82 | | |
| | 0 | 83 | | return RedirectToAction(nameof(Index)); |
| | 0 | 84 | | } |
| | | 85 | | } |
| | | 86 | | } |