示例#1
0
 private void SetGameDetailsViewData(AdminDetailsGameViewModel model)
 {
     this.ViewData["title"]        = model.Title;
     this.ViewData["description"]  = model.Description;
     this.ViewData["image-url"]    = model.ImageUrl;
     this.ViewData["price"]        = model.Price.ToString();
     this.ViewData["size"]         = model.Size.ToString();
     this.ViewData["video-id"]     = model.VideoId;
     this.ViewData["release-date"] = model.ReleaseDate.Value.ToString("yyyy-MM-dd");
 }
示例#2
0
        // Get /admin/games/edit/{id}
        public IHttpResponse EditGame()
        {
            int gameId = int.Parse(this.HttpRequest.UrlParameters["id"]);

            if (!this.Authentication.IsAdmin)
            {
                return(this.RedirectResponse("/"));
            }

            AdminDetailsGameViewModel model = this.gameService.GetGameEditDeleteModel(gameId);

            SetGameDetailsViewData(model);

            return(this.FileViewResponse(EditGameView));
        }
示例#3
0
        // Post /admin/games/edit/{id}
        public IHttpResponse EditGame(AdminDetailsGameViewModel model)
        {
            int gameId = int.Parse(this.HttpRequest.UrlParameters["id"]);

            if (!this.Authentication.IsAdmin)
            {
                return(this.RedirectResponse("/"));
            }

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

            this.gameService.EditGame(gameId, model);

            return(this.RedirectResponse("/admin/games/list"));
        }
        public void EditGame(int gameId, AdminDetailsGameViewModel model)
        {
            using (GameStoreDbContext database = new GameStoreDbContext())
            {
                Game game = database.Games.Where(g => g.Id == gameId).FirstOrDefault();

                if (game != null)
                {
                    game.Title       = model.Title;
                    game.Description = model.Description;
                    game.ImageUrl    = model.ImageUrl;
                    game.Price       = model.Price;
                    game.Size        = model.Size;
                    game.VideoId     = model.VideoId;
                    game.ReleaseDate = model.ReleaseDate.Value;
                }

                database.SaveChanges();
            }
        }