private void Save(Models.GalleryCategory record, bool isNew)
 {
     // add any code to update other fields/tables here
     record.Save();
     // save subform or related checkboxes here eg record.Lines.Save();
     //ifsubform: record.example.Save();
     //CheckLock(record);
     //lockobj.UnLockTable(record.GetTableName(),record.ID);
     ActiveRecordLoader.ClearCache("GalleryCategory");
 }
        /// <summary>
        /// Populates defaults and opens edit form to add new record
        /// GET: /Admin/GalleryCategory/Create
        /// </summary>
        public ActionResult Create()
        {
            var data = new EditViewModel();

            Breadcrumbs.Current.AddBreadcrumb(data.breadcrumbLevel, "Add Gallery Category");
            var record = new Models.GalleryCategory();

            // any default values can be set here or in partial class GalleryCategory.InitDefaults()
            record.UpdateFromRequest();              // grab any defaults from querystring
            data.GalleryCategory = record;
            return(View("GalleryCategoryEdit", data));
        }
        protected ActionResult ProcessForm(Models.GalleryCategory record)
        {
            try {
                record.UpdateFromRequest();
                // read subform or related checkboxes here eg record.Lines.UpdateFromRequest();
                //ifsubform: record.example.UpdateFromRequest();

                Validate(record);
                if (ModelState.IsValid)
                {
                    Save(record, record.IsNewRecord);
                    Web.InfoMessage += "Gallery Category " + record.GetName() + " saved.";
                }
            } catch (UserErrorException e) {
                ModelState.AddModelError("Record", e.Message);
            }

            if (!ModelState.IsValid)
            {
                // invalid so redisplay form with validation message(s)
                return(View("GalleryCategoryEdit", new EditViewModel()
                {
                    GalleryCategory = record
                }));
            }
            else if (Web.Request["SaveAndRefreshButton"] != null)
            {
                return(RedirectToEdit(record.ID));
            }
            else if (Web.Request["DuplicateButton"] != null)
            {
                var newRecord = new Models.GalleryCategory();
                newRecord.UpdateFrom(record);
                newRecord.Save();
                Web.InfoMessage += "Copy of Gallery Category " + record.GetName() + " created. You are now editing the new copy.";
                return(RedirectToEdit(newRecord.ID));
            }
            else
            {
                return(RedirectToReturnPage());
            }
        }
Exemplo n.º 4
0
            public ViewModel(Models.GalleryCategory category)
            {
                // check for admin preview
                if (Web.Request["preview"] == "adminonly")
                {
                    // force login if not already
                    if (!Security.IsLoggedIn)
                    {
                        throw new Beweb.ProgrammingErrorException("force login required");
                    }
                }
                else if (!category.GetIsActive())
                {
                    throw new Beweb.BadUrlException("Category not available with ID of [" + category.ID + "]");
                }
                Category     = category;
                PageTitleTag = category.Title;
                //category.CheckUserAccess();           // uncomment this if using page user access control

                TrackingBreadcrumb.Current.AddBreadcrumb(2, category.Title);
            }
 private void Validate(Models.GalleryCategory record)
 {
     // add any code to check for validity
     //ModelState.AddModelError("Record", "Suchandsuch cannot be whatever.");
 }