| | | 1 | | using Microsoft.AspNetCore.Authorization; |
| | | 2 | | using Microsoft.AspNetCore.Mvc; |
| | | 3 | | using OzonOrdersWeb.Areas.OzonCards.ViewModels; |
| | | 4 | | using Services.DataServices.ExcelMapping; |
| | | 5 | | |
| | | 6 | | namespace OzonOrdersWeb.Areas.OzonCards.Controllers |
| | | 7 | | { |
| | | 8 | | [Area("OzonCards")] |
| | | 9 | | [Authorize(Roles = "User,Admin")] |
| | | 10 | | public class ExcelMappingsController : Controller |
| | | 11 | | { |
| | | 12 | | private readonly IExcelMappingService _mappingService; |
| | | 13 | | |
| | 0 | 14 | | public ExcelMappingsController(IExcelMappingService mappingService) |
| | | 15 | | { |
| | 0 | 16 | | _mappingService = mappingService; |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | public async Task<IActionResult> Index() |
| | | 20 | | { |
| | 0 | 21 | | var mappings = await _mappingService.GetAllMappingsAsync(); |
| | 0 | 22 | | return View(mappings); |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | [HttpPost] |
| | | 26 | | public async Task<IActionResult> Save(ExcelMappingRequest request, string mappingName) |
| | | 27 | | { |
| | | 28 | | try |
| | | 29 | | { |
| | 0 | 30 | | var id = await _mappingService.SaveMappingAsync(request, mappingName, User.Identity?.Name ?? string.Empt |
| | 0 | 31 | | return Json(new { success = true, id }); |
| | | 32 | | } |
| | 0 | 33 | | catch (Exception ex) |
| | | 34 | | { |
| | 0 | 35 | | return Json(new { success = false, message = ex.Message }); |
| | | 36 | | } |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | [HttpGet] |
| | | 40 | | public async Task<IActionResult> Load(int id) |
| | | 41 | | { |
| | | 42 | | try |
| | | 43 | | { |
| | 0 | 44 | | var mapping = await _mappingService.GetMappingAsync(id); |
| | 0 | 45 | | return Json(new { success = true, data = mapping }); |
| | | 46 | | } |
| | 0 | 47 | | catch (Exception ex) |
| | | 48 | | { |
| | 0 | 49 | | return Json(new { success = false, message = ex.Message }); |
| | | 50 | | } |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | [HttpDelete] |
| | | 54 | | public async Task<IActionResult> Delete(int id) |
| | | 55 | | { |
| | | 56 | | try |
| | | 57 | | { |
| | 0 | 58 | | await _mappingService.DeleteMappingAsync(id); |
| | 0 | 59 | | return Json(new { success = true }); |
| | | 60 | | } |
| | 0 | 61 | | catch (Exception ex) |
| | | 62 | | { |
| | 0 | 63 | | return Json(new { success = false, message = ex.Message }); |
| | | 64 | | } |
| | 0 | 65 | | } |
| | | 66 | | } |
| | | 67 | | } |