Пример #1
0
        /// <summary>
        /// GET comments
        /// </summary>
        /// <returns>Action</returns>
        public ActionResult Comment()
        {
            int dealId = int.Parse(RouteData.Values["DealID"].ToString());

            IList<Comment> comments = new List<Comment>();
            Deal deal = new Deal();

            try
            {
                comments = commentDataAccess.GetDealComments(dealId);
                deal = dealDataAccess.GetDeal(dealId);
            }
            catch (DealDatabaseException)
            {
                log.Warn("Could not get deal from database when loading comments");
            }
            catch (CommentDatabaseException)
            {
                log.Warn("Could not get comments from database");
            }

            Dictionary<User, Comment> userComments = new Dictionary<User, Comment>();

            foreach (Comment comment in comments)
            {
                try
                {
                    userComments[memberDataAccess.GetUser(comment.UserName)] = comment;
                }
                catch (MemberDatabaseException)
                {
                    log.Warn("Could not get user from database when loading comments");
                }
            }

            DealComments dealComments = new DealComments()
                {
                    Comments = userComments.OrderByDescending(a => a.Value.Date),
                    Deal = deal,
                    CurrentUsername = userName
                };

            return PartialView(dealComments);
        }
Пример #2
0
        public ActionResult Comment(DealComments commentWrapper)
        {
            Comment comment = new Comment
                                  {
                                      CommentString = commentWrapper.NewComment,
                                      Date = DateTime.Now,
                                      DealId = commentWrapper.Deal.DealID,
                                      UserName = userName
                                  };

            log.Trace("Saving comment {0} for deal {1} from user {2}", commentWrapper.NewComment, commentWrapper.Deal.Title, userName);

            try
            {
                commentDataAccess.SaveDealComment(comment);
            }
            catch (CommentDatabaseException)
            {
                log.Warn("Could not save comment to database");
            }

            return RedirectToAction("Index", "Home");
        }