Beispiel #1
0
        /// <summary>
        /// Populates defaults and opens edit form to add new record
        /// GET: /Admin/BlogComment/Create
        /// </summary>
        public ActionResult Create(int ID)
        {
            Breadcrumbs.Current.AddBreadcrumb(4, "Add Blog Comment");
            var record = new Models.BlogComment();

            record.BlogID = ID;
            // any default values can be set here or in partial class BlogComment.InitDefaults()
            return(View("BlogCommentEdit", record));
        }
Beispiel #2
0
        protected ActionResult ProcessForm(Models.BlogComment record)
        {
            try {
                record.UpdateFromRequest();
                // read subform or related checkboxes here eg record.Lines.UpdateFromRequest();
                Validate(record);
                if (ModelState.IsValid)
                {
                    Save(record, record.IsNewRecord);
                    Web.InfoMessage = "Blog Comment " + record.GetName() + " saved.";
                }
            } catch (UserErrorException e) {
                ModelState.AddModelError("Record", e.Message);
            }

            if (!ModelState.IsValid)
            {
                // invalid so redisplay form with validation message(s)
                return(View("BlogCommentEdit", record));
            }
            else if (Web.Request["SaveAndRefreshButton"] != null)
            {
                return(RedirectToEdit(record.ID));
            }
            else if (Web.Request["DuplicateButton"] != null)
            {
                var newRecord = new Models.BlogComment();
                newRecord.UpdateFrom(record);
                newRecord.Save();
                Web.InfoMessage = "Copy of Blog Comment " + record.GetName() + " created. You are now editing the new copy.";
                return(RedirectToEdit(newRecord.ID));
            }
            else
            {
                return(RedirectToReturnPage());
            }
        }
Beispiel #3
0
 private void Save(Models.BlogComment record, bool isNew)
 {
     // add any code to update other fields/tables here
     record.Save();
     // save subform or related checkboxes here eg record.Lines.Save();
 }
Beispiel #4
0
 private void Validate(Models.BlogComment record)
 {
     // add any code to check for validity
     //ModelState.AddModelError("Record", "Suchandsuch cannot be whatever.");
 }