public ActionResult SendPost(SendPostViewModel viewModel) { if (viewModel.Content == null || !_postValidator.IsValid(viewModel.Content)) { TempData.Add("SendPostContent", viewModel.Content); TempData.Add("SendPostError", "The post has invalid content."); } else if (_topicService.ValidateTopicAndCategoryAlias(viewModel.TopicAlias, viewModel.CategoryAlias)) { var postDTO = Mapper.Map <NewPostDTO>(viewModel); postDTO.AuthorID = _authService.GetCurrentUser().ID; _topicService.AddPost(viewModel.TopicAlias, postDTO); } return(RedirectToAction("Index", new { categoryAlias = viewModel.CategoryAlias, topicAlias = viewModel.TopicAlias })); }
public async Task <ActionResult> AddPost(CreatePostModel model) { var post = new PostModel { TopicId = model.TopicId, AttachedFiles = model.AttachedFiles.Select(t => new FileModel { Data = t.ToByteArray(), FileName = t.FileName }).ToArray(), Content = model.Text, AuthorId = UserData.Id }; await _service.AddPost(post); return(RedirectToAction("Topic", new { topicId = model.TopicId })); }