public IHttpActionResult Get(int Id, string type = "BY_ID") { try { if (type == TYPE_BY_ID) { Scheduling scheduling = new SchedulingDAL().Get(Id); if (scheduling == null) { return(NotFound()); } return(Ok(scheduling)); } else if (type == TYPE_BY_CLIENT) { IList <Scheduling> list = new SchedulingDAL().ListByClient(Id); return(Ok(list)); } else { return(BadRequest()); } } catch (Exception) { return(BadRequest()); } }
public IHttpActionResult Put(int Id, [FromBody] Scheduling scheduling) { try { if (Id != scheduling.Id) { return(BadRequest("Os IDs de identificação não podem ser diferentes")); } SchedulingDAL schedulingDAL = new SchedulingDAL(); Scheduling schedulingOld = schedulingDAL.GetSimple(scheduling.Id); if (schedulingOld == null) { return(NotFound()); } else if (scheduling.HomeId != schedulingOld.HomeId) { return(BadRequest("O empreendimento não pode ser alterado.")); } bool isUpdate = (scheduling.EmployeeId == schedulingOld.EmployeeId); ModelErrors(scheduling, isUpdate); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } schedulingOld.SchedulingDate = scheduling.SchedulingDate; schedulingOld.EmployeeId = scheduling.EmployeeId; schedulingOld.SchedulingStatusId = scheduling.SchedulingStatusId; schedulingOld.SchedulingTypeId = scheduling.SchedulingTypeId; schedulingOld.ServiceId = scheduling.ServiceId; schedulingDAL.Update(schedulingOld); return(Ok()); } catch (Exception) { return(BadRequest()); } }
public IHttpActionResult Delete(int Id) { try { SchedulingDAL schedulingDAL = new SchedulingDAL(); Scheduling scheduling = schedulingDAL.GetSimple(Id); if (scheduling == null) { return(NotFound()); } scheduling.SchedulingStatusId = SchedulingStatus.CANCELED; schedulingDAL.Update(scheduling); return(Ok()); } catch (Exception) { return(BadRequest()); } }