SettlementPaymentsController.cs
5,545 bytes
| 1 | using App.BLL.DTO; |
|---|---|
| 2 | using App.BLL.Services.Admin; |
| 3 | using App.Domain; |
| 4 | using Microsoft.AspNetCore.Authorization; |
| 5 | using Microsoft.AspNetCore.Mvc; |
| 6 | using Microsoft.Extensions.Localization; |
| 7 | using WebApp.Areas.Admin.Models; |
| 8 | |
| 9 | namespace WebApp.Areas.Admin.Controllers |
| 10 | { |
| 11 | [Area("Admin")] |
| 12 | [Authorize(Roles = "admin")] |
| 13 | public class SettlementPaymentsController : Controller |
| 14 | { |
| 15 | private readonly ISettlementPaymentAdminService _service; |
| 16 | private readonly IStringLocalizer<App.Resources.Views.Shared> _l; |
| 17 | |
| 18 | public SettlementPaymentsController(ISettlementPaymentAdminService service, |
| 19 | IStringLocalizer<App.Resources.Views.Shared> l) |
| 20 | { |
| 21 | _service = service; |
| 22 | _l = l; |
| 23 | } |
| 24 | |
| 25 | // GET: Admin/SettlementPayments |
| 26 | public async Task<IActionResult> Index(string? search) |
| 27 | { |
| 28 | var payments = await _service.GetAllAsync(search); |
| 29 | |
| 30 | var vm = new AdminSettlementPaymentIndexViewModel |
| 31 | { |
| 32 | Title = _l["Settlement payments"].Value, |
| 33 | Items = payments.OrderByDescending(s => s.Id).ToList(), |
| 34 | CurrentSearch = search |
| 35 | }; |
| 36 | return View(vm); |
| 37 | } |
| 38 | |
| 39 | // GET: Admin/SettlementPayments/Details/5 |
| 40 | public async Task<IActionResult> Details(Guid? id) |
| 41 | { |
| 42 | if (id == null) |
| 43 | { |
| 44 | return NotFound(); |
| 45 | } |
| 46 | |
| 47 | var settlementPayment = await _service.GetByIdAsync(id.Value); |
| 48 | if (settlementPayment == null) |
| 49 | { |
| 50 | return NotFound(); |
| 51 | } |
| 52 | |
| 53 | return View(new AdminDetailsViewModel<SettlementPaymentBllDto> |
| 54 | { |
| 55 | Title = _l["Settlement payment details"].Value, |
| 56 | Item = settlementPayment |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | public async Task<IActionResult> Create() |
| 61 | { |
| 62 | return View(new AdminSettlementPaymentFormViewModel |
| 63 | { |
| 64 | Title = _l["New settlement payment"].Value, |
| 65 | SettlementPlanList = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await _service.GetSettlementPlansAsync(), "Id", "Id"), |
| 66 | UserList = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await _service.GetUsersAsync(), "Id", "Email") |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | [HttpPost] |
| 71 | [ValidateAntiForgeryToken] |
| 72 | public async Task<IActionResult> Create(AdminSettlementPaymentFormViewModel vm) |
| 73 | { |
| 74 | if (ModelState.IsValid) |
| 75 | { |
| 76 | await _service.CreateAsync(vm.Payment); |
| 77 | return RedirectToAction(nameof(Index)); |
| 78 | } |
| 79 | |
| 80 | vm.Title = _l["New settlement payment"].Value; |
| 81 | vm.SettlementPlanList = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await _service.GetSettlementPlansAsync(), "Id", "Id", vm.Payment.SettlementPlanId); |
| 82 | vm.UserList = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await _service.GetUsersAsync(), "Id", "Email", vm.Payment.FromUserId); |
| 83 | return View(vm); |
| 84 | } |
| 85 | |
| 86 | public async Task<IActionResult> Edit(Guid? id) |
| 87 | { |
| 88 | if (id == null) return NotFound(); |
| 89 | var payment = await _service.GetByIdAsync(id.Value); |
| 90 | if (payment == null) return NotFound(); |
| 91 | |
| 92 | return View(new AdminSettlementPaymentFormViewModel |
| 93 | { |
| 94 | Title = _l["Edit settlement payment"].Value, |
| 95 | Payment = payment, |
| 96 | SettlementPlanList = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await _service.GetSettlementPlansAsync(), "Id", "Id", payment.SettlementPlanId), |
| 97 | UserList = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await _service.GetUsersAsync(), "Id", "Email", payment.FromUserId) |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | [HttpPost] |
| 102 | [ValidateAntiForgeryToken] |
| 103 | public async Task<IActionResult> Edit(Guid id, AdminSettlementPaymentFormViewModel vm) |
| 104 | { |
| 105 | if (id != vm.Payment.Id) return NotFound(); |
| 106 | |
| 107 | if (ModelState.IsValid) |
| 108 | { |
| 109 | await _service.UpdateAsync(vm.Payment); |
| 110 | return RedirectToAction(nameof(Index)); |
| 111 | } |
| 112 | |
| 113 | vm.Title = _l["Edit settlement payment"].Value; |
| 114 | vm.SettlementPlanList = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await _service.GetSettlementPlansAsync(), "Id", "Id", vm.Payment.SettlementPlanId); |
| 115 | vm.UserList = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(await _service.GetUsersAsync(), "Id", "Email", vm.Payment.FromUserId); |
| 116 | return View(vm); |
| 117 | } |
| 118 | |
| 119 | // GET: Admin/SettlementPayments/Delete/5 |
| 120 | public async Task<IActionResult> Delete(Guid? id) |
| 121 | { |
| 122 | if (id == null) |
| 123 | { |
| 124 | return NotFound(); |
| 125 | } |
| 126 | |
| 127 | var settlementPayment = await _service.GetByIdAsync(id.Value); |
| 128 | if (settlementPayment == null) |
| 129 | { |
| 130 | return NotFound(); |
| 131 | } |
| 132 | |
| 133 | return View(new AdminDeleteViewModel<SettlementPaymentBllDto> |
| 134 | { |
| 135 | Title = _l["Delete settlement payment"].Value, |
| 136 | Item = settlementPayment |
| 137 | }); |
| 138 | } |
| 139 | |
| 140 | // POST: Admin/SettlementPayments/Delete/5 |
| 141 | [HttpPost, ActionName("Delete")] |
| 142 | [ValidateAntiForgeryToken] |
| 143 | public async Task<IActionResult> DeleteConfirmed(Guid id) |
| 144 | { |
| 145 | await _service.DeleteAsync(id); |
| 146 | return RedirectToAction(nameof(Index)); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |