Пример #1
0
        public ActionResult GenericAttributeUpdate(GenericAttributeModel model, GridCommand command)
        {
            model.Key   = model.Key.TrimSafe();
            model.Value = model.Value.TrimSafe();

            if (ModelState.IsValid)
            {
                var storeId = _services.StoreContext.CurrentStore.Id;
                var infos   = GetGenericAttributesInfos(model.EntityName);

                if (infos.UpdatePermission.HasValue() && !Services.Permissions.Authorize(infos.UpdatePermission))
                {
                    NotifyError(Services.Permissions.GetUnauthorizedMessage(infos.UpdatePermission));
                }
                else
                {
                    var attr = _genericAttributeService.GetAttributeById(model.Id);

                    // If the key changed, ensure it isn't being used by another attribute.
                    if (!attr.Key.IsCaseInsensitiveEqual(model.Key))
                    {
                        var attr2 = _genericAttributeService.GetAttributesForEntity(model.EntityId, model.EntityName)
                                    .Where(x => x.StoreId == storeId && x.Key.Equals(model.Key, StringComparison.InvariantCultureIgnoreCase))
                                    .FirstOrDefault();

                        if (attr2 != null && attr2.Id != attr.Id)
                        {
                            NotifyWarning(T("Admin.Common.GenericAttributes.NameAlreadyExists", model.Key));
                            return(GenericAttributesSelect(model.EntityName, model.EntityId, command));
                        }
                    }

                    attr.Key   = model.Key;
                    attr.Value = model.Value;

                    _genericAttributeService.UpdateAttribute(attr);
                }
            }
            else
            {
                var modelStateErrorMessages = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                NotifyError(modelStateErrorMessages.FirstOrDefault());
            }

            return(GenericAttributesSelect(model.EntityName, model.EntityId, command));
        }
        public ActionResult GenericAttribute_Update(GenericAttribute model)
        {
            try
            {
                var genericAttribute = _genericAttributeService.GetAttributeById(model.Id);
                genericAttribute.Id          = model.Id;
                genericAttribute.EntityKey   = model.EntityKey;
                genericAttribute.EntityValue = model.EntityValue;

                _genericAttributeService.Update(genericAttribute);
                return(new NullJsonResult());
            }
            catch (Exception)
            {
                return(new NullJsonResult());
            }
        }
Пример #3
0
        public ActionResult GenericAttributeUpdate(GenericAttributeModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel))
            {
                return(AccessDeniedView());
            }

            model.Key   = model.Key.TrimSafe();
            model.Value = model.Value.TrimSafe();

            if (!ModelState.IsValid)
            {
                // display the first model error
                var modelStateErrorMessages = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrorMessages.FirstOrDefault()));
            }

            var storeId = _storeContext.CurrentStore.Id;

            var attr = _genericAttributeService.GetAttributeById(model.Id);

            // if the key changed, ensure it isn't being used by another attribute
            if (!attr.Key.IsCaseInsensitiveEqual(model.Key))
            {
                var attr2 = _genericAttributeService.GetAttributesForEntity(model.EntityId, model.EntityName)
                            .Where(x => x.StoreId == storeId && x.Key.Equals(model.Key, StringComparison.InvariantCultureIgnoreCase))
                            .FirstOrDefault();
                if (attr2 != null && attr2.Id != attr.Id)
                {
                    return(Content(string.Format(_localizationService.GetResource("Admin.Common.GenericAttributes.NameAlreadyExists"), model.Key)));
                }
            }

            attr.Key   = model.Key;
            attr.Value = model.Value;

            _genericAttributeService.UpdateAttribute(attr);

            return(GenericAttributesSelect(model.EntityName, model.EntityId, command));
        }
Пример #4
0
        public static GenericAttribute GetAttributeByKey(this IGenericAttributeService genericAttributeService, BaseEntity entity, string key, int storeId = 0)
        {
            var entityName = entity.GetUnproxiedEntityType().Name;
            var ga         = genericAttributeService.GetAttributesForEntity(entity.Id, entityName)
                             .FirstOrDefault(
                x =>
                x.Key == key &&
                x.StoreId == storeId);

            if (ga != null) //weird but it works this way only
            {
                ga = genericAttributeService.GetAttributeById(ga.Id);
            }
            return(ga);
        }
Пример #5
0
        public void EnableOrDisableUser(int customerId, bool enable)
        {
            if (customerId != 0)
            {
                var cacheData = WebApiCachingUserData.Data();
                var apiUser   = cacheData.FirstOrDefault(x => x.CustomerId == customerId);

                if (apiUser != null)
                {
                    apiUser.Enabled = enable;

                    var attribute = _genericAttributeService.GetAttributeById(apiUser.GenericAttributeId);
                    if (attribute != null)
                    {
                        attribute.Value = apiUser.ToString();
                        _genericAttributeService.UpdateAttribute(attribute);
                    }
                }
            }
        }
Пример #6
0
 /// <summary>
 /// Gets an attribute
 /// </summary>
 /// <param name="attributeId">Attribute identifier</param>
 /// <returns>An attribute</returns>
 public GenericAttribute GetAttributeById(int attributeId)
 {
     return(_genericAttributeService.GetAttributeById(attributeId));
 }