Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional language and cancel buttons #255

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion FMS/Pages/Cabinets/Add.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
<input asp-for="NewCabinet.FirstFileLabel" class="form-control" placeholder="000-0000" aria-describedby="FileLabelHelpBlock" />
<span asp-validation-for="NewCabinet.FirstFileLabel" class="text-danger"></span>
<small id="FileLabelHelpBlock" class="form-text text-muted">
<em>First File Label</em> is the first/lowest file label in the cabinet.
<em>First File Label</em> is the first/lowest file label in the cabinet. The first three numbers denote the county number.
</small>
</div>
</div>
<hr />
<button type="submit" class="btn btn-primary col-sm-4 col-md-3 mb-3 mb-sm-0">Create New Cabinet</button>
<a asp-page="Index" class="btn btn-outline-secondary col-md-2">Cancel</a>
</form>
</div>
112 changes: 56 additions & 56 deletions FMS/Pages/Cabinets/Add.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
using System.Threading.Tasks;
using FMS.Domain.Dto;
using FMS.Domain.Entities.Users;
using FMS.Domain.Repositories;
using FMS.Platform.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace FMS.Pages.Cabinets
{
[Authorize(Roles = UserRoles.SiteMaintenance)]
public class AddModel : PageModel
{
[BindProperty]
public CabinetEditDto NewCabinet { get; set; }

private readonly ICabinetRepository _repository;
public AddModel(ICabinetRepository repository) => _repository = repository;

public void OnGet()
{
// Method intentionally left empty.
}

public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}

NewCabinet.TrimAll();

if (await _repository.CabinetNameExistsAsync(NewCabinet.Name))
{
ModelState.AddModelError("NewCabinet.Name", "There is already a Cabinet with that name.");
}

if (!Domain.Entities.File.IsValidFileLabelFormat(NewCabinet.FirstFileLabel))
{
ModelState.AddModelError("NewCabinet.FirstFileLabel", "The File Label is invalid.");
}

if (!ModelState.IsValid)
{
return Page();
}

await _repository.CreateCabinetAsync(NewCabinet);

TempData?.SetDisplayMessage(Context.Success,
"Cabinet successfully created. Be sure to check File Label sorting.");
return RedirectToPage("./Details", new {id = NewCabinet.Name});
}
}
using System.Threading.Tasks;
using FMS.Domain.Dto;
using FMS.Domain.Entities.Users;
using FMS.Domain.Repositories;
using FMS.Platform.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace FMS.Pages.Cabinets
{
[Authorize(Roles = UserRoles.SiteMaintenance)]
public class AddModel : PageModel
{
[BindProperty]
public CabinetEditDto NewCabinet { get; set; }
private readonly ICabinetRepository _repository;
public AddModel(ICabinetRepository repository) => _repository = repository;
public void OnGet()
{
// Method intentionally left empty.
}
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
NewCabinet.TrimAll();
if (await _repository.CabinetNameExistsAsync(NewCabinet.Name))
{
ModelState.AddModelError("NewCabinet.Name", "There is already a Cabinet with that name.");
}
if (!Domain.Entities.File.IsValidFileLabelFormat(NewCabinet.FirstFileLabel))
{
ModelState.AddModelError("NewCabinet.FirstFileLabel", "The File Label is invalid.");
}
if (!ModelState.IsValid)
{
return Page();
}
await _repository.CreateCabinetAsync(NewCabinet);
TempData?.SetDisplayMessage(Context.Success,
"Cabinet successfully created. Be sure to check File Label sorting.");
return RedirectToPage("./Details", new {id = NewCabinet.Name});
}
}
}
2 changes: 1 addition & 1 deletion FMS/Pages/Cabinets/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<input asp-for="CabinetEdit.FirstFileLabel" class="form-control" placeholder="000-0000" aria-describedby="FileLabelHelpBlock" />
<span asp-validation-for="CabinetEdit.FirstFileLabel" class="text-danger"></span>
<small id="FileLabelHelpBlock" class="form-text text-muted">
<em>First File Label</em> is the first/lowest file label in the cabinet.
<em>First File Label</em> is the first/lowest file label in the cabinet. The first three numbers denote the county number.
</small>
</div>
</div>
Expand Down
184 changes: 92 additions & 92 deletions FMS/Pages/Cabinets/Edit.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
using System;
using System.Threading.Tasks;
using FMS.Domain.Dto;
using FMS.Domain.Entities.Users;
using FMS.Domain.Repositories;
using FMS.Platform.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;

namespace FMS.Pages.Cabinets
{
[Authorize(Roles = UserRoles.SiteMaintenance)]
public class EditModel : PageModel
{
[BindProperty]
public CabinetEditDto CabinetEdit { get; set; }

[BindProperty]
public Guid Id { get; set; }

public string OriginalCabinetName { get; private set; }

private readonly ICabinetRepository _repository;
public EditModel(ICabinetRepository repository) => _repository = repository;

public async Task<IActionResult> OnGetAsync(Guid? id)
{
if (id == null)
{
return NotFound();
}

var cabinet = await _repository.GetCabinetSummaryAsync(id.Value);

if (cabinet == null)
{
return NotFound();
}

Id = id.Value;
CabinetEdit = new CabinetEditDto(cabinet);
OriginalCabinetName = cabinet.Name;

return Page();
}

public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
OriginalCabinetName = (await _repository.GetCabinetSummaryAsync(Id)).Name;
return Page();
}

CabinetEdit.TrimAll();

if (await _repository.CabinetNameExistsAsync(CabinetEdit.Name, Id))
{
ModelState.AddModelError("CabinetEdit.Name", "There is already a Cabinet with that name.");
}

if (!Domain.Entities.File.IsValidFileLabelFormat(CabinetEdit.FirstFileLabel))
{
ModelState.AddModelError("CabinetEdit.FirstFileLabel", "The File Label is invalid.");
}

if (!ModelState.IsValid)
{
OriginalCabinetName = (await _repository.GetCabinetSummaryAsync(Id)).Name;
return Page();
}

try
{
await _repository.UpdateCabinetAsync(Id, CabinetEdit);
}
catch (DbUpdateConcurrencyException)
{
if (!await _repository.CabinetExistsAsync(Id))
{
return NotFound();
}

throw;
}

TempData?.SetDisplayMessage(Context.Success, "Cabinet successfully updated.");
return RedirectToPage("./Details", new {id = CabinetEdit.Name});
}
}
using System;
using System.Threading.Tasks;
using FMS.Domain.Dto;
using FMS.Domain.Entities.Users;
using FMS.Domain.Repositories;
using FMS.Platform.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace FMS.Pages.Cabinets
{
[Authorize(Roles = UserRoles.SiteMaintenance)]
public class EditModel : PageModel
{
[BindProperty]
public CabinetEditDto CabinetEdit { get; set; }
[BindProperty]
public Guid Id { get; set; }
public string OriginalCabinetName { get; private set; }
private readonly ICabinetRepository _repository;
public EditModel(ICabinetRepository repository) => _repository = repository;
public async Task<IActionResult> OnGetAsync(Guid? id)
{
if (id == null)
{
return NotFound();
}
var cabinet = await _repository.GetCabinetSummaryAsync(id.Value);
if (cabinet == null)
{
return NotFound();
}
Id = id.Value;
CabinetEdit = new CabinetEditDto(cabinet);
OriginalCabinetName = cabinet.Name;
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
OriginalCabinetName = (await _repository.GetCabinetSummaryAsync(Id)).Name;
return Page();
}
CabinetEdit.TrimAll();
if (await _repository.CabinetNameExistsAsync(CabinetEdit.Name, Id))
{
ModelState.AddModelError("CabinetEdit.Name", "There is already a Cabinet with that name.");
}
if (!Domain.Entities.File.IsValidFileLabelFormat(CabinetEdit.FirstFileLabel))
{
ModelState.AddModelError("CabinetEdit.FirstFileLabel", "The File Label is invalid");
}
if (!ModelState.IsValid)
{
OriginalCabinetName = (await _repository.GetCabinetSummaryAsync(Id)).Name;
return Page();
}
try
{
await _repository.UpdateCabinetAsync(Id, CabinetEdit);
}
catch (DbUpdateConcurrencyException)
{
if (!await _repository.CabinetExistsAsync(Id))
{
return NotFound();
}
throw;
}
TempData?.SetDisplayMessage(Context.Success, "Cabinet successfully updated.");
return RedirectToPage("./Details", new {id = CabinetEdit.Name});
}
}
}
2 changes: 1 addition & 1 deletion tests/FMS.App.Tests/Cabinets/CabinetEditTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public async Task OnPost_InvalidFileLabel_ReturnsPageWithInvalidModelState()
result.Should().BeOfType<PageResult>();
pageModel.ModelState.IsValid.ShouldBeFalse();
pageModel.ModelState["CabinetEdit.FirstFileLabel"].Errors[0].ErrorMessage.Should()
.Be("The File Label is invalid.");
.Be("The File Label is invalid");
}
}
}
Loading