Skip to content

Commit

Permalink
added view model for actions taken
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-1010 committed Nov 17, 2024
1 parent 83cd3cf commit 3151c19
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gordon360/Controllers/LostAndFoundController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ActionResult<int> CreateMissingItemReport([FromBody] MissingItemReportVie
/// <returns>ObjectResult - the http status code result of the action</returns>
[HttpPost]
[Route("missingitem/{id}/actionTaken")]
public ActionResult<int> CreateActionTaken(int id, [FromBody] ActionsTaken ActionsTaken)
public ActionResult<int> CreateActionTaken(int id, [FromBody] ActionsTakenViewModel ActionsTaken)
{
int ID = lostAndFoundService.CreateActionTaken(id, ActionsTaken);

Expand Down
4 changes: 2 additions & 2 deletions Gordon360/Documentation/Gordon360.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Gordon360/Models/ViewModels/ActionsTakenViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Gordon360.Models.ViewModels
{
public class ActionsTakenViewModel
{
public int ID { get; set; }
public int missingID { get; set; }
public string action { get; set; }
public DateTime actionDate { get; set; }
public string actionNote { get; set; }
public string submitterID { get; set; }

public static implicit operator ActionsTakenViewModel(CCT.ActionsTaken a) => new ActionsTakenViewModel
{
ID = a.ID,
missingID = a.missingID,
action = a.action,
actionDate = a.actionDate,
actionNote = a.actionNote,
submitterID = a.submitterID,
};
}
}
7 changes: 1 addition & 6 deletions Gordon360/Services/LostAndFoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public int CreateMissingItemReport(MissingItemReportViewModel reportDetails, str
}

/// <param name="id">The id</param>
public int CreateActionTaken(int id, ActionsTaken ActionsTaken)
public int CreateActionTaken(int id, ActionsTakenViewModel ActionsTaken)
{
var newActionTaken = context.ActionsTaken.Add(new ActionsTaken
{
Expand All @@ -95,11 +95,6 @@ public int CreateActionTaken(int id, ActionsTaken ActionsTaken)

context.SaveChangesAsync();

if (newActionTaken == null || newActionTaken?.Entity?.ID == 0)
{
throw new ResourceCreationException() { ExceptionMessage = "The report could not be saved." };
}

int actionTakenID = newActionTaken.Entity.ID;

return actionTakenID;
Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public interface IHousingService
public interface ILostAndFoundService
{
public int CreateMissingItemReport(MissingItemReportViewModel reportDetails, string username);
public int CreateActionTaken(int id, ActionsTaken ActionsTaken);
public int CreateActionTaken(int id, ActionsTakenViewModel ActionsTaken);
IEnumerable<MissingItemReportViewModel> GetMissingItems(string username);
IEnumerable<MissingItemReportViewModel> GetMissingItemsAll();
IEnumerable<FoundItems> GetFoundItems();
Expand Down

0 comments on commit 3151c19

Please sign in to comment.