public ActionResult Edit(int id)
        {
            StorageAccount account = _storageAccountService.Load(id);

            if (account == null)
            {
                ModelState.AddModelError("notfound", ValidationResources.StorageAccountNotFoundError);
                return(View());
            }

            Identity identity = User.Identity;

            if (identity.UserId != account.UserId)
            {
                ModelState.AddModelError("forbidden", ValidationResources.NoPermissionsError);
                return(View());
            }

            IStoragePlugin plugin = _storagePluginsService.GetStoragePlugin(account.StoragePluginId);

            if (plugin == null)
            {
                ModelState.AddModelError("storage_plugin", ValidationResources.StoragePluginNotFoundError);
                return(View());
            }

            ViewData.Add(Constants.StorageAccountIdFormKey, account.Id);
            ViewData.Add(Constants.StampFormKey, account.Stamp.ToBinary());
            ViewData.Add(Constants.StorageAccountTitleViewDataKey, account.AccountName);


            object pluginSettingsModel = plugin.GetAccountConfigurationModel(account.Id);

            return(View(pluginSettingsModel));
        }
 public StorageAccountsCollection Init(IStorageAccountService storageAccountService, IStoragePluginsService storagePluginsService, int userId)
 {
     var accounts = storageAccountService.GetActiveStorageAccounts(userId);
     UserId = userId;
     _accounts = accounts.Where(a => storagePluginsService.GetStoragePlugin(a.Item2.Id) != null)
         .Select(a => new AccountItem()
         {
             AccountId = a.Item1.Id,
             AccountName = a.Item1.AccountName,
             StoragePluginId = a.Item1.StoragePluginId,
             StoragePluginName = storagePluginsService.GetStoragePlugin(a.Item2.Id).Name
         }).ToList();
     return this;
 }
Пример #3
0
        public StorageAccountsCollection Init(IStorageAccountService storageAccountService, IStoragePluginsService storagePluginsService, int userId)
        {
            var accounts = storageAccountService.GetActiveStorageAccounts(userId);

            UserId    = userId;
            _accounts = accounts.Where(a => storagePluginsService.GetStoragePlugin(a.Item2.Id) != null)
                        .Select(a => new AccountItem()
            {
                AccountId         = a.Item1.Id,
                AccountName       = a.Item1.AccountName,
                StoragePluginId   = a.Item1.StoragePluginId,
                StoragePluginName = storagePluginsService.GetStoragePlugin(a.Item2.Id).Name
            }).ToList();
            return(this);
        }
Пример #4
0
        public StorageAccountCreationResult CreateStorageAccount(StorageAccount account)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }

            return(_connectionProvider.DoInTransaction(() =>
            {
                if (_storagePluginsService.GetStoragePlugin(account.StoragePluginId) == null)
                {
                    return StorageAccountCreationResult.PluginNotFound;
                }

                StorageAccount checkAccount = _storageAccountRepository.Load(account.AccountName, account.StoragePluginId, account.UserId);

                if (checkAccount != null)
                {
                    return StorageAccountCreationResult.AccountExists;
                }

                _storageAccountRepository.Insert(account);

                return StorageAccountCreationResult.Success;
            }));
        }
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            NameValueCollection form = controllerContext.HttpContext.Request.Form;

            if (!form.AllKeys.Contains(Constants.StorageAccountIdFormKey))
            {
                bindingContext.ModelState.AddModelError("storage_account", ValidationResources.StorageAccountNotFoundError);
                return(null);
            }

            string pluginFormValue = form[Constants.StorageAccountIdFormKey];

            int accountId;

            if (!int.TryParse(pluginFormValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out accountId))
            {
                bindingContext.ModelState.AddModelError("storage_account", ValidationResources.StorageAccountNotFoundError);
                return(null);
            }

            IStorageAccountService accountService = IocContainer.Instance.Resolve <IStorageAccountService>();
            StorageAccount         account        = accountService.Load(accountId);

            if (account == null)
            {
                bindingContext.ModelState.AddModelError("storage_account", ValidationResources.StorageAccountNotFoundError);
                return(null);
            }

            IStoragePluginsService storageService = IocContainer.Instance.Resolve <IStoragePluginsService>();

            IStoragePlugin storagePlugin = storageService.GetStoragePlugin(account.StoragePluginId);

            if (storagePlugin == null)
            {
                bindingContext.ModelState.AddModelError("storage_plugin", ValidationResources.StoragePluginNotFoundError);
                return(null);
            }

            Type modelType = storagePlugin.GetAccountConfigurationModel().GetType();

            if (!String.IsNullOrEmpty(bindingContext.ModelName) && !bindingContext.ValueProvider.ContainsPrefix(bindingContext.ModelName))
            {
                if (!bindingContext.FallbackToEmptyPrefix)
                {
                    return(null);
                }

                bindingContext = new ModelBindingContext
                {
                    ModelMetadata  = bindingContext.ModelMetadata,
                    ModelState     = bindingContext.ModelState,
                    PropertyFilter = bindingContext.PropertyFilter,
                    ValueProvider  = bindingContext.ValueProvider
                };
            }

            //object model = bindingContext.Model ?? CreateModel(controllerContext, bindingContext, bindingContext.ModelType);
            object model = bindingContext.Model ?? CreateModel(controllerContext, bindingContext, modelType);

            bindingContext = new ModelBindingContext
            {
                //ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, bindingContext.ModelType),
                ModelMetadata  = ModelMetadataProviders.Current.GetMetadataForType(() => model, modelType),
                ModelName      = bindingContext.ModelName,
                ModelState     = bindingContext.ModelState,
                PropertyFilter = bindingContext.PropertyFilter,
                ValueProvider  = bindingContext.ValueProvider
            };

            if (OnModelUpdating(controllerContext, bindingContext))
            {
                foreach (PropertyDescriptor descriptor in GetFilteredModelProperties(controllerContext, bindingContext))
                {
                    BindProperty(controllerContext, bindingContext, descriptor);
                }

                OnModelUpdated(controllerContext, bindingContext);
            }

            return(model);
        }