public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { Controller controller = (Controller)context.Controller; GameControllerServices controllerServices = (GameControllerServices)context.HttpContext.RequestServices.GetService(typeof(GameControllerServices)); if (!context.ModelState.IsValid) { GameViewModel viewModel = await controllerServices.GetGameViewModelForEditAsync(); viewModel.Game = (Models.Game)context.ActionArguments["Game"]; List <Image> images = await controllerServices.GetImagesAsync(viewModel.Game.Id); if (images is null) { context.Result = new RedirectToActionResult("Error", "Home", new { area = "Seller" }); } else { viewModel.Game.Images = images; context.Result = new ViewResult() { ViewData = new ViewDataDictionary(controller.ViewData) { Model = viewModel } }; } } else { await next(); } }
public async Task <IActionResult> Edit([FromRoute] int id) { ImageHandler.DeleteImgFolder(_controllerServices.GetImgsTempFolder()); GameViewModel viewModel = await _controllerServices.GetGameViewModelForEditAsync(id); if (viewModel is null) { return(RedirectToAction("Error", "Home", new { area = "Seller" })); } return(View(viewModel)); }