public GameControllerServices(UsedGamesAPIGames usedGamesAPIGames, UsedGamesAPIPlatforms usedGamesAPIPlatforms, IConfiguration configuration, SellerLoginManager loginManager) { _usedGamesAPIGames = usedGamesAPIGames; _usedGamesAPIPlatforms = usedGamesAPIPlatforms; _configuration = configuration; _loginManager = loginManager; }
public void OnAuthorization(AuthorizationFilterContext context) { SellerLoginManager loginManager = context.HttpContext.RequestServices.GetService(typeof(SellerLoginManager)) as SellerLoginManager; if (!loginManager.IsLogged()) { context.Result = new RedirectToActionResult("Login", "Home", new {}); } }
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(); } }
public HomeController(UsedGamesAPISellers usedGamesAPISellers, SellerLoginManager sellerLoginManager) { _usedGamesAPISellers = usedGamesAPISellers; _sellerLoginManager = sellerLoginManager; }