public ActionResult Delete(long GameId) { //set response ActionResult response; // do a check if (Session["RoleId"] != null && (long)Session["RoleId"] == 5) { try { //pulls from database to push one game GameDO game = _GameDataAccess.ViewGameByGameId(GameId); //adding delete function Game deletedGame = _Mapper.MapDoToPo(game); //deleting game by id GameId = deletedGame.GameId; //check id CANT be default or less than 0 if (GameId > 0) { //delteing the game _GameDataAccess.DeleteGame(GameId); //once deleted rta to view all games response = RedirectToAction("ViewAllGames", "Game"); } else { response = RedirectToAction("ViewAllGames", "Game"); } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); response = RedirectToAction("Index", "Home"); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Login", "Account"); } return(RedirectToAction("ViewAllGames", "Game")); }
public ActionResult DeleteGame(int id) { ActionResult response; //check for admin if (Session["RoleID"] != null && (int)Session["RoleID"] == 6) { //if the user is an admin, access the database try { //access database, map to presentation layer GameDO gameDO = _GameDataAccess.ViewGameByID(id); GamePO gamePO = _GameMapper.MapDOtoPO(gameDO); //check id if (gamePO.GameID > 0) { //if id is valid, delete from database _GameDataAccess.DeleteGame(gamePO.GameID); response = RedirectToAction("Index", "Game"); } else { //if id is not valid, show error screen response = RedirectToAction("Error", "Home"); } } catch (Exception ex) { //log error _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Error", "Home"); } finally { } } else { //if the user is not an admin, return to the details page response = RedirectToAction("GameDetails", "Game", new { id }); } return(response); }