public MovieTheoryDO MapReaderToSingle(SqlDataReader reader) { MovieTheoryDO result = new MovieTheoryDO(); //Checks to make sure there is some sort of value. if (reader["MovieTheoryId"] != DBNull.Value) { result.MovieTheoryID = (long)reader["MovieTheoryId"]; } if (reader["TitleOfTheory"] != DBNull.Value) { result.TitleOfTheory = (string)reader["TitleOfTheory"]; } if (reader["Theory"] != DBNull.Value) { result.Theory = (string)reader["Theory"]; } if (reader["Status"] != DBNull.Value) { result.Status = (string)reader["Status"]; } if (reader["MovieId"] != DBNull.Value) { result.MovieId = (long)reader["MovieId"]; } return(result); }
public ActionResult DeleteMovieTheory(long id) { ActionResult response; //Only for admins. if (Session["Role"] != null) { if ((int)Session["Role"] == 3 && id > 0) { try { //Map the theory in order to delete from the database and the presentation layer. MovieTheoryDO movieTheory = movieTheoryDataAccess.ViewMovieTheory(id); MovieTheoryPO deletedMovieTheory = mapper.MapDoToPo(movieTheory); movieTheoryDataAccess.DeleteMovieTheory(deletedMovieTheory.MovieTheoryID); response = RedirectToAction("Index", "Home"); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
//Details that everyone to see. public ActionResult DetailsForAllTheories(long id) { ActionResult response; if (id > 0) { try { //Shows specific movie theory details. MovieTheoryDO movieTheoryDO = movieTheoryDataAccess.ViewMovieTheory(id); MovieTheoryPO movieTheoryPO = mapper.MapDoToPo(movieTheoryDO); response = View(movieTheoryPO); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Index", "Home"); } return(response); }
//Update theory. public void UpdateMovieTheory(MovieTheoryDO movieTheory) { try { using (SqlConnection connection = new SqlConnection(connectionStrings)) using (SqlCommand updateTheory = new SqlCommand("UPDATE_MOVIE_THEORIES", connection)) { updateTheory.CommandType = CommandType.StoredProcedure; updateTheory.Parameters.AddWithValue("@MovieTheoryId", movieTheory.MovieTheoryID); updateTheory.Parameters.AddWithValue("@TitleOfTheory", movieTheory.TitleOfTheory); updateTheory.Parameters.AddWithValue("@Theory", movieTheory.Theory); updateTheory.Parameters.AddWithValue("@Status", movieTheory.Status); updateTheory.Parameters.AddWithValue("@MovieId", movieTheory.MovieId); connection.Open(); updateTheory.ExecuteNonQuery(); } } catch (SqlException sqlex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } }
//Add a movie theory. public void AddMovieTheory(MovieTheoryDO addMovieTheory) { //Returning nothing and DO required. try { using (SqlConnection connection = new SqlConnection(connectionStrings)) using (SqlCommand addTheory = new SqlCommand("ADD_MOVIE_THEORY", connection)) { addTheory.CommandType = CommandType.StoredProcedure; addTheory.Parameters.AddWithValue("@TitleOfTheory", addMovieTheory.TitleOfTheory); addTheory.Parameters.AddWithValue("@Theory", addMovieTheory.Theory); addTheory.Parameters.AddWithValue("@Status", addMovieTheory.Status); addTheory.Parameters.AddWithValue("@MovieId", addMovieTheory.MovieId); connection.Open(); //Allows it to perform the action. addTheory.ExecuteNonQuery(); } } catch (SqlException sqlex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } }
//View one movie theory. public MovieTheoryDO ViewMovieTheory(long movieTheoryID) { MovieTheoryDO movieTheory = new MovieTheoryDO(); try { using (SqlConnection connection = new SqlConnection(connectionStrings)) using (SqlCommand viewOneTheory = new SqlCommand("VIEW_MOVIE_THEORIES", connection)) { viewOneTheory.CommandType = CommandType.StoredProcedure; viewOneTheory.Parameters.AddWithValue("@MovieTheoryID", movieTheoryID); connection.Open(); using (SqlDataReader reader = viewOneTheory.ExecuteReader()) { if (reader.Read()) { //Mapping to the DO movieTheory = mapper.MapReaderToSingle(reader); } } } } 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(movieTheory); }
public ActionResult AddMovieTheory(MovieTheoryPO form) { ActionResult response; //Anyone with an account can add a movie theory. if (Session["Role"] != null) { if (ModelState.IsValid) { try { //Keeping the dropdown list, just in case. ViewBag.StatusDropDown = new List <SelectListItem>(); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Tinfoilly", Value = "Tinfoilly" }); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Perchance", Value = "Perchance" }); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Believable", Value = "Believable" }); MovieTheoryDO newMovieTheory = mapper.MapPoToDo(form); movieTheoryDataAccess.AddMovieTheory(newMovieTheory); response = RedirectToAction("MovieTheoryIndex", "MovieTheory", new { id = form.MovieId }); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Home"); } } else { //Keeping the dropdown list, just in case. ViewBag.StatusDropDown = new List <SelectListItem>(); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Tinfoilly", Value = "Tinfoilly" }); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Perchance", Value = "Perchance" }); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Believable", Value = "Believable" }); response = View(form); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
public ActionResult UpdateMovieTheory(MovieTheoryPO form) { ActionResult response; //Mods and Admins can update movie theories. if (Session["Role"] != null) { if ((int)Session["Role"] != 1) { //Making sure there are no null in required fields. if (ModelState.IsValid) { try { MovieTheoryDO movieTheoryDO = mapper.MapPoToDo(form); movieTheoryDataAccess.UpdateMovieTheory(movieTheoryDO); //Keeping the dropdown list in case something goes wrong. ViewBag.StatusDropDown = new List <SelectListItem>(); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Tinfoilly", Value = "Tinfoilly" }); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Perchance", Value = "Perchance" }); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Believable", Value = "Believable" }); //Id of movie needed to make sure the correct theory was updated on the correct movie. response = RedirectToAction("MovieTheoryIndex", "MovieTheory", new { id = form.MovieId }); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Home"); } } else { response = View(form); } } else { response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
public MovieTheoryPO MapDoToPo(MovieTheoryDO from) { MovieTheoryPO to = new MovieTheoryPO(); to.MovieTheoryID = from.MovieTheoryID; to.TitleOfTheory = from.TitleOfTheory; to.Theory = from.Theory; to.Status = from.Status; to.MovieId = from.MovieId; return(to); }
public ActionResult UpdateMovieTheory(long id) { ActionResult response; if (Session["Role"] != null) { //Admins and Mods can update theories. if ((int)Session["Role"] != 1 && id > 0) { try { MovieTheoryDO movieTheoryDO = movieTheoryDataAccess.ViewMovieTheory(id); MovieTheoryPO movieTheoryPO = mapper.MapDoToPo(movieTheoryDO); //ViewBag drop down list for status. ViewBag.StatusDropDown = new List <SelectListItem>(); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Tinfoilly", Value = "Tinfoilly" }); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Perchance", Value = "Perchance" }); ViewBag.StatusDropDown.Add(new SelectListItem { Text = "Believable", Value = "Believable" }); response = View(movieTheoryPO); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
//View specific theories connected to one movie. public List <MovieTheoryDO> ViewAllMovieTheories(long movieID) { List <MovieTheoryDO> displayMovieTheories = new List <MovieTheoryDO>(); try { using (SqlConnection connection = new SqlConnection(connectionStrings)) using (SqlCommand viewTheoriesByMovieID = new SqlCommand("VIEW_MOVIE_THEORIES_BY_MOVIEID", connection)) { viewTheoriesByMovieID.CommandType = CommandType.StoredProcedure; //Setting up parameters. viewTheoriesByMovieID.Parameters.AddWithValue("@MovieID", movieID); connection.Open(); using (SqlDataReader sqlDataReader = viewTheoriesByMovieID.ExecuteReader()) { while (sqlDataReader.Read()) { MovieTheoryDO movieTheory = mapper.MapReaderToSingle(sqlDataReader); displayMovieTheories.Add(movieTheory); } } } } 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(displayMovieTheories); }
//View all movie theories public List <MovieTheoryDO> AllMovieTheories() { //Return type List <MovieTheoryDO> displayMovieTheories = new List <MovieTheoryDO>(); try { //Setting up connection to sql and making new command. using (SqlConnection connection = new SqlConnection(connectionStrings)) using (SqlCommand viewMovies = new SqlCommand("VIEW_ALL_MOVIE_THEORIES", connection)) { viewMovies.CommandType = CommandType.StoredProcedure; connection.Open(); //Setting up reader and using it. using (SqlDataReader sqlDataReader = viewMovies.ExecuteReader()) { while (sqlDataReader.Read()) { //Mapping to the DO from the reader. MovieTheoryDO movieTheory = mapper.MapReaderToSingle(sqlDataReader); displayMovieTheories.Add(movieTheory); } } } } 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(displayMovieTheories); }