예제 #1
0
        // POST
        public IHttpResponse Edit(AdminEditGameViewModel model)
        {
            var redirectResponse = this.RedirectIfNotAdminOrNotAthenticated();

            if (redirectResponse != null)
            {
                return(redirectResponse);
            }

            if (!this.ValidateModel(model))
            {
                return(this.Edit(model.Id));
            }

            bool isEdited = this.gameService.Edit(
                model.Id,
                model.Title,
                model.Description,
                model.Image,
                model.Price,
                model.Size,
                model.VideoId,
                model.ReleaseDate.Value);

            if (!isEdited)
            {
                this.ShowError("Game not found in database");

                return(this.Edit(model.Id));
            }

            return(new RedirectResponse(Routes.ListAllGamesPath));
        }
        public IHttpResponse Edit(AdminEditGameViewModel model) // for POST
        {
            // Accessed by Admins only
            if (!this.Authentication.IsAdmin)
            {
                return(this.RedirectResponse(HomePath));
            }

            // Validate model
            if (!this.ValidateModel(model))
            {
                this.ShowError("Invalid game details");

                return(this.Edit(model));
            }

            // Update game in db
            var success = this.gameService.Update(
                model.Id,
                model.Title,
                model.Description,
                model.ImageUrl,
                model.Price,
                model.Size,
                model.VideoId,
                (DateTime)model.ReleaseDate);

            if (!success)
            {
                this.ShowError($"Game #{model.Id} does not exist");
            }

            return(this.List());
        }
예제 #3
0
        public IHttpResponse Edit(int id)
        {
            if (!this.Authentication.IsAdmin)
            {
                return(this.RedirectResponse(HomePath));
            }

            AdminEditGameViewModel game = this.games.GetGameById(id);

            if (game == null)
            {
                return(this.RedirectResponse(HomePath));
            }

            this.ViewData["alert-display"] = "none";
            if (this.ViewData.ContainsKey("alert-message"))
            {
                this.ViewData["alert-display"] = "block";
            }

            this.ViewData["game-title"]       = game.Title;
            this.ViewData["game-description"] = game.Description;
            this.ViewData["game-image"]       = game.Image;
            this.ViewData["game-price"]       = game.Price.ToString();
            this.ViewData["game-release"]     = game.ReleaseDate.ToString();
            this.ViewData["game-size"]        = game.Size.ToString();
            this.ViewData["game-videoId"]     = game.VideoId;
            this.ViewData["game-id"]          = game.Id.ToString();

            return(this.FileViewResponse(EditGameView));
        }
예제 #4
0
        public IHttpResponse Edit(AdminEditGameViewModel model)
        {
            if (!this.ValidateModel(model))
            {
                return(this.Edit());
            }

            this.games.Edit(model);

            return(this.List());
        }
예제 #5
0
        public IHttpResponse Edit(AdminEditGameViewModel model)
        {
            if (!this.Authentication.IsAdmin)
            {
                return(new RedirectResponse(HomePath));
            }
            var id = int.Parse(this.Request.UrlParameters["id"]);

            if (string.IsNullOrWhiteSpace(model.RealeaseDate))
            {
                this.AddError(RequiredDate);
                return(this.Edit());
            }
            this.games.Edit(id, model);
            return(new RedirectResponse(ListGamesPath));
        }
예제 #6
0
        public void Edit(int id, AdminEditGameViewModel model)
        {
            using (var db = new GameStoreDbContext())
            {
                var game = db.Games
                           .FirstOrDefault(gid => gid.Id == id);
                game.Title        = model.Title;
                game.Price        = model.Price;
                game.Description  = model.Description;
                game.Image        = model.Image;
                game.Size         = model.Size;
                game.RealeaseDate = DateTime.Parse(model.RealeaseDate);
                game.VideoId      = model.VideoId;

                db.SaveChanges();
            }
        }
예제 #7
0
        public IHttpResponse Edit(AdminEditGameViewModel model)
        {
            if (!this.Authentication.IsAdmin)
            {
                return(new RedirectResponse("/"));
            }

            if (!this.ValidateModel(model))
            {
                this.ShowError("Invaid input!");

                return(new RedirectResponse($"/admin/games/edit/{model.Id}"));
            }

            this.gameService.EditGame(model.Id, model.Title, model.Description, model.ImageUrl, model.Price, model.Size, model.TrailerId, model.ReleaseDate.Value);

            return(new RedirectResponse("/admin/games/list"));
        }
예제 #8
0
        public IHttpResponse Edit(AdminEditGameViewModel model)
        {
            if (!this.Authentication.IsAdmin)
            {
                return(this.RedirectResponse(HomePath));
            }

            // are validations passed ?
            if (!this.ValidateModel(model))
            {
                return(this.Edit(model.Id));
            }

            if (!this.games.Edit(model))
            {
                return(new BadRequestResponse());
            }

            return(this.RedirectResponse(AllGamesListPath));
        }
예제 #9
0
        public IHttpResponse Details()
        {
            int id = int.Parse(this.Request.UrlParameters["id"]);
            AdminEditGameViewModel game = this.games.GetGameById(id);

            this.ViewData["buy-button"] = "inline";
            if (!this.Authentication.IsAuthenticated)
            {
                return(this.RedirectResponse(HomePath));

                this.ViewData["buy-button"] = "none";
            }


            //this.ViewData["bought-info"] = "none";
            //if (this.Request.UrlParameters.ContainsKey("bought") && this.Request.UrlParameters["bought"] == "success")
            //{
            //    this.ViewData["bought-info"] = "block";
            //}

            this.ViewData["game-title"]       = game.Title;
            this.ViewData["game-videoUrl"]    = game.VideoId;
            this.ViewData["game-description"] = game.Description;
            this.ViewData["game-price"]       = game.Price.ToString();
            this.ViewData["game-size"]        = game.Size.ToString();
            this.ViewData["game-release"]     = game.ReleaseDate.ToShortDateString();
            this.ViewData["game-id"]          = game.Id.ToString();

            if (this.Authentication.IsAdmin)
            {
                this.ViewData["admin-set"] = "inline";
            }
            else
            {
                this.ViewData["admin-set"] = "none";
            }

            return(this.FileViewResponse(DetailsView));
        }
        public void Edit(AdminEditGameViewModel model)
        {
            using (var db = new GameStoreDbContext())
            {
                var game = db.Games
                           .FirstOrDefault(g => g.Id == model.Id);

                if (game == null)
                {
                    return;
                }

                game.Description  = model.Description;
                game.ThumbnailUrl = model.Thumbnail;
                game.Price        = model.Price;
                game.ReleaseDate  = model.ReleaseDate;
                game.Size         = model.Size;
                game.Title        = model.Title;
                game.Trailer      = model.Trailer;

                db.SaveChanges();
            }
        }
예제 #11
0
        public bool Edit(AdminEditGameViewModel editedGame)
        {
            using (var db = new GameStoreDbContext())
            {
                if (db.Games.Any(g => g.Id == editedGame.Id))
                {
                    Game game = db.Games.FirstOrDefault(g => g.Id == editedGame.Id);
                    game.Description = editedGame.Description;
                    game.Image       = editedGame.Image;
                    game.Price       = editedGame.Price;
                    game.ReleaseDate = editedGame.ReleaseDate;
                    game.Size        = editedGame.Size;
                    game.Title       = editedGame.Title;
                    game.VideoId     = editedGame.VideoId;

                    db.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
예제 #12
0
        public IHttpResponse DeleteGet(int id)
        {
            if (!this.Authentication.IsAdmin)
            {
                return(this.RedirectResponse(HomePath));
            }

            AdminEditGameViewModel game = this.games.GetGameById(id);

            if (game == null)
            {
                return(this.RedirectResponse(HomePath));
            }

            this.ViewData["game-title"]       = game.Title;
            this.ViewData["game-description"] = game.Description;
            this.ViewData["game-image"]       = game.Image;
            this.ViewData["game-price"]       = game.Price.ToString();
            this.ViewData["game-release"]     = game.ReleaseDate.ToString();
            this.ViewData["game-size"]        = game.Size.ToString();
            this.ViewData["game-videoId"]     = game.VideoId;

            return(this.FileViewResponse(DeleteGameView));
        }