public IHttpActionResult GetActionQSE(int id) { ActionQSE actionqse = db.ActionQSEs.Find(id); if (actionqse == null) { return(NotFound()); } return(Ok(actionqse)); }
// POST api/ActionQSE public HttpResponseMessage PostActionQSE(ActionQSE actionQSE) { actionQSE.Responsable = PersonneAnnuaireService.GetPersonneFromAllAnnuaireOrCreate(actionQSE.Responsable.Nom, actionQSE.Responsable.Prenom, actionQSE.ResponsableId, db); if (actionQSE.VerificateurId != 0 && actionQSE.VerificateurId != null) { actionQSE.Verificateur = PersonneAnnuaireService.GetPersonneFromAllAnnuaireOrCreate(actionQSE.Verificateur.Nom, actionQSE.Verificateur.Prenom, actionQSE.VerificateurId, db); } db.ActionQSEs.Add(actionQSE); db.SaveChanges(); if (actionQSE.CauseQSEId != 0 && actionQSE.CauseQSEId != null) { FicheSecuriteServices.FicheSecuriteOpenOrClose(actionQSE); } return(Request.CreateResponse <ActionQSE>(HttpStatusCode.OK, actionQSE, Configuration.Formatters.JsonFormatter)); }
public IHttpActionResult DeleteActionQSE(int id) { ActionQSE actionqse = db.ActionQSEs.Find(id); if (actionqse == null) { return(NotFound()); } db.ActionQSEs.Remove(actionqse); db.SaveChanges(); if (actionqse.CauseQSEId != 0 && actionqse.CauseQSEId != null) { FicheSecuriteServices.FicheSecuriteOpenOrClose(actionqse); } return(Ok(actionqse)); }
public ActionQSE Get(Int32 id) { ActionQSE ActionQSE = _db.ActionQSEs.SingleOrDefault(r => r.ActionQSEId == id); return(ActionQSE); }
// PUT api/ActionQSE/5 public HttpResponseMessage PutActionQSE(int id, ActionQSE actionqse) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, Configuration.Formatters.JsonFormatter)); } if (id != actionqse.ActionQSEId) { return(Request.CreateResponse(HttpStatusCode.BadRequest, Configuration.Formatters.JsonFormatter)); } var currentAction = db.ActionQSEs.Find(actionqse.ActionQSEId); db.Entry(currentAction).CurrentValues.SetValues(actionqse); db.Entry(currentAction).State = EntityState.Modified; try { if (currentAction.ResponsableId == 0) { currentAction.Responsable = PersonneAnnuaireService.GetPersonneFromAllAnnuaireOrCreate( currentAction.Responsable.Nom, currentAction.Responsable.Prenom, currentAction.ResponsableId, db ); } if (currentAction.VerificateurId == 0) { currentAction.Responsable = PersonneAnnuaireService.GetPersonneFromAllAnnuaireOrCreate( currentAction.Responsable.Nom, currentAction.Responsable.Prenom, currentAction.ResponsableId, db ); } db.SaveChanges(); if (currentAction.CauseQSEId != 0 && currentAction.CauseQSEId != null) { FicheSecuriteServices.FicheSecuriteOpenOrClose(currentAction); } } catch (DbUpdateConcurrencyException) { if (!ActionQSEExists(id)) { return(Request.CreateResponse(HttpStatusCode.NotFound, Configuration.Formatters.JsonFormatter)); } else { throw; } } // Si l'action appartient à une FS (et non une NC) >> On passe aussi la FS pour chercher la mise à jour de l'état de la FS (Workflow) dans la View. if (currentAction.CauseQSEId != null) { Dictionary <string, Object> Response = new Dictionary <string, Object>(); Response.Add("FicheSecurite", currentAction.CauseQS.FicheSecurite); Response.Add("Action", currentAction); return(Request.CreateResponse(HttpStatusCode.OK, Response, Configuration.Formatters.JsonFormatter)); } return(Request.CreateResponse(HttpStatusCode.OK, currentAction, Configuration.Formatters.JsonFormatter)); //StatusCode(HttpStatusCode.NoContent, currentAction, Configuration.Formatters.JsonFormatter); }