| | | 1 | | using Microsoft.AspNetCore.Mvc; |
| | | 2 | | using Newtonsoft.Json; |
| | | 3 | | using OzonRepositories.Data; |
| | | 4 | | using Services.CacheServices.Cache.OzonOrdersCache; |
| | | 5 | | |
| | | 6 | | namespace OzonOrdersWeb.Controllers |
| | | 7 | | { |
| | | 8 | | [Area("Studio2")] |
| | | 9 | | public class OrderItemController : Controller |
| | | 10 | | { |
| | | 11 | | private readonly OrderItemRepository _orderItemRepository; |
| | | 12 | | private readonly OrderCache _cache; |
| | 0 | 13 | | public OrderItemController(OrderItemRepository orderItemRepository, |
| | 0 | 14 | | OrderCache cache) |
| | | 15 | | { |
| | 0 | 16 | | _orderItemRepository = orderItemRepository; |
| | 0 | 17 | | _cache = cache; |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public async Task<IActionResult> Delete(int id) |
| | | 21 | | { |
| | 0 | 22 | | var item = await _orderItemRepository.GetAsync(id); |
| | 0 | 23 | | if (item == null) return NotFound(); |
| | | 24 | | |
| | 0 | 25 | | return View(item); |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | [HttpPost, ActionName("Delete")] |
| | | 29 | | [ValidateAntiForgeryToken] |
| | | 30 | | public async Task<IActionResult> DeleteConfirmed(int id) |
| | | 31 | | { |
| | 0 | 32 | | await _orderItemRepository.DeleteAsync(id); |
| | 0 | 33 | | return RedirectToAction("Index", "Cart"); // Возврат к списку корзин |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | [HttpPost] |
| | | 37 | | [ValidateAntiForgeryToken] |
| | | 38 | | public async Task<IActionResult> SwapStudioOrderIds(string ids, int page) |
| | | 39 | | { |
| | 0 | 40 | | if (string.IsNullOrEmpty(ids)) |
| | 0 | 41 | | return BadRequest("ids пустые"); |
| | | 42 | | |
| | 0 | 43 | | var idArray = ids.Split(',').Select(int.Parse).ToArray(); |
| | | 44 | | |
| | 0 | 45 | | if (idArray.Length != 2) |
| | 0 | 46 | | return BadRequest("нужно передать ровно 2 id"); |
| | | 47 | | |
| | 0 | 48 | | var result = await _orderItemRepository.SwapStudioOrderIdsWithValidationAsync(idArray[0], idArray[1]); |
| | | 49 | | |
| | 0 | 50 | | if (!result) |
| | 0 | 51 | | return BadRequest("обмен не удался"); |
| | | 52 | | |
| | 0 | 53 | | HttpContext.Session.SetString("selectedIds", JsonConvert.SerializeObject(new List<int>())); |
| | 0 | 54 | | await _cache.Update(); |
| | | 55 | | |
| | 0 | 56 | | return Ok(new { success = true }); |
| | 0 | 57 | | } |
| | | 58 | | } |
| | | 59 | | } |