public async Task <IActionResult> Register() { ImageHandler.DeleteImgFolder(_controllerServices.GetImgsTempFolder()); GameViewModel viewModel = await _controllerServices.GetGameViewModelForRegisterAsync(); if (viewModel is null) { return(RedirectToAction("Error", "Home", new { area = "Seller" })); } return(View(viewModel)); }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { SellerLoginManager loginManager = (SellerLoginManager)context.HttpContext.RequestServices.GetService(typeof(SellerLoginManager)); Controller controller = (Controller)context.Controller; GameControllerServices controllerServices = (GameControllerServices)context.HttpContext.RequestServices.GetService(typeof(GameControllerServices)); int imgsPerGame = controllerServices.GetImgsPerGame(); Models.Game game = (Models.Game)context.ActionArguments["game"]; if (game.SellerId != loginManager.GetUserId()) { context.Result = new BadRequestResult(); } string[] tempImgPaths = ImageHandler.GetAllTempImageRelativePaths(controllerServices.GetImgsTempFolder()); if (!context.ModelState.IsValid || tempImgPaths.Length < imgsPerGame) { if (tempImgPaths.Length < imgsPerGame) { controller.ViewData["MSG_E"] = $"You need to have {imgsPerGame} for images a game"; } controller.ViewData["SellerId"] = loginManager.GetUserId(); UsedGamesAPIPlatformResponse response = await GetPlatformsAsync(context); if (!response.Success) { context.Result = new RedirectToActionResult("Error", "Home", new { area = "Seller" }); } SelectList platforms = new SelectList(response.Platforms, "Id", "Name"); GameViewModel viewModel = new GameViewModel(game, platforms, imgsPerGame, loginManager.GetUserId(), tempImgPaths); context.Result = controller.View(viewModel); } else { await next(); } }