コード例 #1
0
        public async Task <ActionResult> UpdateStory(string storyId, UpdateStoryRequestModel model)
        {
            var loggedUser = this.User.GetId();
            var result     = await this.storyService.UpdateStoryAsync(model, storyId, loggedUser);

            if (!result.Success)
            {
                return(BadRequest(result.Errors));
            }

            return(Ok(result.Result));
        }
コード例 #2
0
        public async Task <ResultModel <bool> > UpdateStoryAsync(UpdateStoryRequestModel model, string storyId, string userId)
        {
            var story = await this.dbContext
                        .Stories
                        .Where(s => s.Id == storyId && !s.IsDeleted)
                        .FirstOrDefaultAsync();

            if (story == null)
            {
                return(new ResultModel <bool>
                {
                    Errors = { UserErrors.InvalidUserId }
                });
            }
            var isBanned = await this.userService.IsBanned(story.UserId);

            if (isBanned)
            {
                return(new ResultModel <bool>
                {
                    Errors = { UserErrors.BannedUserCreateStory }
                });
            }
            if (userId != story.UserId)
            {
                return(new ResultModel <bool>
                {
                    Errors = { UserErrors.UserHaveNoPermissionToUpdate }
                });
            }


            // All of them aren't nullable.
            story.Title = model.Title;

            story.Content = model.Content;

            story.PictureUrl = model.PictureUrl;

            story.ModifiedOn = DateTime.UtcNow;

            this.dbContext.Update(story);
            await this.storyCategoriesService.UpdateAsync(storyId, model.Categories);

            return(new ResultModel <bool>
            {
                Result = true,
                Success = true,
            });
        }