/// <summary>
        /// Populates defaults and opens edit form to add new record
        /// GET: /Admin/Category/Create
        /// </summary>
        public ActionResult Create()
        {
            Breadcrumbs.Current.AddBreadcrumb(3, "Add Category");
            var record = new Models.ProductCategory();

            // any default values can be set here or in partial class Category.InitDefaults()
            return(View("ProductCategoryEdit", record));
        }
Beispiel #2
0
        public static List <Models.ProductCategory> RemoveReferences(this List <Models.ProductCategory> list)
        {
            var newList = new List <Models.ProductCategory>();

            list.ForEach(item =>
            {
                var obj = new Models.ProductCategory();
                obj     = item.RemoveReferences();
                newList.Add(obj);
            });
            return(newList);
        }
Beispiel #3
0
        private static Models.ProductCategory RemoveReference(this Models.ProductCategory item)
        {
            var obj = new Models.ProductCategory();

            if (item != null)
            {
                obj.Id               = item.Id;
                obj.Name             = item.Name;
                obj.SpanishName      = item.SpanishName;
                obj.ParentId         = item.ParentId;
                obj.Icon             = item.Icon;
                obj.IsActive         = item.IsActive;
                obj.ProductCategory1 = item.ProductCategory1;
            }
            return(obj);
        }
Beispiel #4
0
        public static Models.ProductCategory RemoveReferences(this Models.ProductCategory item)
        {
            var obj = new Models.ProductCategory();

            obj = item.RemoveReference();
            if (item?.ProductCategory1 != null)
            {
                obj.ProductCategory1 = new List <Models.ProductCategory>();
                foreach (var itemk in item.ProductCategory1)
                {
                    obj.ProductCategory1.Add(itemk.RemoveReference());
                }
            }
            if (item?.Parent != null)
            {
                obj.Parent = new Models.ProductCategory();
                obj.Parent = item.RemoveReference();
            }
            return(obj);
        }
        protected ActionResult ProcessForm(Models.ProductCategory 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 = "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("ProductCategoryEdit", record));
            }
            else if (Web.Request["SaveAndRefreshButton"] != null)
            {
                return(RedirectToEdit(record.ID));
            }
            else if (Web.Request["DuplicateButton"] != null)
            {
                var newRecord = new Models.ProductCategory();
                newRecord.UpdateFrom(record);
                newRecord.Save();
                Web.InfoMessage = "Copy of Category " + record.GetName() + " created. You are now editing the new copy.";
                return(RedirectToEdit(newRecord.ID));
            }
            else
            {
                return(RedirectToReturnPage());
            }
        }
 private void Save(Models.ProductCategory record, bool isNew)
 {
     // add any code to update other fields/tables here
     record.Save();
     // save subform or related checkboxes here eg record.Lines.Save();
 }
 private void Validate(Models.ProductCategory record)
 {
     // add any code to check for validity
     //ModelState.AddModelError("Record", "Suchandsuch cannot be whatever.");
 }