Esempio n. 1
0
        public async Task <UsedGamesAPIPlatformResponse> GetPlatformsAsync()
        {
            HttpResponseMessage responseMsg = await _client.GetAsync(_client.BaseAddress);

            string responseStr = await responseMsg.Content.ReadAsStringAsync();

            UsedGamesAPIPlatformResponse response = JsonConvert.DeserializeObject <UsedGamesAPIPlatformResponse>(responseStr);

            response.Success = responseMsg.IsSuccessStatusCode;
            if (responseMsg.StatusCode == HttpStatusCode.Unauthorized)
            {
                response.IsUnauthorized = true;
            }

            return(response);
        }
Esempio n. 2
0
        public async Task <GameViewModel> GetGameViewModelForRegisterAsync()
        {
            UsedGamesAPIPlatformResponse response = await _usedGamesAPIPlatforms.GetPlatformsAsync();

            if (!response.Success)
            {
                return(null);
            }

            GameViewModel viewModel = new GameViewModel
                                      (
                platforms: new SelectList(response.Platforms, "Id", "Name"), imgsPerGame: GetImgsPerGame(), sellerId: _loginManager.GetUserId()
                                      );

            return(viewModel);
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        public async Task <GameViewModel> GetGameViewModelForEditAsync(int id)
        {
            UsedGamesAPIGameResponse gameResponse = await _usedGamesAPIGames.GetAsync(id, _loginManager.GetUserToken());

            if (!gameResponse.Success)
            {
                return(null);
            }

            UsedGamesAPIPlatformResponse platformResponse = await _usedGamesAPIPlatforms.GetPlatformsAsync();

            if (!platformResponse.Success)
            {
                return(null);
            }

            GameViewModel viewModel = new GameViewModel
                                      (
                game: gameResponse.Game, platforms: new SelectList(platformResponse.Platforms, "Id", "Name"),
                imgsPerGame: GetImgsPerGame(), sellerId: _loginManager.GetUserId()
                                      );

            return(viewModel);
        }