コード例 #1
0
ファイル: RatingController.cs プロジェクト: okicks/RBPServer
        public IHttpActionResult Post(CreateRecipeRating rating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateRatingService();

            if (!service.CreateRecipeRating(rating))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
コード例 #2
0
        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);
            }
        }