public IHttpActionResult Post(CreateRecipeRating rating) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateRatingService(); if (!service.CreateRecipeRating(rating)) { return(InternalServerError()); } return(Ok()); }
public bool CreateRecipeRating(CreateRecipeRating model) { var entity = new RecipeRating() { Rater = _userId, RecipeId = model.RecipeId, Rating = model.Rating }; using (var ctx = new ApplicationDbContext()) { ctx.RecipeRatings.Add(entity); return(ctx.SaveChanges() == 1); } }