Skip to content

Commit 56b58d4

Browse files
author
Michael Caltagirone
committed
Added alert when invoice string length is greater than 21 characters.
1 parent c32949a commit 56b58d4

File tree

3 files changed

+80
-72
lines changed

3 files changed

+80
-72
lines changed

src/PaymentPortal/Controllers/PaymentsController.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,16 @@ public ActionResult Login(LoginModel model)
110110
/// </summary>
111111
/// <returns></returns>
112112
[Authorize]
113-
public ActionResult SelectInvoices()
113+
public ActionResult SelectInvoices(string errorMessage)
114114
{
115115
try
116116
{
117117
int ContIndex = Convert.ToInt32(User.Identity.Name);
118118
var model = new SelectInvoicesModel
119119
{
120120
Client = engineService.GetClientDetails(ContIndex),
121-
Invoices = engineService.GetInvoiceDetails(ContIndex)
121+
Invoices = engineService.GetInvoiceDetails(ContIndex),
122+
ErrorMessage = errorMessage
122123
};
123124
return View(model);
124125
}
@@ -158,13 +159,12 @@ public ActionResult Goodbye()
158159
[ValidateAntiForgeryToken]
159160
[HttpPost]
160161
public async Task<ActionResult> PayNow(string[] Invoices)
161-
{
162+
{
162163
try
163164
{
164-
if (Invoices.Sum(i => i.Length) > 21)
165-
{
166-
ModelState.AddModelError("", "Too many invoices selected. Sorry, but we cannot process all those invoices at one time.");
167-
return View("SelectInvoices");
165+
if (Invoices.Select(i => i.Length).Sum() > 21)
166+
{
167+
return RedirectToAction("SelectInvoices", new { errorMessage = "Too many invoices selected. Sorry, but we cannot process all those invoices at one time." });
168168
}
169169

170170
int ContIndex = Convert.ToInt32(User.Identity.Name);
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
using PEPaymentProvider;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Web;
6-
7-
namespace PaymentPortal.Models
8-
{
9-
public class SelectInvoicesModel
10-
{
11-
public ClientDetails Client { get; set; }
12-
13-
public IEnumerable<InvoiceDetails> Invoices { get; set; }
14-
15-
}
1+
using PEPaymentProvider;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Web;
6+
7+
namespace PaymentPortal.Models
8+
{
9+
public class SelectInvoicesModel
10+
{
11+
public ClientDetails Client { get; set; }
12+
13+
public IEnumerable<InvoiceDetails> Invoices { get; set; }
14+
15+
public string ErrorMessage { get; set; }
16+
}
1617
}
Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,57 @@
1-
@model PaymentPortal.Models.SelectInvoicesModel
2-
<div class="row">
3-
<div class="col-md-3">
4-
<img src="@Html.Raw(System.Configuration.ConfigurationManager.AppSettings["FirmLogo"])" alt="@Html.Raw(System.Configuration.ConfigurationManager.AppSettings["FirmName"])" class="img-responsive" />
5-
</div>
6-
<div class="col-md-9 text-right">
7-
<blockquote>
8-
<div class="h6">Client: @Model.Client.ClientCode</div>
9-
<address>
10-
<strong>@Model.Client.ClientName</strong><br/>
11-
@Model.Client.ContAddress<br />
12-
@Model.Client.ContCity, @Model.Client.ContCounty, @Model.Client.ContPostCode
13-
</address>
14-
</blockquote>
15-
</div>
16-
</div>
17-
<hr />
18-
@Html.ValidationSummary()
19-
@using (Html.BeginForm("PayNow", "Payments", FormMethod.Post, new { @class = "form-horizontal" }))
20-
{
21-
<fieldset>
22-
@Html.AntiForgeryToken()
23-
<legend>Select Invoices to Pay Now</legend>
24-
<div class="form-group">
25-
<div class="col-sm-offset-4 col-sm-8">
26-
<button type="submit" class="btn btn-primary">Pay Selected Invoices Now</button>
27-
</div>
28-
</div>
29-
@foreach (var inv in Model.Invoices)
30-
{
31-
var ttl = inv.CurSymbol + inv.DebtForTotal.ToString("N2");
32-
var outstanding = inv.CurSymbol + inv.DebtForUnpaid.ToString("N2");
33-
<div class="col-sm-4">
34-
<div class="checkbox">
35-
<label>
36-
<input type="checkbox" checked name="Invoices" value="@inv.DebtTranRefAlpha" />
37-
@inv.TransactionType #@inv.DebtTranRefAlpha for @ttl on @inv.DebtTranDate.ToShortDateString()<br />
38-
<strong>@outstanding outstanding</strong>
39-
</label>
40-
</div>
41-
</div>
42-
}
43-
<div class="form-group">
44-
<div class="col-sm-offset-4 col-sm-8">
45-
<button type="submit" class="btn btn-primary">Pay Selected Invoices Now</button>
46-
</div>
47-
</div>
48-
</fieldset>
49-
}
50-
1+
@model PaymentPortal.Models.SelectInvoicesModel
2+
<div class="row">
3+
<div class="col-md-3">
4+
<img src="@Html.Raw(System.Configuration.ConfigurationManager.AppSettings["FirmLogo"])" alt="@Html.Raw(System.Configuration.ConfigurationManager.AppSettings["FirmName"])" class="img-responsive" />
5+
</div>
6+
<div class="col-md-9 text-right">
7+
<blockquote>
8+
<div class="h6">Client: @Model.Client.ClientCode</div>
9+
<address>
10+
<strong>@Model.Client.ClientName</strong><br />
11+
@Model.Client.ContAddress<br />
12+
@Model.Client.ContCity, @Model.Client.ContCounty, @Model.Client.ContPostCode
13+
</address>
14+
</blockquote>
15+
</div>
16+
</div>
17+
<hr />
18+
@Html.ValidationSummary()
19+
@using (Html.BeginForm("PayNow", "Payments", FormMethod.Post, new { @class = "form-horizontal" }))
20+
{
21+
<fieldset>
22+
@Html.AntiForgeryToken()
23+
<legend>Select Invoices to Pay Now</legend>
24+
@if (!string.IsNullOrWhiteSpace(Model.ErrorMessage))
25+
{
26+
<div class="alert alert-danger alert-dismissible" role="alert">
27+
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
28+
<strong>@Model.ErrorMessage</strong>
29+
</div>
30+
}
31+
<div class="form-group">
32+
<div class="col-sm-offset-4 col-sm-8">
33+
<button type="submit" class="btn btn-primary">Pay Selected Invoices Now</button>
34+
</div>
35+
</div>
36+
@foreach (var inv in Model.Invoices)
37+
{
38+
var ttl = inv.CurSymbol + inv.DebtForTotal.ToString("N2");
39+
var outstanding = inv.CurSymbol + inv.DebtForUnpaid.ToString("N2");
40+
<div class="col-sm-4">
41+
<div class="checkbox">
42+
<label>
43+
<input type="checkbox" checked name="Invoices" value="@inv.DebtTranRefAlpha" />
44+
@inv.TransactionType #@inv.DebtTranRefAlpha for @ttl on @inv.DebtTranDate.ToShortDateString()<br />
45+
<strong>@outstanding outstanding</strong>
46+
</label>
47+
</div>
48+
</div>
49+
}
50+
<div class="form-group">
51+
<div class="col-sm-offset-4 col-sm-8">
52+
<button type="submit" class="btn btn-primary">Pay Selected Invoices Now</button>
53+
</div>
54+
</div>
55+
</fieldset>
56+
}
57+

0 commit comments

Comments
 (0)