profileShare

rasmusjy / splitapp-backend-microservices

Read-only snapshot

No repository description.

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