예제 #1
0
        public async Task <IActionResult> Edit(PostEditInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            await this.postsService.EditPostAsync(input);

            return(this.RedirectToAction(nameof(this.ById), new { id = input.Id }));
        }
예제 #2
0
        public async Task <IActionResult> Edit(PostEditInputModel model, int postId)
        {
            var result = await this.postsService.UpdatePost(model, postId);

            if (!result)
            {
                return(this.Redirect("Error"));
            }

            return(this.RedirectToAction(nameof(this.Index), new { postId = postId }));
        }
예제 #3
0
        public async Task EditPostAsync(PostEditInputModel input)
        {
            var post = this.postsRepository
                       .All()
                       .Where(x => x.Id == input.Id)
                       .FirstOrDefault();

            post.Title   = input.Title;
            post.Content = input.Content;

            this.postsRepository.Update(post);
            await this.postsRepository.SaveChangesAsync();
        }
예제 #4
0
        public async Task <bool> UpdatePost(PostEditInputModel model, int postId)
        {
            var post = await this.postsRepo.All().FirstOrDefaultAsync(x => x.Id == postId);

            if (post == null)
            {
                return(false);
            }

            post.Content = model.Content;
            post.Privacy = model.Status;

            this.postsRepo.Update(post);
            await this.postsRepo.SaveChangesAsync();

            return(true);
        }
예제 #5
0
        public async Task <IActionResult> SubmitEdit(PostEditInputModel input)
        {
            if
            (input.AuthorUserName != this.User.Identity.Name)
            {
                return(this.BadRequest());
            }

            var post = this.postsRepository.All().Where(x => x.Id == input.Id).FirstOrDefault();

            post.CategoryId = input.CategoryId;
            post.Content    = input.Content;
            post.Title      = input.Title;
            this.postsRepository.Update(post);
            await this.postsRepository.SaveChangesAsync();

            return(this.RedirectToAction(nameof(this.ById), new { id = post.Id }));
        }