Ejemplo n.º 1
0
        //Maps all games
        public GamesDO MapAllGames(DataRow dataRow)
        {
            try
            {
                GamesDO games = new GamesDO();

                //If the game ID is not null, then add values to the game object from the database
                if (dataRow["GameID"] != DBNull.Value)
                {
                    games.GameID = (Int64)dataRow["GameID"];
                }
                games.GameName    = dataRow["GameName"].ToString();
                games.System      = dataRow["System"].ToString();
                games.Genre       = dataRow["Genre"].ToString();
                games.ReleaseDate = (DateTime)dataRow["ReleaseDate"];
                games.Price       = (decimal)dataRow["Price"];

                //Returning the object with a row updated from SQL
                return(games);
            }
            catch (Exception ex)
            {
                GameErrorHandler(false, "fatal", "GameDAO", "MapAllGames", ex.Message, ex.StackTrace);
                throw ex;
            }
        }
Ejemplo n.º 2
0
        //Method that creates a game
        public void CreateNewGame(GamesDO games)
        {
            try
            {
                //Creates a new SQL connection
                using (SqlConnection gameStoreConn = new SqlConnection(connString))
                {
                    //Creating a Command to use a stored procedure
                    SqlCommand enterCommand = new SqlCommand("CREATE_GAMES", gameStoreConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;

                    //Parameters that are being passed to the stored procedures
                    enterCommand.Parameters.AddWithValue("@GameName", games.GameName);
                    enterCommand.Parameters.AddWithValue("@System", games.System);
                    enterCommand.Parameters.AddWithValue("@Genre", games.Genre);
                    enterCommand.Parameters.AddWithValue("@ReleaseDate", games.ReleaseDate);
                    enterCommand.Parameters.AddWithValue("@Price", games.Price);

                    //Opens the connection
                    gameStoreConn.Open();

                    //Executes Non Query Command
                    enterCommand.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                GameErrorHandler(false, "fatal", "GameDAO", "CreateNewGame", ex.Message, ex.StackTrace);
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public ActionResult CreateGame(GamesPO form)
        {
            //Declaring local variables
            ActionResult oResponse = RedirectToAction("Index", "Game");

            //Checking if Model state is Valid
            if (ModelState.IsValid)
            {
                try
                {
                    //Mapping in a dataAccess call
                    GamesDO dataObject = GameMapper.MapPoToDo(form);
                    dataAccess.CreateNewGame(dataObject);

                    TempData["Message"] = $"{form.GameName} was created successfully";
                }
                catch (Exception ex)
                {
                    oResponse = View(form);
                }
            }
            else
            {
                oResponse = View(form);
            }

            return(oResponse);
        }
Ejemplo n.º 4
0
        //Method that posts the information for UpdateGame
        public ActionResult UpdateGame(GamesPO form)
        {
            //Declaring local variables
            ActionResult oResponse = RedirectToAction("Index", "Game");

            //Checking if Model state is Valid
            if (ModelState.IsValid)
            {
                try
                {
                    //Mapping in a dataAccess call
                    GamesDO dataObject = GameMapper.MapPoToDo(form);
                    dataAccess.UpdateGames(dataObject);
                }
                catch (Exception ex)
                {
                    oResponse = View(form);
                }
            }
            else
            {
                oResponse = View(form);
            }
            return(oResponse);
        }
        public static GamesDO MapBoToDo(GamesBO from)
        {
            GamesDO to = new GamesDO();

            to.GameID      = from.GameID;
            to.GameName    = from.GameName;
            to.System      = from.System;
            to.Genre       = from.Genre;
            to.ReleaseDate = from.ReleaseDate;
            to.Price       = from.Price;

            return(to);
        }
        public static List <GamesDO> MapBoToDo(List <GamesBO> from)
        {
            List <GamesDO> to = new List <GamesDO>();

            if (from != null)
            {
                foreach (GamesBO item in from)
                {
                    GamesDO mappedItems = MapBoToDo(item);
                    to.Add(mappedItems);
                }
            }
            return(to);
        }
Ejemplo n.º 7
0
        //Method that gets the information for UpdateGame
        public ActionResult UpdateGame(Int64 gameId)
        {
            GamesPO displayObject = new GamesPO();

            try
            {
                //Mapping in a dataAccess call
                GamesDO game = dataAccess.ViewGameAtID(gameId);
                displayObject = GameMapper.MapDoToPo(game);
            }
            catch (Exception ex)
            {
            }
            return(View(displayObject));
        }
Ejemplo n.º 8
0
        //Method that views a certain game by it's ID
        public GamesDO ViewGameAtID(Int64 gameId)
        {
            GamesDO games = new GamesDO();

            try
            {
                //Creates a SQLConnection
                using (SqlConnection gameStoreConn = new SqlConnection(connString))
                {
                    //Creating a Command to use a stored procedure
                    SqlCommand enterCommand = new SqlCommand("VIEW_GAMEID", gameStoreConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;

                    //Parameters that are being passed to the stored procedures
                    enterCommand.Parameters.AddWithValue("@GameID", gameId);

                    //Opens SQLConnection
                    gameStoreConn.Open();

                    //Using a SQLDataAdapter to get the SQL table
                    DataTable gameInfo = new DataTable();
                    using (SqlDataAdapter gameAdapter = new SqlDataAdapter(enterCommand))
                    {
                        gameAdapter.Fill(gameInfo);
                        gameAdapter.Dispose();
                    }

                    //Mapping datarow to a List of the games
                    foreach (DataRow row in gameInfo.Rows)
                    {
                        games = MapAllGames(row);
                    }
                }
            }
            catch (Exception ex)
            {
                GameErrorHandler(false, "fatal", "GameDAO", "ViewGameAtID", ex.Message, ex.StackTrace);

                ex.Data["Message"] = "It Broke";
                throw;
            }
            return(games);
        }
Ejemplo n.º 9
0
        //Method that will display all the games in the database
        public List <GamesDO> ViewAllGames()
        {
            List <GamesDO> allGames = new List <GamesDO>();

            try
            {
                //Creates a SQLConnection
                using (SqlConnection gameStoreConn = new SqlConnection(connString))
                {
                    //Creating a Command to use a stored procedure
                    SqlCommand enterCommand = new SqlCommand("READ_GAMES", gameStoreConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;

                    //Opens SqlConnection
                    gameStoreConn.Open();

                    //Using a SQLDataAdapter to get the SQL table
                    DataTable gameInfo = new DataTable();
                    using (SqlDataAdapter gameAdapter = new SqlDataAdapter(enterCommand))
                    {
                        gameAdapter.Fill(gameInfo);
                        gameAdapter.Dispose();
                    }

                    //Mapping datarow to a List of the games
                    foreach (DataRow row in gameInfo.Rows)
                    {
                        GamesDO mappedRow = MapAllGames(row);
                        allGames.Add(mappedRow);
                    }
                }
            }
            catch (Exception ex)
            {
                GameErrorHandler(false, "fatal", "GameDAO", "ViewAllGames", ex.Message, ex.StackTrace);
                throw ex;
            }
            //returning a list of the games
            return(allGames);
        }
Ejemplo n.º 10
0
        //Method that creates a Cart
        public ActionResult Cart()
        {
            List <GamesPO> displayGames = new List <GamesPO>();

            try
            {
                List <GamesBO> businessObjects = new List <GamesBO>();
                List <int>     cart            = (List <int>)Session["Cart"];
                foreach (int gameId in cart)
                {
                    GamesDO games = dataAccess.ViewGameAtID(gameId);
                    displayGames.Add(GameMapper.MapDoToPo(games));
                    businessObjects.Add(GamesBOMapper.MapDoToBo(games));
                }
                decimal totalSum = businessLayer.CalculationSum(businessObjects);
                ViewBag.Total = totalSum;
            }
            catch (Exception ex)
            {
            }

            return(View(displayGames));
        }