profileShare

rasmusjy / splitapp-backend-modular-monolith

Read-only snapshot

No repository description.

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