Ejemplo n.º 1
0
        private string Save(Models.Comment record, bool isNew)
        {
            bool moveOnToNextItem = false;

            // send emails (only if DeclineReason has been changed):
            if (record.Fields.DeclineReason.IsDirty && (record.Status == Comment.CommentStatus.Approved.ToString() || record.Status == Comment.CommentStatus.Declined.ToString()))
            {
                if (record.Status == Comment.CommentStatus.Approved.ToString())
                {
                    // mark as Approved
                    record.ApprovedByPersonID = Security.LoggedInUserID;
                    record.ApprovedDate       = DateTime.Now;
                }

                // user email:
                //Beweb.SiteCustom.Emails.CommentApproveDeclineToPerson(record);
                moveOnToNextItem = true;
            }

            // add any code to update other fields/tables here
            record.Save();
            //record.RebuildCachedComments();
            // save subform or related checkboxes here eg record.Lines.Save();

            // regardless of what button they clicked - move on to the next item if they declined or approved something
            if (moveOnToNextItem)
            {
                // find the next item
                var nextCommentId = BewebData.GetValue(new Sql("SELECT TOP(1) CommentId FROM Comment WHERE Status=", Comment.CommentStatus.Submitted.ToString().SqlizeText()
                                                               , "AND CommentID < ", record.CommentID, " ORDER BY CommentID DESC"));

                if (nextCommentId.IsBlank())
                {
                    nextCommentId = BewebData.GetValue(new Sql("SELECT TOP(1) CommentId FROM Comment WHERE Status=", Comment.CommentStatus.Submitted.ToString().SqlizeText()
                                                               , "AND CommentID < ", record.CommentID, " ORDER BY CommentID ASC"));

                    if (nextCommentId.IsBlank())
                    {
                        return("~/Admin/CommentAdmin/Moderate");
                    }
                }
                return("~/Admin/CommentAdmin/Edit/" + nextCommentId);
            }
            return("");
        }
Ejemplo n.º 2
0
        protected ActionResult ProcessForm(Models.Comment record)
        {
            try {
                record.UpdateFromRequest();
                // read subform or related checkboxes here eg record.Lines.UpdateFromRequest();
                Validate(record);
                if (ModelState.IsValid)
                {
                    var returnUrl = Save(record, record.IsNewRecord);
                    TempData["info"] = "Comment " + record.GetName() + " saved.";
                    if (returnUrl.IsNotBlank())
                    {
                        return(Redirect(returnUrl));
                    }
                }
            } catch (UserErrorException e) {
                ModelState.AddModelError("Record", e.Message);
            }

            if (!ModelState.IsValid)
            {
                // invalid so redisplay form with validation message(s)
                return(View("CommentEdit", record));
            }
            else if (Web.Request["SaveAndRefreshButton"] != null)
            {
                return(RedirectToEdit(record.ID));
            }
            else if (Web.Request["DuplicateButton"] != null)
            {
                var newRecord = new Models.Comment();
                newRecord.UpdateFrom(record);
                newRecord.Save();
                TempData["info"] = "Copy of Comment " + record.GetName() + " created. You are now editing the new copy.";
                return(RedirectToEdit(newRecord.ID));
            }
            else
            {
                return(RedirectToReturnPage());
            }
        }