public async Task <ActionResult> UpdateInterventionStatus([FromRoute] long id, [FromBody] UpdateInterventionsPayload payload) { var myIntervention = await this.context.Interventions.FindAsync(id); if (myIntervention == null) { return(NotFound()); } if (payload.status.Equals("InProgress", System.StringComparison.InvariantCultureIgnoreCase)) { myIntervention.start_date = System.DateTime.Now; myIntervention.status = "InProgress"; } else if (payload.status.Equals("Completed", System.StringComparison.InvariantCultureIgnoreCase)) { myIntervention.end_date = System.DateTime.Now; myIntervention.status = "Completed"; } else { return(BadRequest()); } this.context.Interventions.Update(myIntervention); await this.context.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult <Intervention> > UpdateInterventionsStatus([FromRoute] long id, [FromBody] UpdateInterventionsPayload payload) { var myIntervention = await this.context.Interventions.FindAsync(id); if (myIntervention == null) { return(NotFound()); } if (payload.status == "InProgress") { myIntervention.status = payload.status; myIntervention.start_date = DateTime.Now; } else if (payload.status == "Completed") { myIntervention.status = payload.status; myIntervention.end_date = DateTime.Now; } else { return(BadRequest()); } this.context.Interventions.Update(myIntervention); await this.context.SaveChangesAsync(); return(await this.context.Interventions.FindAsync(id)); }