Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ public IActionResult AddSuperviseDelegate(MyStaffListViewModel model)
var adminId = GetAdminID();
var centreId = GetCentreId();
var supervisorEmail = GetUserEmail();
AddSupervisorDelegateAndReturnId(adminId, model.DelegateEmail ?? String.Empty, supervisorEmail, centreId);

ModelState.Remove("Page");
if (ModelState.IsValid)
{
AddSupervisorDelegateAndReturnId(adminId, model.DelegateEmail ?? String.Empty, supervisorEmail, centreId);
return RedirectToAction("MyStaffList", model.Page);
}
else
{
ModelState.ClearErrorsForAllFieldsExcept("DelegateEmail");
Expand All @@ -121,19 +125,27 @@ public IActionResult AddMultipleSuperviseDelegates(AddMultipleSupervisorDelegate
var adminId = GetAdminID();
var centreId = GetCentreId();
var supervisorEmail = GetUserEmail();
var delegateEmailsList = NewlineSeparatedStringListHelper.SplitNewlineSeparatedList(model.DelegateEmails);
foreach (var delegateEmail in delegateEmailsList)

if (ModelState.IsValid)
{
if (delegateEmail.Length > 0)
var delegateEmailsList = NewlineSeparatedStringListHelper.SplitNewlineSeparatedList(model.DelegateEmails);
foreach (var delegateEmail in delegateEmailsList)
{
if (RegexStringValidationHelper.IsValidEmail(delegateEmail))
if (delegateEmail.Length > 0)
{
AddSupervisorDelegateAndReturnId(adminId, delegateEmail, supervisorEmail, centreId);
if (RegexStringValidationHelper.IsValidEmail(delegateEmail))
{
AddSupervisorDelegateAndReturnId(adminId, delegateEmail, supervisorEmail, centreId);
}
}
}
return RedirectToAction("MyStaffList");
}
else
{
ModelState.ClearErrorsForAllFieldsExcept("DelegateEmails");
return View("AddMultipleSupervisorDelegates", model);
}

return RedirectToAction("MyStaffList");
}

private void AddSupervisorDelegateAndReturnId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public static class CommonValidationErrorMessages
public const string TooLongEmail = "Email must be 255 characters or fewer";
public const string InvalidEmail = "Enter an email in the correct format, like name@example.com";
public const string WhitespaceInEmail = "Email must not contain any whitespace characters";
public const string EmailsRegexWithNewLineSeparator = @"(([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)(\s*\r\n\s*|\s*$))*";
public const string InvalidMultiLineEmail = "Enter an email in the correct format (like name@example.com). Note: Each email address should be on separate lines";

public const string PasswordRegex = @"(?=.*?[^\w\s])(?=.*?[0-9])(?=.*?[A-Za-z]).*";
public const string PasswordInvalidCharacters = "Password must contain at least 1 letter, 1 number and 1 symbol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace DigitalLearningSolutions.Web.ViewModels.Supervisor
using DigitalLearningSolutions.Web.Helpers;
using System.ComponentModel.DataAnnotations;

namespace DigitalLearningSolutions.Web.ViewModels.Supervisor
{
public class AddMultipleSupervisorDelegatesViewModel
{
Expand All @@ -7,6 +10,9 @@ public AddMultipleSupervisorDelegatesViewModel(string? delegateEmails)
{
DelegateEmails = delegateEmails;
}

[Required(ErrorMessage = "Enter an email")]
[RegularExpression(CommonValidationErrorMessages.EmailsRegexWithNewLineSeparator, ErrorMessage = CommonValidationErrorMessages.InvalidMultiLineEmail)]
public string? DelegateEmails { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<form method="post" novalidate>
<vc:text-area asp-for="DelegateEmails"
label="User email addresses"
populate-with-current-value="false"
populate-with-current-value="true"
rows="8"
spell-check="false"
hint-text="Provide the work email address of each member of staff to add to your supervision list on a separate line."
Expand Down