// PUT api/timesheets/5 public HttpResponseMessage Put(int id, [FromBody] Timesheet timesheet) { var opStatus = _TimesheetRepository.UpdateTimesheet(timesheet); if (!opStatus.Status) { throw new HttpResponseException(Request.CreateResponse <OperationStatus>(HttpStatusCode.NotFound, opStatus)); } //Generate success response var response = Request.CreateResponse <OperationStatus>(HttpStatusCode.OK, opStatus); return(response); }
public IActionResult Put(int id, [FromBody] TimesheetDto ts) { Timesheet timesheet = _timeSheetRepository.GetTimsheetById(ts.Id); if (ts.Status.Equals(TimesheetStatus.Approved.ToString())) { _logger.LogWarning($"About to approve timesheet for id: {ts.Id}"); timesheet.Approved(_mediator); } else if (ts.Status.Equals(TimesheetStatus.Rejected.ToString())) { _logger.LogWarning($"About to reject timesheet for id: {ts.Id}"); timesheet.Rejected(_mediator); } else if (ts.Status.Equals(TimesheetStatus.Submitted.ToString())) { _logger.LogWarning($"Timesheet Submitted for id: {ts.Id}"); timesheet.Submitted(_mediator); } _timeSheetRepository.UpdateTimesheet(timesheet); return(Ok()); }
public IActionResult End(int id) { var timesheet = _timesheetRepository.GetTimesheet(id); if (timesheet == null || timesheet.UserId != GetUserId() || timesheet.Absence) { return(BadRequest()); } timesheet.EndTime = DateTime.Now.TimeOfDay; _timesheetRepository.UpdateTimesheet(timesheet); var result = _mapper.Map <TimesheetResponse>(timesheet); CalculateFlexTime(result); return(Ok(result)); }
public async Task <IActionResult> PutTimesheet(long timesheetId, [FromBody] Timesheet timesheet) { if (timesheetId != timesheet.Id || timesheet.IsDeleted) { return(BadRequest()); } try { await _timesheetRepository.UpdateTimesheet(timesheet); } catch (KeyNotFoundException) { return(NotFound()); } catch (Exception) { throw; } return(NoContent()); }