public async void AddPost_ShouldPass(string text) { var post = await _repository.AddPost(new Post { Text = text }); Assert.NotNull(post.Id); Assert.Equal(text, post.Text); }
public ActionResult AddPost(string description, string subject, string content) { User user = CheckAuthentication(Request.Cookies[id]); if (user == null) { return(RedirectToAction("Authorize")); } else { if (!string.IsNullOrWhiteSpace(description) && !string.IsNullOrWhiteSpace(subject) && !string.IsNullOrWhiteSpace(content)) { try { Guid subjKey = Guid.Parse(subject); Subject subj = subjectRepo.GetSubject(subjKey); content = Uri.UnescapeDataString(content); Post newPost = new Post(user.UserKey, subj.SubjectKey, description, content); postRepo.AddPost(newPost); return(new EmptyResult()); } catch { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } }
public async Task <Post> AddPost(Post post) { if (post == null) { throw new ArgumentNullException(nameof(post), "Post cannot be null."); } if (string.IsNullOrWhiteSpace(post.Text)) { throw new ArgumentNullException(nameof(post.Text), "Text cannot be null."); } return(await _repository.AddPost(post)); }
public async void AddComment_ShouldPass(string postText, string commentText) { var post = await _postrepository.AddPost(new Post { Text = postText }); var firstComments = post.Comments?.ToList(); await _commentsRepository.AddComment(new Comment { Post = post, Text = commentText }); var secondComments = post.Comments.First(); Assert.Null(firstComments); Assert.Equal(commentText, secondComments.Text); }
public IActionResult AddPost(AddPostVM viewModel, string command) { if (command.Equals("submit2")) { _postsRepository.AddNewCategory(viewModel); return(RedirectToAction("addpost", "admin")); } else { if (!ModelState.IsValid) { return(View(viewModel)); } _postsRepository.AddPost(viewModel, "Administrator"); return(RedirectToAction("index", "home")); } }
public string Posted([FromBody] Posts post) { if (post == null) { return("nulled"); } Posts newPost = postRepo.AddPost(new Posts() { UserId = post.UserId, Locations = post.Locations, PostText = post.PostText, PostDate = post.PostDate, PostTime = post.PostTime, PostImage = post.PostImage }); return(ToJson(new PostComponent(newPost))); }
public async Task AddPost(Guid UserId, string Text) { Post post = new Post() { Author = new User() { Id = UserId }, Text = Text }; if (post.IsValidData()) { await _postsRepository.AddPost(post); } else { throw new ArgumentException("Invalid arguments"); } }
public string AddPost(string blogid, string username, string password, MetaPost post, bool publish) { EnsureUser(username, password).Wait(); var newStory = new Data.Post(); try { newStory.Title = post.title; newStory.Content = post.description; newStory.DatePublished = post.dateCreated == DateTime.MinValue ? DateTime.UtcNow : post.dateCreated; newStory.Tags = string.Join(",", post.categories); newStory.IsPublished = publish; newStory.Slug = newStory.GetStoryUrl(); _repo.AddPost(newStory); _repo.SaveAll(); } catch (Exception) { throw new MetaWeblogException("Failed to save the post."); } return(newStory.Id.ToString()); }
public void AddPost(Post post) { repository.AddPost(post); }