public IHttpActionResult PutPercentBodyFatModel(int id, PercentBodyFatModel percentBodyFatModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != percentBodyFatModel.ID) { return(BadRequest()); } db.Entry(percentBodyFatModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PercentBodyFatModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetPercentBodyFatModel(int id) { PercentBodyFatModel percentBodyFatModel = db.PercentBodyFats.Find(id); string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; if (percentBodyFatModel == null || percentBodyFatModel.Owner != owner) { return(NotFound()); } return(Ok(percentBodyFatModel)); }
public IHttpActionResult PostPercentBodyFatModel(PercentBodyFatModel percentBodyFatModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; percentBodyFatModel.Owner = owner; //percentBodyFatModel.Logged = DateTime.UtcNow; db.PercentBodyFats.Add(percentBodyFatModel); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = percentBodyFatModel.ID }, percentBodyFatModel)); }