Beispiel #1
0
        // GET: Admin/Games/Edit/5
        public ActionResult Edit(int? id)
        {
            GameDTO game = facade.GetGameGateway().Get(id);
            List<PlatformGameDTO> platformGames = facade.GetPlatformGameGateway().GetAll().Where(o => o.GameId == game.Id).ToList();
            List<PlatformDTO> platforms = new List<PlatformDTO>();
            List<GenreDTO> genres = new List<GenreDTO>();

            foreach (var p in platformGames)
            {
                platforms.Add(facade.GetPlatformGateway().Get(p.PlatformId));
            }
            foreach (var g in game.Genres)
            {
                genres.Add(facade.GetGenreGateway().Get(g.Id));
            }
            GameEditVM gEditVM = new GameEditVM(platformGames, platforms, genres, game);
            ViewBag.Genres = new SelectList(facade.GetGenreGateway().GetAll(), "Id", "Name");
            return View(gEditVM);
        }
Beispiel #2
0
        public ActionResult Edit([Bind(Include = "Id,Title,ReleaseDate,CoverUrl,TrailerUrl,Description")] GameDTO game, int[] Genres)
        {
            if (!ModelState.IsValid)
            {
                List<PlatformGameDTO> platformGames = facade.GetPlatformGameGateway().GetAll().Where(o => o.GameId == game.Id).ToList();
                List<PlatformDTO> platforms = new List<PlatformDTO>();
                List<GenreDTO> genres = new List<GenreDTO>();

                foreach (var p in platformGames)
                {
                    platforms.Add(facade.GetPlatformGateway().Get(p.PlatformId));
                }
                foreach (var g in game.Genres)
                {
                    genres.Add(facade.GetGenreGateway().Get(g.Id));
                }
                GameEditVM gEditVM = new GameEditVM(platformGames, platforms, genres, game);
                ViewBag.Genres = new SelectList(facade.GetGenreGateway().GetAll(), "Id", "Name");
                return View(gEditVM);
            }
            List<GenreDTO> NewGenres = new List<GenreDTO>();
            foreach (var genreID in Genres)
            {
                NewGenres.Add(new GenreDTO() { Id = genreID });
            }
            game.Genres = NewGenres;
            facade.GetGameGateway().Update(game);
            return RedirectToAction("Index");
        }
Beispiel #3
0
        // GET: Admin/Games/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            GameDTO game = facade.GetGameGateway().Get(id);
            List<PlatformGameDTO> platformGames = facade.GetPlatformGameGateway().GetAll().Where(o => o.GameId == game.Id).ToList();
            List<PlatformDTO> platforms = new List<PlatformDTO>();
            List<GenreDTO> genres = new List<GenreDTO>();

            foreach (var p in platformGames)
            {
                platforms.Add(facade.GetPlatformGateway().Get(p.PlatformId));
            }
            foreach (var g in game.Genres)
            {
                genres.Add(facade.GetGenreGateway().Get(g.Id));
            }
            GameEditVM gEditVM = new GameEditVM(platformGames, platforms, genres, game);
            if (game == null)
            {
                return HttpNotFound();
            }
            return View(gEditVM);
        }