public async Task <ActionResult> EditePost(EditePostViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var post = await _services.GetPost(model.id); if (post == null) { return(NotFound()); } if (model.NewImage != null) { _services.DeleteImage(post.imageName); post.imageName = await _services.UploadImage(model.NewImage); } post.Title = model.Title; post.Description = model.Description; post.AltImage = model.AltImage; post.Text = model.Text; post.Tags = model.Tages; post.Category = model.Category; await _services.UpdatePost(post); return(Redirect("/")); }
public async Task <IActionResult> EditPost(int id) { Publication post = _publicationService.GetPostDB(id); if (post == null) { return(NotFound()); } EditePostViewModel model = new EditePostViewModel { Id = post.Id, PublicationName = post.PublicationName, PublicationText = post.PublicationText, Discription = post.Discription, TopicName = _topicService.GetTopicName(post.TopicId) }; return(View(model)); }
public async Task <IActionResult> EditPost(EditePostViewModel model) { if (ModelState.IsValid) { Publication post = _publicationService.GetPostDB(model.Id); if (post != null) { post.PublicationName = model.PublicationName; post.PublicationText = model.PublicationText; post.Discription = model.Discription; post.TopicId = _topicService.GetTopicDB(model.TopicName).Id; post.Topic = _topicService.GetTopicDB(model.TopicName); _publicationService.UpdatePost(post); return(RedirectToAction("AllPosts")); } } return(View(model)); }
public async Task <ActionResult> EditePost(int id) { var post = await _services.GetPost(id); if (post == null) { return(NotFound()); } var model = new EditePostViewModel { AltImage = post.AltImage, Category = post.Category, Description = post.Description, id = post.PostId, ImageName = post.imageName, Tages = post.Tags, Text = post.Text, Title = post.Title }; return(View(model)); }