/// <summary> /// Adds the comment. /// </summary> /// <param name="comment">The comment.</param> /// <returns></returns> public CommentDisplayViewModel AddComment(CommentEditViewModel comment) { var entry = this.unitOfWork.Entries.GetById(comment.EntryID); if (entry == null) { return(null); } var commentID = Guid.NewGuid(); var homePage = !string.IsNullOrWhiteSpace(comment.Website) ? comment.Website.Replace("http://", "") : string.Empty; Person owner = null; if (!string.IsNullOrWhiteSpace(comment.Email)) { var emailHash = GetMd5Hash(comment.Email); owner = this.unitOfWork.People.GetByEmailHash(emailHash); } // if no email is provided, or the user with the email is not yet in the table if (owner == null) { // create a new person for this comment owner = new Person { DisplayName = comment.DisplayName, EmailHash = string.Empty, HomePage = homePage }; } var isEntryOwner = owner == entry.Author; var c = new Comment() { CommentId = commentID, Content = comment.Content, CreationDate = DateTimeOffset.UtcNow, Owner = owner, IsEntryOwner = isEntryOwner }; entry.Comments.Add(c); entry.TotalComments++; this.unitOfWork.Commit(); var commentVO = new CommentDisplayViewModel(); commentVO.Content = c.Content; commentVO.DisplayName = c.Owner.DisplayName; commentVO.EmailHash = c.Owner.EmailHash; commentVO.UtcTimeString = c.CreationDate.UtcDateTime.ToString("MM/dd/yyyy HH:mm"); commentVO.IsBlogOwner = c.IsEntryOwner; commentVO.Website = c.Owner.HomePage; return(commentVO); }
/// <summary> /// Gets the entry. /// </summary> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <param name="title">The title.</param> /// <returns></returns> public BlogItemViewModel GetEntry(int year, int month, int day, string title) { var entries = from e in this.unitOfWork.Entries.GetAll() where e.CreationDate.Year == year && e.CreationDate.Month == month && e.CreationDate.Day == day && e.StrippedDownTitle == title select e; if (entries.Count() != 1) { return(null); } var entry = entries.First(); var viewEntry = entry.ConvertToViewModel(); viewEntry.ShowTitleLink = false; foreach (var c in entry.Comments.OrderBy(c => c.CreationDate)) { //commentVO = c.ConvertToViewModel(); var commentVO = new CommentDisplayViewModel(); commentVO.Content = c.Content; commentVO.DisplayName = c.Owner.DisplayName; commentVO.EmailHash = c.Owner.EmailHash; commentVO.UtcTimeString = c.CreationDate.UtcDateTime.ToString("MM/dd/yyyy HH:mm"); commentVO.IsBlogOwner = c.IsEntryOwner; commentVO.Website = c.Owner.HomePage; viewEntry.Comments.Add(commentVO); } return(viewEntry); }