public ActionResult Add(StorageAccountModel storageAccountModel) { if (storageAccountModel == null) { storageAccountModel = new StorageAccountModel(); ModelState.AddModelError("empty_model", ValidationResources.AccountInvalidError); } IEnumerable<SelectListItem> storagePlugins = GetSupportedStoragePlugins(); storageAccountModel.StoragePlugins = storagePlugins; if (ModelState.IsValid) { StorageAccount account = new StorageAccount { AccountName = storageAccountModel.AccountName, StoragePluginId = storageAccountModel.PluginId, UserId = User.Identity.UserId }; StorageAccountCreationResult result = _storageAccountService.CreateStorageAccount(account); switch (result) { case StorageAccountCreationResult.PluginNotFound: ModelState.AddModelError("storage_plugin_not_found", ValidationResources.StoragePluginNotFoundError); break; case StorageAccountCreationResult.AccountExists: ModelState.AddModelError("storage_account_exists", ValidationResources.AccountExistsError); break; case StorageAccountCreationResult.Success: return RedirectToAction("Edit", new {account.Id}); } } return View(storageAccountModel); }
public ActionResult Add() { IEnumerable<SelectListItem> storagePlugins = GetSupportedStoragePlugins(); var model = new StorageAccountModel { StoragePlugins = storagePlugins }; return View(model); }