// POST api/PostureLevel public IHttpActionResult Post([FromBody] PostureLevelViewModel model) { try { PostureLevelsService.AddUserPostureLevel(model, User.Identity.GetUserId()); } catch (NullReferenceException ex) { return(BadRequest()); } return(Ok()); }
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(); }