Skip to content

Commit

Permalink
Issue#313 Missing validation check (#325)
Browse files Browse the repository at this point in the history
* Add missing validation to CreateStaff

* Added clarification to Staff.Phone property

* Add missing validation checks for staff, steering committee members, and board members

* Add email validation
  • Loading branch information
JoeProgrammer88 authored Aug 25, 2024
1 parent f84b407 commit 611a31a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
53 changes: 41 additions & 12 deletions PC2/Controllers/AboutController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ public IActionResult CreateStaff()
[HttpPost]
public async Task<IActionResult> CreateStaff(Staff staff)
{
await StaffDB.AddStaff(_context, staff);
return RedirectToAction("IndexStaff");
if (ModelState.IsValid)
{
await StaffDB.AddStaff(_context, staff);
return RedirectToAction("IndexStaff");
}
return View(staff);
}

/// <summary>
Expand All @@ -56,8 +60,13 @@ public async Task<IActionResult> EditStaff(int id)
[HttpPost]
public async Task<IActionResult> EditStaff(Staff staff)
{
await StaffDB.SaveChanges(_context, staff);
return RedirectToAction("IndexStaff");
if (ModelState.IsValid)
{
await StaffDB.SaveChanges(_context, staff);
return RedirectToAction("IndexStaff");
}

return View(staff);
}

/// <summary>
Expand Down Expand Up @@ -105,8 +114,13 @@ public IActionResult CreateBoard()
[HttpPost]
public async Task<IActionResult> CreateBoard(Board board)
{
await BoardDB.CreateBoardMember(_context, board);
return RedirectToAction("IndexBoard");
if (ModelState.IsValid)
{
await BoardDB.CreateBoardMember(_context, board);
return RedirectToAction("IndexBoard");
}

return View(board);
}

/// <summary>
Expand All @@ -123,8 +137,13 @@ public async Task<IActionResult> EditBoard(int id)
[HttpPost]
public async Task<IActionResult> EditBoard(Board board)
{
await BoardDB.EditBoardMember(_context, board);
return RedirectToAction("IndexBoard");
if (ModelState.IsValid)
{
await BoardDB.EditBoardMember(_context, board);
return RedirectToAction("IndexBoard");
}

return View(board);
}

/// <summary>
Expand Down Expand Up @@ -172,8 +191,13 @@ public IActionResult CreateSteeringCommittee()
[HttpPost]
public async Task<IActionResult> CreateSteeringCommittee(SteeringCommittee steeringCommittee)
{
await SteeringCommitteeDB.Create(_context, steeringCommittee);
return RedirectToAction("IndexSteeringCommittee");
if (ModelState.IsValid)
{
await SteeringCommitteeDB.Create(_context, steeringCommittee);
return RedirectToAction("IndexSteeringCommittee");
}

return View(steeringCommittee);
}

/// <summary>
Expand All @@ -190,8 +214,13 @@ public async Task<IActionResult> EditSteeringCommittee(int id)
[HttpPost]
public async Task<IActionResult> EditSteeringCommittee(SteeringCommittee steeringCommittee)
{
await SteeringCommitteeDB.EditSteeringCommittee(_context, steeringCommittee);
return RedirectToAction("IndexSteeringCommittee");
if (ModelState.IsValid)
{
await SteeringCommitteeDB.EditSteeringCommittee(_context, steeringCommittee);
return RedirectToAction("IndexSteeringCommittee");
}

return View(steeringCommittee);
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions PC2/Models/People.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Staff : People
{
/// <summary>
/// The staff/person's phone number.
/// Note: Not every staff member has a phone number.
/// </summary>
public string? Phone { get; set; }

Expand All @@ -45,6 +46,8 @@ public class Staff : People
/// <summary>
/// The staff/person's email address.
/// </summary>
[DataType(DataType.EmailAddress)]
[EmailAddress]
public required string Email { get; set; }

/// <summary>
Expand Down

0 comments on commit 611a31a

Please sign in to comment.