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 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); }
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); }
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 ActionResult CreateGame() { ActionResult response = null; if ((Int64)Session["RoleID"] == 3) { GamePO gameObject = new GamePO(); response = View(gameObject); } else { response = RedirectToAction("Index"); } return(response); }
//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); }
public ActionResult UpdateGame(GamePO form, HttpPostedFileBase picture, HttpPostedFileBase game) { //Set variables for the file paths. string downloadPath = string.Empty; string picturePath = string.Empty; ActionResult response = null; //Only contributors and administrators can update the games. if (ModelState.IsValid && (Session["UserRole"] != null && (int)Session["UserRole"] < 3)) { try { //Send game and picture files to a method for acceptance. //A bool value deterimes the type of file submitted from the form. downloadPath = form.Download; picturePath = form.Picture; //Apply the selected files to the form if they were accepted. form.Download = AcceptFile(game, downloadPath, false); form.Picture = AcceptFile(picture, picturePath, true); //Send the form to the database to be applied to the selected game. GameDO gameObject = Mapper.GamePOtoDO(form); _dataAccess.UpdateGame(gameObject); //Run the remove unused file method to maintian efficient storage usage. RemovePriorFile(); response = RedirectToAction("GameDetails", "Games", new { specificGame = form.GameID }); } catch (Exception ex) { Logger.Log(ex); //If can issue occurs, redirect to the Index page. response = RedirectToAction("Index", "Games"); } finally { } } else { //If there was an issue with the model, give the user their input information back. response = View(form); } return(response); }
public ActionResult UpdateGame(Int64 gameID) { ActionResult response = null; if ((Int64)Session["RoleID"] == 3) { GameMap map = new GameMap(); GameDL dl = new GameDL(); GameDO gameObject = dl.ViewGameByID(gameID); GamePO form = map.GameDOToPO(gameObject); response = View(form); } else { response = RedirectToAction("Index"); } return(response); }
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); }
public ActionResult UpdateGame(GamePO updatedGame) { ActionResult response; //check for admin or mod if (Session["RoleID"] != null && (int)Session["RoleID"] == 6 || Session["RoleID"] != null && (int)Session["RoleID"] == 4) { //if the user is an admin or a mod, check the model if (ModelState.IsValid) { //if the model is valid, access the database try { //map form, send to database GameDO gameDO = _GameMapper.MapPOtoDO(updatedGame); _GameDataAccess.UpdateGame(gameDO); response = RedirectToAction("GameDetails", "Game", new { id = updatedGame.GameID }); } catch (Exception ex) { //log error _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); //set tempdata for an error TempData["GameError"] = "There was an error processing this game, please check the information you entered and try again."; response = View(updatedGame); } finally { } } else { //if the model is not valid, return to form response = View(updatedGame); } } else { //if the user is not an admin or a mod, redirect to the login page response = RedirectToAction("Login", "Account"); } return(response); }
//Method for mapping from DO to PO public static GamePO GameDOtoPO(GameDO from) { //Declaring a new PO object using the GamePO model GamePO to = new GamePO(); //Mapping all relevant information. from is the pass in, to is the result. to.GameId = from.GameId; to.White = from.White; to.WhiteName = from.WhiteName; to.WhiteRating = from.WhiteRating; to.Black = from.Black; to.BlackName = from.BlackName; to.BlackRating = from.BlackRating; to.Location = from.Location; to.DatePlayed = from.DatePlayed; to.Winner = from.Winner; //sends the data back to the method that called it return(to); }
public ActionResult CreateGame(GamePO newGame) { ActionResult response; //check for admin if (Session["RoleID"] != null && (int)Session["RoleID"] == 6) { //if the user is an admin, check the model if (ModelState.IsValid) { //if the model is valid, access the database try { //map to data layer, access database GameDO game = _GameMapper.MapPOtoDO(newGame); _GameDataAccess.CreateGame(game); response = RedirectToAction("Index", "Game"); } catch (Exception ex) { //log error _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); TempData["GameError"] = "There was an error processing this game, please check the information you entered and try again."; response = View(newGame); } finally { } } else { //if the model is not valid, return to the form response = View(newGame); } } else { //if the user is not an admin, redirect to the login page response = RedirectToAction("Login", "Account"); } return(response); }
//Takes in the information that a user wants to update about a certain game public ActionResult UpdateGame(int gameId) { //declaring object using model GamePO GamePO gameToUpdate = new GamePO(); //Beginning of processes try { //declare List using Model GameDO, and use it to store all information on the game recovered by using a DAL access call GameDO item = _dataAccess.GameReadByID(gameId); //assign all data to object using a mapper gameToUpdate = MapGameTF.GameDOtoPO(item); //establish list to hold all data on all players as recovered by the DAL access call List <PlayerDO> players = _playerAccess.PlayerReadAll(); //declare list to hold relevant data from full DAL call List <SelectListItem> options = new List <SelectListItem>(); foreach (PlayerDO dataObject in players) { //Declare list to hold player names SelectListItem option = new SelectListItem(); //make list aspect equal dataObject variable option.Text = dataObject.Name; //make list aspect equal dataObject variable option.Value = dataObject.PlayerId.ToString(); //take object "option", and add it to list "options" options.Add(option); } //set object value of PlayersDropDown equal to values of "options" gameToUpdate.PlayersDropDown = options; } //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(gameToUpdate)); }
public ActionResult UpdateGame(int id) { ActionResult response; //check for admin or mod if (Session["RoleID"] != null && (int)Session["RoleID"] == 6 || Session["RoleID"] != null && (int)Session["RoleID"] == 4) { //if the user is an admin or a mod, check id if (id > 0) { //if id is valid, access the database try { //access database, map to presentation layer GameDO gameDO = _GameDataAccess.ViewGameByID(id); GamePO gamePO = _GameMapper.MapDOtoPO(gameDO); response = View(gamePO); } 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 list of games response = RedirectToAction("Index", "Game"); } } else { //if the user is not an admin or a mod, redirect to the login page response = RedirectToAction("Login", "Account"); } return(response); }
//Method for taking in the necessary data to add a new game to the database public ActionResult AddGame() { //declaring object using model GamePO GamePO game = new GamePO(); //Beginning of processes try { //declare List using Model PlayerDO, and use it to store all information on all players recovered by using a DAL access call List <PlayerDO> players = _playerAccess.PlayerReadAll(); //Declare list to hold player names List <SelectListItem> options = new List <SelectListItem>(); //loop to get all objects assigned appropriately foreach (PlayerDO dataObject in players) { //Declare new object to temporarily hold data SelectListItem option = new SelectListItem(); //make list aspect equal dataObject variable option.Text = dataObject.Name; //make list aspect equal dataObject variable option.Value = dataObject.PlayerId.ToString(); //take object "option", and add it to list "options" options.Add(option); } //set object value of PlayersDropDown equal to values of "options" game.PlayersDropDown = options; } //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(game)); }
public ActionResult Index() { ActionResult response = null; if (Session["UserName"] != null) { GameDL dl = new GameDL(); GameMap map = new GameMap(); List <GamePO> fullList = new List <GamePO>(); List <GameDO> allData = dl.ViewGames(); foreach (GameDO data in allData) { GamePO mappedData = map.GameDOToPO(data); fullList.Add(mappedData); } response = View(fullList); } else { response = RedirectToAction("Index", "Home"); } return(response); }
//Method to pass information into the database and update the necessary game public ActionResult UpdateGame(GamePO 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 GameDO dataObject = MapGameTF.GamePOtoDO(form); //calling on a DAL access field to allow us to use a specific method within, while passing in the DO object _dataAccess.GameUpdate(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", "Game"); } //section of code that runs if the form is not valid else { //assigning a value to our variable that will be used if the form isn't valid result = View(form); } //runs the portion of code that is necessary for the situation return(result); }
public ActionResult AddGame(HttpPostedFileBase picture, HttpPostedFileBase game, GamePO form) { //Variables for path values. string downloadPath = string.Empty; string picturePath = string.Empty; ActionResult response = null; //Only contributors and administrators can add games to the database. if (ModelState.IsValid && (Session["UserRole"] != null && (int)Session["UserRole"] < 3)) { try { //Send game and picture files to a method for acceptance. //A bool value deterimes the type of file submitted from the form. form.Download = AcceptFile(game, downloadPath, false); form.Picture = AcceptFile(picture, picturePath, true); //Add the game's information to the database and redirect to the games index. GameDO gameObject = Mapper.GamePOtoDO(form); _dataAccess.AddGame(gameObject); response = RedirectToAction("Index", "Games"); } catch (Exception ex) { Logger.Log(ex); //If an issue occurs while adding a game, redirect to the games index. response = RedirectToAction("Index", "Games"); } finally { } } //If there was a problem with the model while adding a game, give the user back the form info. else { response = View(form); } return(response); }
public ActionResult GameDetails(int specificGame = default(int)) { ActionResult response = null; //Creates a new business object for use with displaying the game's rating. QuaintBLO businessAccess = new QuaintBLO(); //string picturePath = ConfigurationManager.AppSettings.Get("FilePath"); //Sets variables needed for the rating average and path to rating star pictures. decimal average = 0; string path = "/Content/RatingStars/"; if (specificGame != 0) { try { //Get a list of all comments and sends them to the business layer to be calculated. List <CommentDO> commentList = _dataAccessC.ViewGameComments(specificGame); List <CommentBO> sendComments = Mapper.ListCommentDOtoBO(commentList); //List of bytes for all ratings for a specific GameId. List <byte> ratingList = _dataAccessC.AllRatings(specificGame); //Average of all ratings for a specific game retrieved after calculations average = businessAccess.RatingAverage(ratingList); //Display the average in a whole number with one decimal place format, coverted to string. string displayAverage = average.ToString("#.#"); //Displays the number of comments a specific game has, as calculated by the business layer. int displayCommentCount = businessAccess.CommentCount(sendComments); //Get all the details for a game from the database. GameDO gameObject = _dataAccess.GameDetails(specificGame); GamePO displayGame = Mapper.GameDOtoPO(gameObject); //Display a star image representation of the rating average recieved from the calculation. if (average < 0.4m) { ViewBag.StarRating = Path.Combine(path + "0star.png"); } else if (average >= 0.5m && average < 0.9m) { ViewBag.StarRating = Path.Combine(path + "0.5star.png"); } else if (average >= 1m && average < 1.4m) { ViewBag.StarRating = Path.Combine(path + "1star.png"); } else if (average >= 1.5m && average < 1.9m) { ViewBag.StarRating = Path.Combine(path + "1.5star.png"); } else if (average >= 2m && average < 2.4m) { ViewBag.StarRating = Path.Combine(path + "2star.png"); } else if (average >= 2.5m && average < 2.9m) { ViewBag.StarRating = Path.Combine(path + "2.5star.png"); } else if (average >= 3m && average < 3.4m) { ViewBag.StarRating = Path.Combine(path + "3star.png"); } else if (average >= 3.5m && average < 3.9m) { ViewBag.StarRating = Path.Combine(path + "3.5star.png"); } else if (average >= 4m && average < 4.4m) { ViewBag.StarRating = Path.Combine(path + "4star.png"); } else if (average >= 4.5m && average < 4.9m) { ViewBag.StarRating = Path.Combine(path + "4.5star.png"); } else { ViewBag.StarRating = Path.Combine(path + "5star.png"); } //Set the calculations to a ViewBag for display within the View. ViewBag.Rating = displayAverage; ViewBag.Comments = displayCommentCount; response = View(displayGame); } catch (Exception ex) { Logger.Log(ex); //If an issue occurs, redirect to the Index of Games. response = RedirectToAction("Index", "Games"); } finally { } } else { response = RedirectToAction("Index", "Games"); } return(response); }