public HttpResponseMessage ToggleStaffingSchedule(ToggleStaffingScheduleInput toggleInput) { if (this.ModelState.IsValid) { try { var staffingSchedule = _scheduledTasksService.GetScheduledTaskById(toggleInput.Id); if (staffingSchedule == null) { throw HttpStatusCode.NotFound.AsException(); } if (staffingSchedule.UserId != UserId) { throw HttpStatusCode.Unauthorized.AsException(); } staffingSchedule.Active = toggleInput.Act; _scheduledTasksService.SaveScheduledTask(staffingSchedule); return(Request.CreateResponse(HttpStatusCode.Created)); } catch (Exception ex) { Logging.LogException(ex); throw HttpStatusCode.InternalServerError.AsException(); } } throw HttpStatusCode.BadRequest.AsException(); }
public async Task <ActionResult> ToggleStaffingSchedule(ToggleStaffingScheduleInput toggleInput, CancellationToken cancellationToken) { if (this.ModelState.IsValid) { try { var staffingSchedule = await _scheduledTasksService.GetScheduledTaskByIdAsync(toggleInput.Id); if (staffingSchedule == null) { return(NotFound()); } if (staffingSchedule.UserId != UserId) { return(Unauthorized()); } staffingSchedule.Active = toggleInput.Act; var task = await _scheduledTasksService.SaveScheduledTaskAsync(staffingSchedule); return(CreatedAtAction(nameof(ToggleStaffingSchedule), new { id = task.IdValue }, task)); } catch (Exception ex) { Logging.LogException(ex); return(BadRequest()); } } return(BadRequest()); }