//Method to gather information from a user to update a player
        public ActionResult UpdatePlayer(int playerId)
        {
            //declaring object using model PlayerPO
            PlayerPO playerToUpdate = new PlayerPO();

            //Beginning of processes
            try
            {
                //declare List using Model PlayerDO, and use it to store all information on the game recovered by using a DAL access call
                PlayerDO item = _dataAccess.PlayerReadByID(playerId);
                //assign all data to object using a mapper
                playerToUpdate = MapPlayerTF.PlayerDOtoPO(item);
            }
            //catch to record any exceptions that crop up
            catch (Exception ex)
            {
                //call to method to record necessary information
                ErrorFile.ErrorHandlerPL(ex);
            }
            //finally to tie up any loose ends
            finally
            { }
            //Sends the data in the list to the view to be seen by the user.
            return(View(playerToUpdate));
        }
示例#2
0
        //Method for mapping from DO to PO
        public static PlayerPO PlayerDOtoPO(PlayerDO from)
        {
            //Declaring a new PO object using the PlayerPO model
            PlayerPO to = new PlayerPO();

            //Mapping all relevant information. from is the pass in, to is the result.
            to.PlayerId           = from.PlayerId;
            to.Name               = from.Name;
            to.PeakRating         = from.PeakRating;
            to.BirthDate          = from.BirthDate;
            to.Dead               = from.Dead;
            to.CountryOfOrigin    = from.CountryOfOrigin;
            to.CountryRepresented = from.CountryRepresented;
            //sends the data back to the method that called it
            return(to);
        }
        //Method to pass in all information gathered from a user and update a player's information in the database
        public ActionResult UpdatePlayer(PlayerPO form)
        {
            //Declaring an action result variable, but assigning it to null to reassign later
            ActionResult result = null;

            //Checks to see if the UI form is filled out correctly
            if (ModelState.IsValid)
            {
                //Beginning of processes
                try
                {
                    //passing the UI form information to run through our mapper, and assigning it to a DO object
                    PlayerDO dataObject = MapPlayerTF.PlayerPOtoDO(form);
                    //calling on a DAL access field to allow us to use a specific method within, while passing in the DO object
                    _dataAccess.PlayerUpdate(dataObject);
                }
                //catch to record any exceptions that crop up
                catch (Exception ex)
                {
                    //call to method to record necessary information
                    ErrorFile.ErrorHandlerPL(ex);
                }
                //finally to tie up any loose ends
                finally
                { }
                //assigns a page redirection to our variable
                result = RedirectToAction("Index", "Player");
            }
            //section of code that runs if the form is not valid
            else
            {
                //assigns a page redirection to our variable
                result = View(form);
            }
            //runs the portion of code that is necessary for the situation
            return(result);
        }