Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }