public IActionResult SupervisorReviewTimesheet(SupervisorDetailTimeSheetViewModel model) { if (ModelState.IsValid) { if (model.Approved == ApprovalType.Denied) { if (model.ReasonDenied != null) { var timesheet = _context.TimeSheets.Find(model.TimesheetId); timesheet.Approved = model.Approved; timesheet.ReasonDenied = model.ReasonDenied; _context.TimeSheets.Update(timesheet); _context.SaveChanges(); } else { //Reason Denied has to be there if denied return(View(model)); } } else { var timesheet = _context.TimeSheets.Find(model.TimesheetId); timesheet.Approved = model.Approved; _context.TimeSheets.Update(timesheet); _context.SaveChanges(); return(View("Index")); } } return(RedirectToAction("SupervisorsPendingTimeSheets")); }
public IActionResult SupervisorReviewTimesheet(int id) { var supervisor = _userManager.FindByNameAsync(User.Identity.Name).Result; var timesheet = _context.TimeSheets.Find(id); var timesheetUser = _userManager.FindByIdAsync(timesheet.UserId).Result; var timeWorked = TimeSheetTimeSpent(timesheet); var amountMade = TimeSheetAmountMade(timesheet, timeWorked); var model = new SupervisorDetailTimeSheetViewModel { StartDate = timesheet.StartDate, EndDate = timesheet.EndDate, ExemptFromOvertime = timesheet.ExemptFromOvertime, Approved = timesheet.Approved, AmountMade = amountMade, TimeWorked = timeWorked, ReasonDenied = timesheet.ReasonDenied ?? "Not Denied Yet", TimesheetId = timesheet.Id, User = timesheetUser.Email }; return(View(model)); }