Пример #1
0
        public ActionResult Edit(ExtendedAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var extendedAttribute = _extendedAttributeService.GetExtendedAttributeById(model.Id);

            if (extendedAttribute == null)
            {
                //No extended attribute found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                extendedAttribute = model.ToEntity(extendedAttribute);
                _extendedAttributeService.UpdateExtendedAttribute(extendedAttribute);

                UpdateAttributeLocales(extendedAttribute, model);

                //activity log
                _userActivityService.InsertActivity("EditExtendedAttribute", _localizationService.GetResource("ActivityLog.EditExtendedAttribute"), extendedAttribute.Name);

                NotifySuccess(_localizationService.GetResource("Admin.Catalog.Attributes.ExtendedAttributes.Updated"));
                return(continueEditing ? RedirectToAction("Edit", extendedAttribute.Id) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareExtendedAttributeModel(model, extendedAttribute, true);
            return(View(model));
        }
Пример #2
0
        public ActionResult Create(ExtendedAttributeModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            if (!String.IsNullOrWhiteSpace(model.Name))
            {
                var ext2 = _extendedAttributeService.GetExtendedAttributeByName(model.Name);
                if (ext2 != null)
                {
                    ModelState.AddModelError("", "Name is already registered");
                }
            }

            if (ModelState.IsValid)
            {
                var extendedAttribute = model.ToEntity();
                _extendedAttributeService.InsertExtendedAttribute(extendedAttribute);
                UpdateAttributeLocales(extendedAttribute, model);

                //activity log
                _userActivityService.InsertActivity("AddNewExtendedAttribute", _localizationService.GetResource("ActivityLog.AddNewExtendedAttribute"), extendedAttribute.Name);

                NotifySuccess(_localizationService.GetResource("Admin.Catalog.Attributes.ExtendedAttributes.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = extendedAttribute.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareExtendedAttributeModel(model, null, true);
            return(View(model));
        }