Ejemplo n.º 1
0
 public IActionResult Edit(PostEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (_postService.AddOrUpdate(model))
         {
             return(RedirectToAction("MyPosts", new { @area = GlobalConstants.AdminArea }));
         }
     }
     return(View(model));
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditPost(PostFormViewModel post)
        {
            if (!ModelState.IsValid)
            {
                return(View(post));
            }

            var addedPost = await _postService.AddOrUpdate(new PostDto
            {
                Id          = post.Id,
                Author      = User.Identity.Name,
                Title       = post.Title,
                Content     = post.Content,
                IsPublished = post.IsPublished,
                Categories  = post.Categories?
                              .Split(" ")
                              .Where(c => !string.IsNullOrWhiteSpace(c))
                              .Select(c => new CategoryDto {
                    Name = c
                })
            });

            return(RedirectToAction(nameof(Post), new { id = addedPost.Id }));
        }