// POST api/PostureLevel
        public IHttpActionResult Post([FromBody] PostureLevelViewModel model)
        {
            try
            {
                PostureLevelsService.AddUserPostureLevel(model, User.Identity.GetUserId());
            }
            catch (NullReferenceException ex)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Esempio n. 2
0
        public static void AddUserPostureLevel(PostureLevelViewModel model, string userId)
        {
            if (context.Users.Find(model.UserId) == null)
            {
                throw new NullReferenceException();
            }

            context.PostureLevels.Add(new PostureLevel
            {
                Date   = DateTime.Now,
                Level  = model.Level,
                UserId = model.UserId,
            });

            context.SaveChanges();
        }