public async Task <IActionResult> DeleteFile(BlobStorageModels model) { var user = await _userManager.GetUserAsync(HttpContext.User); _blobStorageService.DeleteFile("icehockey", model.FileDelete.ID, user.UserName); return(View("Index")); }
public async Task <IActionResult> EditTeam([Bind("Name,FormImage,Description")] Team input, int id) { // Ensure data is valid if (!ModelState.IsValid) { return(View()); } // Get team var team = _context.Teams.FirstOrDefault(x => x.Id == id); // If team was not found, redirect with error if (team == null) { ModelState.AddModelError("Name", "Team not found."); return(View()); } // Update data if (input.FormImage != null) { // Delete old image await _storageService.DeleteFile( team.Image.Replace(_configuration.GetValue <string>("AzureUrl"), "")); // Upload new image team.Image = await _storageService.UploadFile(input.FormImage); } // Set other fields team.Name = input.Name; team.Description = input.Description; // Save database changes await _context.SaveChangesAsync(); // Redirect to team with success message return(Redirect($"/user/team/{team.Id}").WithSuccess("Success", "Team edited.")); }