Ejemplo n.º 1
0
		private static void SortComments(ref Page page)
		{
			if (page == null)
				throw new ArgumentNullException();

			page.Comments = page.Comments.OrderByDescending(x => x.Posted).ToList();
		}
Ejemplo n.º 2
0
		public async Task<Page> AddCommentAsync(string title, string content, IPrincipal user, Page page)
		{
			if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(content) ||
				user == null || page == null)
				throw new ArgumentException();

			var appuser = await _userService.GetUserByIPrincipalAsync(user);
			var comment = new PageComment
			{
				Author = appuser,
				Content = content.FilterHtml(),
				Id = Guid.NewGuid(),
				OriginalContent = page,
				Posted = DateTime.Now,
				Title = HttpUtility.HtmlEncode(title)
			};
			page.Comments.Add(comment);

			await _db.SaveChangesAsync();
			SortComments(ref page);
			return page;
		}
Ejemplo n.º 3
0
		public async Task<Guid> AddPageAsync(string title, string content, IPrincipal user)
		{
			if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(content) || user == null)
				throw new ArgumentException();

			var appuser = await _userService.GetUserByNameAsync(user.Identity.Name);
			if (appuser == null)
				throw new ArgumentException();

			var page = new Page
			{
				Author = appuser,
				Comments = new List<PageComment>(),
				Content = content.ConvertNewlines(),
				Id = Guid.NewGuid(),
				LastEdited = DateTime.Now,
				Posted = DateTime.Now,
				Title = HttpUtility.HtmlEncode(title)
			};

			_db.Pages.Add(page);
			await _db.SaveChangesAsync();

			return page.Id;
		}
Ejemplo n.º 4
0
		public async Task DeletePageAsync(Page page)
		{
			if (page == null)
				throw new ArgumentNullException();

			_db.Pages.Remove(page);
			await _db.SaveChangesAsync();
		}
			public async Task AddComment()
			{
				var page = new Page();

				PageServiceMock.Setup(f => f.GetPageByIdAsync("guid"))
					.ReturnsAsync(page);

				var comment = new CommentSubmittionModel("guid");
				comment.Comment.Content = "some content";
				comment.Comment.Title = "titlehere";

				var result = await Controller.SubmitComment(comment) as RedirectToRouteResult;
				Assert.IsNotNull(result);

				PageServiceMock.Verify(f => f.AddCommentAsync("titlehere", "some content", It.IsAny<IPrincipal>(), page));
			}