public IActionResult NewVaultFromService(string type, string items) { ViewBag.Title = "Create Vault"; ModifyVaultViewModel model = new ModifyVaultViewModel(); model.CurrentSub = Subdomain; string decodedItems = HttpUtility.UrlDecode(items); string[] allURLs = decodedItems.Split(','); int index = 0; foreach (string url in allURLs) { string[] urlInfo = url.Split(':'); string uploadId = urlInfo[0]; string title = string.Empty; if (urlInfo.GetUpperBound(0) >= 1) { // They also passed in the original filename, so let's use it as our title title = urlInfo[1]; } if (IsValidItem(type, uploadId)) { ModifyVaultItemViewModel item = new ModifyVaultItemViewModel(); item.isTemplate = false; item.index = index; item.title = title; item.url = uploadId; item.type = type; model.items.Add(item); index++; } } return(View("~/Areas/Vault/Views/Vault/ModifyVault.cshtml", model)); }
public IActionResult EditVault(string url, string type, string items) { ViewBag.Title = "Edit Vault"; Vault.Models.Vault foundVault = _dbContext.Vaults.Where(v => v.Url == url).FirstOrDefault(); if (foundVault != null) { if (foundVault.User.Username == User.Identity.Name) { ViewBag.Title = "Edit Vault | " + foundVault.Title; ModifyVaultViewModel model = new ModifyVaultViewModel(); model.CurrentSub = Subdomain; model.isEdit = true; model.vaultId = foundVault.VaultId; model.title = foundVault.Title; model.description = foundVault.Description; int index = 0; // Add all their existing items for the vault foreach (VaultItem item in foundVault.VaultItems.OrderBy(v => v.Index)) { ModifyVaultItemViewModel itemModel = new ModifyVaultItemViewModel(); itemModel.index = index; itemModel.isTemplate = false; if (item.GetType().BaseType == typeof(UploadVaultItem)) { UploadVaultItem upload = (UploadVaultItem)item; itemModel.title = upload.Title; itemModel.description = upload.Description; itemModel.type = "Upload"; itemModel.url = upload.Upload.Url; model.items.Add(itemModel); index++; } else if (item.GetType().BaseType == typeof(PasteVaultItem)) { PasteVaultItem paste = (PasteVaultItem)item; itemModel.title = paste.Title; itemModel.description = paste.Description; itemModel.type = "Paste"; itemModel.url = paste.Paste.Url; model.items.Add(itemModel); index++; } } // If they passed any new items in via the parameters, let's add them if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(items)) { string decodedItems = HttpUtility.UrlDecode(items); string[] allItems = decodedItems.Split(','); foreach (string newItem in allItems) { string[] urlInfo = newItem.Split(':'); string itemId = urlInfo[0]; string title = string.Empty; if (urlInfo.GetUpperBound(0) >= 1) { // They also passed in the original filename, so let's use it as our title title = urlInfo[1]; } if (IsValidItem(type, itemId)) { ModifyVaultItemViewModel item = new ModifyVaultItemViewModel(); item.isTemplate = false; item.index = index; item.title = title; item.url = itemId; item.type = type; model.items.Add(item); index++; } } } return(View("~/Areas/Vault/Views/Vault/ModifyVault.cshtml", model)); } return(new StatusCodeResult(StatusCodes.Status403Forbidden)); } return(new StatusCodeResult(StatusCodes.Status404NotFound)); }