public static void AddComment(Comment comment)
 {
     CommentsDataSource comDS = new CommentsDataSource();
     CommentEntry comm = new CommentEntry();
     Converter.CopyFields(comment, comm);
     comDS.AddComment(comm);
 }
 private static bool ShowComment(string statusFilter, Comment comm)
 {
     switch (statusFilter)
     {
         case "New":
             return comm.Status == "New" && comm.Type != "General Comment (no reply required)";
         case "Action Required":
             return comm.Status != "NoActionRequired" && (comm.Type == "Data Request" || comm.Type == "Data Error");
         case "Reply Required":
             return (comm.Status == "New" || comm.Status == "Addressed") && comm.Type != "General Comment (no reply required)";
         case "All":
         case "":
         case null:
             return comm.Type != "General Comment (no reply required)";
         default:
             return true;
     }
 }
        public ActionResult Add(string name, string subject, string comment, string email, string type, bool notify, string datasetId, string datasetName, string parentType, string container, string captchaChallenge, string captchaResponse)
        {
            var validCaptcha = Recaptcha.Validate(captchaChallenge, captchaResponse, Request.UserHostAddress);
            if (!validCaptcha || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(comment) || string.IsNullOrEmpty(datasetId))
                return EmptyHtml();

            var result = new Comment
                {
                    Subject = subject,
                    Body = comment,
                    Posted = DateTime.Now,
                    Email = email,
                    Type = type,
                    Status = "New",
                    Notify = notify && !string.IsNullOrEmpty(email),
                    ParentName = datasetId,
                    ParentType = parentType,
                    Author = name,
                    ParentContainer = container,
                };

            CommentRepository.AddComment(result);

            string linkToParent = Request.UrlReferrer.AbsoluteUri;

            var ni = new NotifyInfo
            {
                CommentEntry = result,
                Link = linkToParent,
                DatasetName = datasetName,
            };
            Action<NotifyInfo> notification = SendNotification;
            notification.BeginInvoke(ni, null, null);

            return View("Comment", result);
        }
            public static CommentEntry CopyFields(Comment source, CommentEntry target)
            {
                if(!String.IsNullOrEmpty(source.RowKey))
                    target.RowKey = source.RowKey;

                target.Username = source.Author;
                target.Comment = source.Body;
                target.DatasetId = source.ParentName;
                target.ParentType = source.ParentType;
                target.PartitionKey = source.ParentContainer;
                target.PostedOn = source.Posted;
                target.Status = source.Status;
                target.Subject = source.Subject;
                target.Type = source.Type;
                target.Notify = source.Notify;
                target.Email = source.Email;

                return target;
            }
 public static void Update(Comment comment)
 {
     CommentsDataSource comDS = new CommentsDataSource();
     CommentEntry comm = comDS.GetById(comment.RowKey);
     Converter.CopyFields(comment, comm);
     comDS.Update(comm);
 }
        public ActionResult Reply(string subject, string comment, string datasetId, string parentType, string container, string origRowKey)
        {
            var result = new Comment
            {
                Subject = subject,
                Body = comment,
                Posted = DateTime.Now,
                Type = "General Comment (no reply required)",
                Status = "N/A",
                Notify = false,
                ParentName = datasetId,
                ParentType = parentType,
                Author = User.Identity.Name,
                ParentContainer = container
            };

            CommentRepository.AddComment(result);

            Comment original = CommentRepository.GetComment(origRowKey);
            original.Status = "Replied";
            CommentRepository.Update(original);

            return Json("Replied", JsonRequestBehavior.AllowGet);
        }