public HttpResponseMessage DeleteStaffingSchedule(int staffingSecheduleId) { if (this.ModelState.IsValid) { try { var staffingSchedule = _scheduledTasksService.GetScheduledTaskById(staffingSecheduleId); if (staffingSchedule == null) { throw HttpStatusCode.NotFound.AsException(); } if (staffingSchedule.UserId != UserId) { throw HttpStatusCode.Unauthorized.AsException(); } _scheduledTasksService.DeleteScheduledTask(staffingSecheduleId); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { Logging.LogException(ex); throw HttpStatusCode.InternalServerError.AsException(); } } throw HttpStatusCode.BadRequest.AsException(); }
public async Task <ActionResult> DeleteStaffingSchedule(int staffingSecheduleId) { if (this.ModelState.IsValid) { try { var staffingSchedule = await _scheduledTasksService.GetScheduledTaskByIdAsync(staffingSecheduleId); if (staffingSchedule == null) { return(NotFound()); } if (staffingSchedule.UserId != UserId) { return(Unauthorized()); } await _scheduledTasksService.DeleteScheduledTask(staffingSecheduleId); return(Ok()); } catch (Exception ex) { Logging.LogException(ex); return(BadRequest()); } } return(BadRequest()); }