Example #1
0
        public async Task <ActionResult <BlogPostExportModel> > Patch([FromForm] BlogPostEditLikesInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            var result = await this.blogPostService.EditLikesAsync(input);

            return(this.Ok(result));
        }
        public async Task <int> EditLikesAsync(BlogPostEditLikesInputModel input)
        {
            var entity = await this.blogPostsRepository
                         .All()
                         .FirstOrDefaultAsync(x => x.Id == input.Id);

            entity.Likes = input.Likes;

            await this.blogPostsRepository.SaveChangesAsync();

            return(entity.Likes);
        }