Beispiel #1
0
        /// <summary>
        /// Populates defaults and opens edit form to add new record
        /// GET: /Admin/DocumentDownload/Create
        /// </summary>
        public ActionResult Create()
        {
            var data = new EditViewModel();

            Breadcrumbs.Current.AddBreadcrumb(3, "Add Document Download");
            var record = new Models.DocumentDownload();

            // any default values can be set here or in partial class DocumentDownload.InitDefaults()
            record.UpdateFromRequest();              // grab any defaults from querystring
            data.DocumentDownload = record;
            return(View("DocumentDownloadEdit", data));
        }
Beispiel #2
0
        protected ActionResult ProcessForm(Models.DocumentDownload 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 += "Document Download " + record.GetName() + " saved.";
                }
            } catch (UserErrorException e) {
                ModelState.AddModelError("Record", e.Message);
            }

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