public IActionResult Edit(PostEditViewModel model) { if (ModelState.IsValid) { if (_postService.AddOrUpdate(model)) { return(RedirectToAction("MyPosts", new { @area = GlobalConstants.AdminArea })); } } return(View(model)); }
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 })); }