public ActionResult UpdateGame(long GameId)
        {
            //sets response
            ActionResult responce;

            try
            {
                //instantiate updategame by game id
                GameDO updategame = _GameDataAccess.ViewGameByGameId(GameId);
                //maps from do to po
                Game gamedetails = _Mapper.MapDoToPo(updategame);

                //checks
                if (updategame.GameId > 0)
                {
                    responce = View(gamedetails);
                }
                else
                {
                    responce = RedirectToAction("ViewAllGames", "Game");
                }
            }
            catch (SqlException sqlex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex);
                responce = RedirectToAction("Index", "Home");
            }
            catch (Exception ex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                responce = RedirectToAction("Index", "Home");
            }
            return(responce);
        }
        public ActionResult UpdateGame(int specificGame = default(int))
        {
            // Only administrators and contributors can update games.
            ActionResult response = null;

            if ((Session["UserRole"] != null && (int)Session["UserRole"] < 3) || specificGame != 0)
            {
                try
                {
                    //Give the user the game's information to be updated.
                    GameDO gameObject  = _dataAccess.GameDetails(specificGame);
                    GamePO displayGame = Mapper.GameDOtoPO(gameObject);
                    response = View(displayGame);
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    //If there is an issue, send the user to the game's index.
                    response = RedirectToAction("Index", "Games");
                }
                finally { }
            }
            else
            {
                response = RedirectToAction("Index", "Games");
            }
            return(response);
        }
Exemple #3
0
        public ActionResult CreateGame(GamePO form)
        {
            ActionResult response = null;

            if ((Int64)Session["RoleID"] == 3)
            {
                GameDL  dl  = new GameDL();
                GameMap map = new GameMap();
                if (ModelState.IsValid)
                {
                    GameDO gameDO = map.GamePOToDO(form);
                    dl.CreateGame(gameDO);
                    response = RedirectToAction("Index");
                }
                else
                {
                    response = View(form);
                }
            }
            else
            {
                response = RedirectToAction("Index");
            }
            return(response);
        }
        public void UpdateGame(GameDO gameUpdate)
        {
            try
            {
                using (SqlConnection connectionGamestore = new SqlConnection(_ConnectionString))
                    using (SqlCommand updateGame = new SqlCommand("GAME_UPDATE", connectionGamestore))
                    {
                        //sets commmand type
                        updateGame.CommandType = CommandType.StoredProcedure;
                        //sets timeout
                        updateGame.CommandTimeout = 60;
                        //takes in these parameters
                        updateGame.Parameters.AddWithValue("@GameId", gameUpdate.GameId);
                        updateGame.Parameters.AddWithValue("@Title", gameUpdate.Title);
                        updateGame.Parameters.AddWithValue("@Description", gameUpdate.Description);
                        updateGame.Parameters.AddWithValue("@Developing_Company", gameUpdate.DevelopingCompany);
                        updateGame.Parameters.AddWithValue("@Condition", gameUpdate.GameCondition);
                        updateGame.Parameters.AddWithValue("@Price", gameUpdate.Price);

                        //open the connection
                        connectionGamestore.Open();
                        updateGame.ExecuteNonQuery();
                    }
            }
            catch (SqlException sqlex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex);
            }
            catch (Exception ex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
            }
        }
        public ActionResult UpdateGame(Game form)
        {
            //setting the response
            ActionResult response;

            //check
            if (ModelState.IsValid)
            {
                try
                {
                    //mapping gamedo to po
                    GameDO gameDO = _Mapper.MapPoToDo(form);

                    _GameDataAccess.UpdateGame(gameDO);

                    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 = View(form);
            }

            return(response);
        }
 public void CreateGame(GameDO gameObject)
 {
     try
     {
         using (SqlConnection connection = new SqlConnection(connectionString))
         {
             SqlCommand command = new SqlCommand("CREATE_GAME", connection);
             command.CommandType = CommandType.StoredProcedure;
             connection.Open();
             command.Parameters.AddWithValue("@gameTitle", gameObject.GameTitle);
             command.Parameters.AddWithValue("@romanNumeral", gameObject.RomanNumeral);
             command.Parameters.AddWithValue("@releaseDate", gameObject.ReleaseDate);
             command.Parameters.AddWithValue("@copiesSold", gameObject.CopiesSold);
             command.Parameters.AddWithValue("@gameSummary", gameObject.GameSummary);
             command.Parameters.AddWithValue("@price", gameObject.Price);
             command.ExecuteNonQuery();
             connection.Close();
             command.Dispose();
             connection.Dispose();
         }
     }
     catch (Exception ex)
     {
         ErrorLog error = new ErrorLog();
         error.Log(ex, "CreateGame", "DAL", "Error");
     }
 }
Exemple #7
0
        /// <summary>
        /// Filters data while reading from the database.
        /// </summary>
        /// <param name="reader">SqlDataReader to read from the database</param>
        /// <returns>Returns a GameDO with filtered information</returns>
        public GameDO MapReaderToSingle(SqlDataReader reader)
        {
            GameDO gameDO = new GameDO();

            if (reader["GameID"] != DBNull.Value)
            {
                gameDO.GameID = (int)reader["GameID"];
            }
            if (reader["Title"] != DBNull.Value)
            {
                gameDO.Title = (string)reader["Title"];
            }
            if (reader["ReleaseDate"] != DBNull.Value)
            {
                gameDO.ReleaseDate = (string)reader["ReleaseDate"];
            }
            if (reader["Developer"] != DBNull.Value)
            {
                gameDO.Developer = (string)reader["Developer"];
            }
            if (reader["Platform"] != DBNull.Value)
            {
                gameDO.Platform = (string)reader["Platform"];
            }
            return(gameDO);
        }
        public void AddGame(GameDO GameToCreate)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(_ConnectionString))
                    using (SqlCommand command = new SqlCommand("GAME_CREATE", connection))
                    {
                        command.CommandType    = CommandType.StoredProcedure;
                        command.CommandTimeout = 60;
                        command.Parameters.AddWithValue("@Price", GameToCreate.Price);
                        command.Parameters.AddWithValue("@Title", GameToCreate.Title);
                        command.Parameters.AddWithValue("@Description", GameToCreate.Description);
                        command.Parameters.AddWithValue("@Developing_Company", GameToCreate.DevelopingCompany);
                        command.Parameters.AddWithValue("@Condition", GameToCreate.GameCondition);

                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                    }
            }
            catch (SqlException sqlex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex);
            }
        }
Exemple #9
0
        public ActionResult Index()
        {
            Game gamepo = new Game();

            try
            {
                List <CalculationBO> table     = new List <CalculationBO>();
                List <GameOrderDO>   gameorder = new List <GameOrderDO>();
                gameorder = _GameOrderDataAccess.ViewAllGameOrders();
                foreach (GameOrderDO view in gameorder)
                {
                    CalculationBO businesObject = new CalculationBO();
                    businesObject.GameId      = view.GameId;
                    businesObject.GameOrderId = view.GameOrderId;
                    businesObject.Price       = view.Price;
                    table.Add(businesObject);
                }
                long   value  = calc.Total(table);
                GameDO gamedo = new GameDO();

                gamedo = game.ViewGameByGameId(value);
                gamepo = mapper.MapDoToPo(gamedo);
            }
            catch
            {
            }

            return(View(gamepo));
        }
        public ActionResult ViewCart()
        {
            List <long> cart        = (List <long>)Session["Cart"];
            List <Game> mappedGames = new List <Game>();

            try
            {
                foreach (long gameId in cart)
                {
                    //call on game dao then call on method
                    GameDO game = _GameDataAccess.ViewGameByGameId(gameId);

                    mappedGames.Add(_Mapper.MapDoToPo(game));
                }
            }

            catch (SqlException sqlex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex);
            }
            catch (Exception ex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
            }
            return(View(mappedGames));
        }
        public GameDO MapReaderToSingle(SqlDataReader reader)
        {
            GameDO result = new GameDO();

            if (reader["GameId"] != DBNull.Value)
            {
                result.GameId = (long)reader["GameId"];
            }

            if (reader["Title"] != DBNull.Value)
            {
                result.Title = (string)reader["Title"];
            }

            if (reader["Description"] != DBNull.Value)
            {
                result.Description = (string)reader["Description"];
            }
            if (reader["Developing Company"] != DBNull.Value)
            {
                result.DevelopingCompany = (string)reader["Developing Company"];
            }
            if (reader["Condition"] != DBNull.Value)
            {
                result.GameCondition = (string)reader["Condition"];
            }
            if (reader["Price"] != DBNull.Value)
            {
                result.Price = (decimal)reader["Price"];
            }
            return(result);
        }
        public List <GameDO> ViewGameID()
        {
            List <GameDO> gameList = new List <GameDO>();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand("VIEW_GAME_IDS", connection);
                    command.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        GameDO gameObject = new GameDO();
                        gameObject.GameID    = reader.GetInt64(0);
                        gameObject.GameTitle = reader.GetString(1);
                        gameList.Add(gameObject);
                    }
                    connection.Close();
                    command.Dispose();
                    connection.Dispose();
                }
            }
            catch (Exception ex)
            {
                ErrorLog error = new ErrorLog();
                error.Log(ex, "ViewGameID", "DAL", "Error");
            }
            return(gameList);
        }
Exemple #13
0
        /// <summary>
        /// Displays the information for a specific game
        /// </summary>
        /// <param name="id">ID of the game needing to be displayed</param>
        /// <returns>Returns a result based on status</returns>
        public ActionResult GameDetails(int id)
        {
            ActionResult response;
            ReviewVM     viewModel = new ReviewVM();

            //check id
            if (id > 0)
            {
                //if id is valid, access the database
                try
                {
                    //set game
                    GameDO gameDO = _GameDataAccess.ViewGameByID(id);
                    viewModel.Game = _GameMapper.MapDOtoPO(gameDO);

                    //instantiate lists
                    List <ReviewDO> gameReviews   = _ReviewDataAccess.ViewReviews();
                    List <ReviewPO> mappedReviews = new List <ReviewPO>();
                    viewModel.ReviewsList = new List <ReviewPO>();

                    //map reviews to a list of POs
                    foreach (ReviewDO reviewDO in gameReviews)
                    {
                        //get review information
                        ReviewPO reviewPO = _ReviewMapper.MapDOtoPO(reviewDO);

                        //get game information for title
                        GameDO reviewGame = _GameDataAccess.ViewGameByID(reviewPO.GameID);
                        reviewPO.GameTitle = gameDO.Title;

                        //get user information for username
                        UserDO userDO = _UserDataAccess.ViewUserByID(reviewPO.UserID);
                        reviewPO.Username = userDO.Username;

                        mappedReviews.Add(reviewPO);
                    }

                    //filter list and map to view model
                    viewModel.ReviewsList = mappedReviews.Where(n => n.GameID == viewModel.Game.GameID).ToList();

                    response = View(viewModel);
                }
                catch (Exception ex)
                {
                    //log error
                    _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                    response = RedirectToAction("Error", "Home");
                }
                finally { }
            }
            else
            {
                //if id is not valid, return to game list
                response = RedirectToAction("Index", "Game");
            }

            return(response);
        }
        public List <GameDO> ViewGames()
        {
            List <GameDO> gameList = new List <GameDO>();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand("VIEW_GAMES", connection);
                    command.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        GameDO gameObject = new GameDO();


                        gameObject.GameID    = reader.GetInt64(0);
                        gameObject.GameTitle = reader.GetString(1);
                        if (!reader.IsDBNull(2))
                        {
                            gameObject.RomanNumeral = reader.GetString(2);
                        }
                        else
                        {
                        }
                        gameObject.ReleaseDate = reader.GetString(3);
                        if (!reader.IsDBNull(4))
                        {
                            gameObject.CopiesSold = reader.GetInt32(4);
                        }
                        else
                        {
                        }
                        gameObject.GameSummary = reader.GetString(5);
                        if (!reader.IsDBNull(6))
                        {
                            gameObject.Price = reader.GetDecimal(6);
                        }
                        else
                        {
                        }
                        gameList.Add(gameObject);
                    }
                    connection.Close();
                    command.Dispose();
                    connection.Dispose();
                }
            }
            catch (Exception ex)
            {
                ErrorLog error = new ErrorLog();
                error.Log(ex, "ViewGames", "DAL", "Error");
            }
            return(gameList);
        }
Exemple #15
0
        public List <GameDO> ViewGames()
        {
            //Setting the variables to be used for this method.
            SqlConnection connectionToSql = null;
            SqlCommand    storedProcedure = null;
            SqlDataReader reader          = null;
            List <GameDO> gameList        = new List <GameDO>();
            GameDO        gameObject      = new GameDO();

            try
            {
                //Set up for connecting to SQL, using the stored procedure and how to access the information.
                connectionToSql             = new SqlConnection(_connectionString);
                storedProcedure             = new SqlCommand("OBTAIN_GAMES", connectionToSql);
                storedProcedure.CommandType = System.Data.CommandType.StoredProcedure;

                //Opens the connection to SQL.
                connectionToSql.Open();
                //Tell SQLDataReader to gather the information from SQL as determined by the stored procedure.
                reader = storedProcedure.ExecuteReader();

                //Cycle through the database and apply each property in SQL to an object
                //Then add that object to a list of objects.
                while (reader.Read())
                {
                    gameObject             = new GameDO();
                    gameObject.GameID      = int.Parse(reader["GameID"].ToString());
                    gameObject.GameName    = reader["GameName"].ToString();
                    gameObject.ReleaseYear = short.Parse(reader["ReleaseYear"].ToString());
                    gameObject.Genre       = reader["Genre"].ToString();
                    gameObject.Developer   = reader["Developer"].ToString();
                    gameObject.Publisher   = reader["Publisher"].ToString();
                    gameObject.Platform    = reader["Platform"].ToString();
                    gameObject.Download    = reader["Download"].ToString();
                    gameObject.Picture     = reader["Picture"].ToString();
                    gameObject.Description = reader["Description"].ToString();
                    gameList.Add(gameObject);
                }
            }
            catch (Exception ex)
            {
                LoggerDAL.Log(ex, "Fatal");
                //If an issue occurs, the result would likely be fatal, throw the exception.
                throw ex;
            }
            finally
            {
                //When the connection has been established, close and dispose the connection before finishing.
                if (connectionToSql != null)
                {
                    connectionToSql.Close();
                    connectionToSql.Dispose();
                }
            }
            return(gameList);
        }
Exemple #16
0
        //This method id called to the the game's information if a comment fails to add.
        private void FillTempData(int specificGame = default(int))
        {
            //Gets the game information and sets the temp data for a specific game.
            GameDO game = _gameDataAccess.GameDetails(specificGame);

            if (game != null)
            {
                TempData["GameName"] = game.GameName;
            }
        }
        public ActionResult AddGame(Game form)

        {
            ActionResult response;

            // checks role
            if (Session["RoleId"] != null && (long)Session["RoleId"] == 5)
            {
                try
                {
                    //check modelstate
                    if (ModelState.IsValid)

                    {
                        //maps dataObject new game DO
                        GameDO dataObject = new GameDO();
                        dataObject.GameId            = form.GameId;
                        dataObject.Title             = form.Title;
                        dataObject.Description       = form.Description;
                        dataObject.DevelopingCompany = form.DevelopingCompany;
                        dataObject.GameCondition     = form.Condition;
                        dataObject.Price             = form.Price;
                        //Adds a game based off the dao
                        _GameDataAccess.AddGame(dataObject);
                        //Temporarily holds onto the title
                        TempData["Title"] = dataObject.Title;
                        response          = RedirectToAction("AddGame", "Game");
                    }
                    else
                    { // sets the response to View the form
                        response = View(form);
                    }
                }

                //catches and exception and logs it
                catch (SqlException sqlex)

                {
                    _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex);
                    response = RedirectToAction("AllUsers", "Account");
                }
                catch (Exception ex)
                {
                    _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                    response = RedirectToAction("AllUsers", "Account");
                }
            }
            else//if the check fails sets the response
            {
                response = RedirectToAction("Login", "Account");
            }


            return(response);
        }
Exemple #18
0
        public GamePO MapDOtoPO(GameDO gameDO)
        {
            GamePO gamePO = new GamePO();

            gamePO.GameID      = gameDO.GameID;
            gamePO.Title       = gameDO.Title;
            gamePO.ReleaseDate = gameDO.ReleaseDate;
            gamePO.Developer   = gameDO.Developer;
            gamePO.Platform    = gameDO.Platform;
            return(gamePO);
        }
Exemple #19
0
        public GameDO GameDetails(int GameID)
        {
            //Setting the variables to be used for this method.
            SqlConnection connectionToSql = null;
            SqlCommand    storedProcedure = null;
            SqlDataReader reader          = null;
            GameDO        gameObject      = new GameDO();

            try
            {
                //Set up for connecting to SQL, using the stored procedure and how to access the information.
                connectionToSql             = new SqlConnection(_connectionString);
                storedProcedure             = new SqlCommand("VIEW_GAME", connectionToSql);
                storedProcedure.CommandType = System.Data.CommandType.StoredProcedure;
                //Applies the game Id given to the method to the stored procedure.
                storedProcedure.Parameters.AddWithValue("@GameID", GameID);

                //Opens the connection to SQL.
                connectionToSql.Open();
                //Tell SQLDataReader to gather the information from SQL as determined by the stored procedure.
                reader = storedProcedure.ExecuteReader();

                //Reads all the information in SQL via the stored procedure and applies the data to the object.
                while (reader.Read())
                {
                    gameObject.GameID      = int.Parse(reader["GameID"].ToString());
                    gameObject.GameName    = reader["GameName"].ToString();
                    gameObject.ReleaseYear = short.Parse(reader["ReleaseYear"].ToString());
                    gameObject.Genre       = reader["Genre"].ToString();
                    gameObject.Developer   = reader["Developer"].ToString();
                    gameObject.Publisher   = reader["Publisher"].ToString();
                    gameObject.Platform    = reader["Platform"].ToString();
                    gameObject.Download    = reader["Download"].ToString();
                    gameObject.Picture     = reader["Picture"].ToString();
                    gameObject.Description = reader["Description"].ToString();
                }
            }
            catch (Exception ex)
            {
                LoggerDAL.Log(ex, "Fatal");
                //If an issue occurs, the result would likely be fatal, throw the exception.
                throw ex;
            }
            finally
            {
                //When the connection has been established, close and dispose the connection before finishing.
                if (connectionToSql != null)
                {
                    connectionToSql.Close();
                    connectionToSql.Dispose();
                }
            }
            return(gameObject);
        }
Exemple #20
0
        public GameDO MapPoToDo(Game from)
        {
            GameDO to = new GameDO();

            to.GameId            = from.GameId;
            to.Title             = from.Title;
            to.Description       = from.Description;
            to.DevelopingCompany = from.DevelopingCompany;
            to.GameCondition     = from.Condition;
            to.Price             = from.Price;
            return(to);
        }
Exemple #21
0
        public ActionResult ViewGameComments(int specificGame = default(int))
        {
            ActionResult response = null;

            try
            {
                //Access the comments if a GameID is given
                if (specificGame != 0)
                {
                    //Store the game's information, proceed if the game at given ID exists.
                    GameDO game = _gameDataAccess.GameDetails(specificGame);
                    if (game != null)
                    {
                        //Get game comments from the database, map them to presentation,
                        //pass them to the ViewModel.
                        List <CommentDO> commentList     = _dataAccess.ViewGameComments(specificGame);
                        List <CommentPO> displayComments = Mapper.ListCommentDOtoPO(commentList);
                        ViewCommentPO    viewComment     = new ViewCommentPO(displayComments);

                        //Get and set game name.
                        TempData["GameName"] = game.GameName;

                        //Attach user information.
                        if (Session["UserID"] == null)
                        {
                            viewComment.Comment.GameID = specificGame;
                        }
                        else
                        {
                            viewComment.Comment.GameID = specificGame;
                            viewComment.Comment.UserID = (int)Session["UserID"];
                        }
                        response = View(viewComment);
                    }
                    //No game found, redirect to game index.
                    else
                    {
                        response = RedirectToAction("Index", "Games");
                    }
                }
                else
                {
                    response = RedirectToAction("Index", "Games");
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                response = RedirectToAction("Index", "Games");
            }
            finally { }
            return(response);
        }
Exemple #22
0
        public Game MapDoToPo(GameDO from)
        {
            Game to = new Game();

            to.GameId            = from.GameId;
            to.Title             = from.Title;
            to.Description       = from.Description;
            to.DevelopingCompany = from.DevelopingCompany;
            to.Condition         = from.GameCondition;
            to.Price             = from.Price;
            return(to);
        }
Exemple #23
0
        //Method for assigning data from database values to c# values
        private static GameDO RowToItem(DataRow iSource)
        {
            //establishing new object
            GameDO to = new GameDO();

            //pulling "Value" from SQL, casting it or converting it as necessary, and assigning it to it's c# equivalent
            to.GameId = (long)iSource["GameId"];
            //Checking if SQL value is null or not, and if not, proceeds into the if
            if (iSource["WhitePlayer"] != DBNull.Value)
            {
                //pulling "Value" from SQL, casting it or converting it as necessary, and assigning it to it's c# equivalent
                to.WhiteName = iSource["WhitePlayer"].ToString();
            }
            //Checking if SQL value is null or not, and if not, proceeds into the if
            if (iSource["WhiteRating"] != DBNull.Value)
            {
                //pulling "Value" from SQL, casting it or converting it as necessary, and assigning it to it's c# equivalent
                to.WhiteRating = (int)iSource["WhiteRating"];
            }
            //Checking if SQL value is null or not, and if not, proceeds into the if
            if (iSource["BlackPlayer"] != DBNull.Value)
            {
                //pulling "Value" from SQL, casting it or converting it as necessary, and assigning it to it's c# equivalent
                to.BlackName = iSource["BlackPlayer"].ToString();
            }
            //Checking if SQL value is null or not, and if not, proceeds into the if
            if (iSource["BlackRating"] != DBNull.Value)
            {
                //pulling "Value" from SQL, casting it or converting it as necessary, and assigning it to it's c# equivalent
                to.BlackRating = (int)iSource["BlackRating"];
            }
            //Checking if SQL value is null or not, and if not, proceeds into the if
            if (iSource["Location"] != DBNull.Value)
            {
                //pulling "Value" from SQL, casting it or converting it as necessary, and assigning it to it's c# equivalent
                to.Location = iSource["Location"].ToString();
            }
            //Checking if SQL value is null or not, and if not, proceeds into the if
            if (iSource["DatePlayed"] != DBNull.Value)
            {
                //pulling "Value" from SQL, casting it or converting it as necessary, and assigning it to it's c# equivalent
                to.DatePlayed = (DateTime)iSource["DatePlayed"];
            }
            //Checking if SQL value is null or not, and if not, proceeds into the if
            if (iSource["Winner"] != DBNull.Value)
            {
                //pulling "Value" from SQL, casting it or converting it as necessary, and assigning it to it's c# equivalent
                to.Winner = iSource["Winner"].ToString();
            }
            //Return all data to previous method
            return(to);
        }
        public GamePO GameDOToPO(GameDO gameDO)
        {
            GamePO gamePO = new GamePO();

            gamePO.GameID       = gameDO.GameID;
            gamePO.GameTitle    = gameDO.GameTitle;
            gamePO.RomanNumeral = gameDO.RomanNumeral;
            gamePO.ReleaseDate  = gameDO.ReleaseDate;
            gamePO.CopiesSold   = gameDO.CopiesSold;
            gamePO.GameSummary  = gameDO.GameSummary;
            gamePO.Price        = gameDO.Price;
            return(gamePO);
        }
        public GameDO ViewGameByID(Int64 GameID)
        {
            GameDO gameObject = new GameDO();

            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand("VIEW_GAME_BY_ID", connection);
                    command.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    command.Parameters.AddWithValue("@gameID", GameID);
                    SqlDataReader reader = command.ExecuteReader();
                    reader.Read();
                    gameObject.GameID    = reader.GetInt64(0);
                    gameObject.GameTitle = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                    {
                        gameObject.RomanNumeral = reader.GetString(2);
                    }
                    else
                    {
                    }
                    gameObject.ReleaseDate = reader.GetString(3);
                    if (!reader.IsDBNull(4))
                    {
                        gameObject.CopiesSold = reader.GetInt32(4);
                    }
                    else
                    {
                    }
                    gameObject.GameSummary = reader.GetString(5);
                    if (!reader.IsDBNull(6))
                    {
                        gameObject.Price = reader.GetDecimal(6);
                    }
                    else
                    {
                    }
                    connection.Close();
                    command.Dispose();
                    connection.Dispose();
                }
            }
            catch (Exception ex)
            {
                ErrorLog error = new ErrorLog();
                error.Log(ex, "ViewGameByID", "DAL", "Error");
            }
            return(gameObject);
        }
Exemple #26
0
        //Method for viewing more specific details of a game
        public GameDO GameReadByID(long gameId)
        {
            //Defining SqlConnection for this method
            SqlConnection scon = null;
            //Establishing a new data adapter
            SqlDataAdapter iDReader = null;
            //Establishing a new data table
            DataTable table = new DataTable();
            //Establishing new object using model GameDO
            GameDO game = new GameDO();

            //Beginning of method processes
            try
            {
                scon = new SqlConnection(_conn);
                //Defining a variable for the SqlCommand, as well as the stored proc and connection we're using
                SqlCommand readRowById = new SqlCommand("GAME_READ_BY_ID", scon);
                //Defining what kind of command our SqlCommand is
                readRowById.CommandType = CommandType.StoredProcedure;
                //Adding in all the variables. Format: ("@SqlVariable", C#VariableValue)
                readRowById.Parameters.AddWithValue("@GameId", gameId);
                //opening sql connection
                scon.Open();
                //defining our adapter and what command it uses
                iDReader = new SqlDataAdapter(readRowById);
                //telling the code to use the stored procedure
                readRowById.ExecuteNonQuery();
                //telling code to use the data table to fill itself
                iDReader.Fill(table);
                //setting our object equal to all information pulled from database by running it through a mapper
                game = GameListMap.DataTableToList(table).FirstOrDefault();
            }
            //Catch for any errors that may happen
            catch (Exception ex)
            {
                //passing in the exception that was thrown to the errorhandler
                ErrorHandlerDAL.ErrorLogger(ex);
            }
            //finally cleans up any last loose ends
            finally
            {
                //closing SqlConnection
                scon.Close();
                //disposing of the SqlConnection
                scon.Dispose();
            }
            //Method for viewing more specific details of a game
            return(game);
        }
        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"));
        }
        // game datails grabs the id of that game and shows the details
        public ActionResult GameDetails(long GameId)

        {
            ActionResult result;


            try
            {
                //check
                if (Session["RoleId"] != null && (long)Session["RoleId"] >= 3)
                {
                    //instantiate game by game id
                    GameDO game = _GameDataAccess.ViewGameByGameId(GameId);
                    //maps from do to po
                    Game detailsGame = _Mapper.MapDoToPo(game);

                    //check
                    if (detailsGame.GameId > 0)
                    {
                        //returns the view
                        result = View(detailsGame);
                    }
                    else
                    {
                        //result = rta to view all games
                        result = RedirectToAction("ViewAllGames", "Game");
                    }
                }
                //if check fails
                else
                {
                    result = RedirectToAction("Login", ("Account"));
                }
            }
            catch (SqlException sqlex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex);
                result = RedirectToAction("Index", "Home");
            }
            catch (Exception ex)
            {
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                result = RedirectToAction("Index", "Home");
            }


            return(result);
        }
        //Map the properties from the DataAccess to the Presentation.
        public static GamePO GameDOtoPO(GameDO from)
        {
            GamePO to = new GamePO();

            to.GameID      = from.GameID;
            to.GameName    = from.GameName;
            to.ReleaseYear = from.ReleaseYear;
            to.Genre       = from.Genre;
            to.Developer   = from.Developer;
            to.Publisher   = from.Publisher;
            to.Platform    = from.Platform;
            to.Download    = from.Download;
            to.Picture     = from.Picture;
            to.Description = from.Description;
            return(to);
        }
        /// <summary>
        /// Reads one record from the Games table in the GAMEGROOVE database
        /// </summary>
        /// <param name="gameID">ID of the game needing to be viewed</param>
        /// <returns></returns>
        public GameDO ViewGameByID(int gameID)
        {
            GameDO game = new GameDO();

            //catch errors while accessing the database
            try
            {
                //connect to sql, run stored procedure
                using (SqlConnection connection = new SqlConnection(_ConnectionString))
                    using (SqlCommand command = new SqlCommand("VIEW_GAME_BY_ID", connection))
                    {
                        command.CommandType    = CommandType.StoredProcedure;
                        command.CommandTimeout = 60;

                        //set parameter for stored procedure
                        command.Parameters.AddWithValue("@GameID", gameID);

                        connection.Open();

                        //read from the database, uses [if] statement to read only one record
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                game = _Mapper.MapReaderToSingle(reader);
                            }
                        }
                    }
            }
            //catch sqlexceptions for accurate logging
            catch (SqlException ex)
            {
                //log error
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                throw ex;
            }
            //catch further exceptions
            catch (Exception ex)
            {
                //log error
                _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                throw ex;
            }
            finally { }

            return(game);
        }