Ejemplo n.º 1
0
        internal DeleteGameViewModel GetGameToDelete(int gameId)
        {
            Game game = this.context.Games.Find(gameId);
            DeleteGameViewModel viewModel = new DeleteGameViewModel()
            {
                GameId = game.Id,
                Title  = game.Title
            };

            return(viewModel);
        }
Ejemplo n.º 2
0
        public IActionResult <DeleteGameViewModel> Delete(HttpResponse response, HttpSession session, int gameId)
        {
            if (!IsAuthenticatedAsAdmin(session))
            {
                Redirect(response, "/home/homepage");
                return(null);
            }
            DeleteGameViewModel viewModel = service.GetDeleteViewModel(gameId);

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Delete(DeleteGameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var game = await _context.Games
                       .SingleOrDefaultAsync(m => m.GameId == model.GameId);

            _context.Games.Remove(game);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 4
0
        public IActionResult <DeleteGameViewModel> Delete(int gameId, HttpSession session, HttpResponse response)
        {
            if (!this.loginManager.IsAuthenticated(session))
            {
                this.Redirect(response, "/home/login");
                return(null);
            }

            if (!this.loginManager.IfUserIsAdmin(session))
            {
                this.Redirect(response, "/home/index");
                return(null);
            }

            DeleteGameViewModel viewModel = this.adminService.GetGameToDelete(gameId);

            return(this.View(viewModel));
        }
Ejemplo n.º 5
0
        public IActionResult <DeleteGameViewModel> Delete(HttpSession session, HttpResponse response, int id)
        {
            if (!AuthenticationManager.IsAuthenticated(session.Id))
            {
                this.Redirect(response, "/users/register");
                return(null);
            }

            User activeUser = AuthenticationManager.GetAuthenticatedUser(session.Id);

            if (!activeUser.IsAdmin)
            {
                this.Redirect(response, "/home/index");
                return(null);
            }

            DeleteGameViewModel viewModel = this.service.GetDeleteGameViewModel(id);

            return(this.View(viewModel));
        }
        // POST
        public IHttpResponse Delete(DeleteGameViewModel viewModel)
        {
            this.gameService.Delete(int.Parse(viewModel.GameId));

            return(new RedirectResponse(@"/"));
        }