public async Task <IHttpActionResult> Update(Checkpoint checkpoint) { try { //Validation Checkpoint checkpointInDb = Db.Checkpoints.FirstOrDefault(p => p.Id == checkpoint.Id); Validator result = CheckpointValidator.Edit(checkpoint, checkpointInDb); if (!result.Success) { return(BadRequest(result.ErrorMessage)); } checkpointInDb.City = checkpoint.City; checkpointInDb.Country = checkpoint.Country; checkpointInDb.PlaceType = checkpoint.PlaceType; checkpointInDb.TypeOfControl = checkpoint.TypeOfControl; await Db.SaveChangesAsync(); return(Ok("Checkpoint updated successfully")); } catch (DbUpdateConcurrencyException) { return(BadRequest("Checkpoint was changed by another user")); } catch { return(BadRequest()); } }
public async Task <IHttpActionResult> Create(Checkpoint checkpoint) { try { //Validation Validator result = CheckpointValidator.Create(checkpoint); if (!result.Success) { return(BadRequest(result.ErrorMessage)); } //Create Checkpoint Db.Checkpoints.Add(checkpoint); await Db.SaveChangesAsync(); return(Ok("Checkpoint created successfully")); } catch { return(BadRequest("An error has occurred")); } }