Skip to content

Commit

Permalink
working post request
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-1010 committed Nov 18, 2024
1 parent 3151c19 commit 898def3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Gordon360/Models/ViewModels/ActionsTakenViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ namespace Gordon360.Models.ViewModels
{
public class ActionsTakenViewModel
{
public int ID { get; set; }
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 string? submitterID { get; set; }
public string username { get; set; }

public static implicit operator ActionsTakenViewModel(CCT.ActionsTaken a) => new ActionsTakenViewModel
{
Expand All @@ -18,7 +19,6 @@ public class ActionsTakenViewModel
action = a.action,
actionDate = a.actionDate,
actionNote = a.actionNote,
submitterID = a.submitterID,
};
}
}
25 changes: 22 additions & 3 deletions Gordon360/Services/LostAndFoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,35 @@ public int CreateMissingItemReport(MissingItemReportViewModel reportDetails, str
/// <param name="id">The id</param>
public int CreateActionTaken(int id, ActionsTakenViewModel ActionsTaken)
{
var account = context.ACCOUNT.FirstOrDefault(x => x.AD_Username == ActionsTaken.username);

string idNum;

if (account != null)
{
idNum = account.gordon_id;
}
else
{
throw new ResourceCreationException() { ExceptionMessage = "No account could be found for the user." };
}

var newActionTaken = context.ActionsTaken.Add(new ActionsTaken

{
missingID = ActionsTaken.missingID,
missingID = id,
action = ActionsTaken.action,
actionNote = ActionsTaken.actionNote,
actionDate = ActionsTaken.actionDate,
submitterID = ActionsTaken.submitterID,
submitterID = idNum
});

context.SaveChangesAsync();
context.SaveChanges();

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

int actionTakenID = newActionTaken.Entity.ID;

Expand Down

0 comments on commit 898def3

Please sign in to comment.