//View one movie public MovieDO ViewMovie(long movieID) { MovieDO movie = new MovieDO(); try { using (SqlConnection connection = new SqlConnection(connectionStrings)) using (SqlCommand viewOneMovie = new SqlCommand("VIEW_MOVIES", connection)) { viewOneMovie.CommandType = CommandType.StoredProcedure; viewOneMovie.Parameters.AddWithValue("@MovieId", movieID); connection.Open(); using (SqlDataReader reader = viewOneMovie.ExecuteReader()) { if (reader.Read()) { movie = 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(movie); }
private async void btnDidISee_Click(object sender, RoutedEventArgs e) { string title = txtDidISee.Text; Movie movie = MovieDO.FindByTitle(title); string message = String.Empty; if (movie == null) { message = String.Format("You haven't seen {0}", title); } else { EpisodeEntity lastEpisode = RecordDO.GetEpisodesByMovie(movie).LastOrDefault(); if (lastEpisode == null) { message = "You have seen that one!"; } else { message = String.Format("Last episode you saw was S{0:D2}E{1:D2}", lastEpisode.Season, lastEpisode.Serie); } } MessageDialog dialog = new MessageDialog(message); await dialog.ShowAsync(); }
public ActionResult UpdateMovie(long id) { ActionResult response; //Mods and Admins can update movies. if (Session["Role"] != null) { if ((int)Session["Role"] != 1 && id > 0) { try { MovieDO movieDO = movieDataAccess.ViewMovie(id); MoviePO moviePO = mapper.MapDoToPo(movieDO); response = View(moviePO); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Movie"); } } else { response = RedirectToAction("Index", "Movie"); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
public ActionResult AddMovie(MoviePO form) { ActionResult response; //Anyone with an account can add a movie. if (Session["Role"] != null) { if (ModelState.IsValid) { try { MovieDO newMovie = mapper.MapPoToDo(form); movieDataAccess.AddMovie(newMovie); response = RedirectToAction("Index", "Movie"); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Movie"); } } else { response = View(form); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
public ActionResult UpdateMovie(int Id) { //Setting response to null ActionResult response = null; try { //Getting specific movie, by passing in the ID MovieDO movieDO = _movieDAO.ViewMovieByMovieId(Id); //MApping the movieDO to PO MoviePO moviePO = Mapping.Mapper.MovieDOtoPO(movieDO); //Setting response to the view to see the called upon movie response = View(moviePO); } catch (Exception exception) { //Logs if there's an issue _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace); //Setting response to see the movie details regardless response = RedirectToAction("MovieDetails", "Movie"); } finally { } //Show whichever response happened return(response); }
public ActionResult MovieDetails(int Id) { //Setting response to null ActionResult response = null; //Instantiating my movie/actor combo object MovieWithActorsPO movieWith = new MovieWithActorsPO(); try { foreach (ActorDO actor in _actorDAO.ViewActorsByMovieID(Id)) { //Passing in the actor from DO to PO to the moviewith combo movieWith.Actors.Add(Mapping.Mapper.ActorDOtoPO(actor)); } //Getting the details from the movieID that was passed MovieDO movieDO = _movieDAO.ViewMovieByMovieId(Id); //Mapping the Movie DO to PO to the movie/actor combo movieWith.Movie = Mapping.Mapper.MovieDOtoPO(movieDO); //Setting response to view the movie details and actors response = View(movieWith); } catch (Exception exception) { //Logs if there's an exception _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace); //Takes you to all movies if there's an exception response = RedirectToAction("ViewAllMovies", "Movie"); } finally { } //Show whichever response happened return(response); }
//Details for movie details. public ActionResult MovieDetails(long id) { ActionResult response; //Anyone with an account can see movie details. if (Session["Role"] != null) { if (id > 0) { try { //Map for one single movie for details. MovieDO movieDO = movieDataAccess.ViewMovie(id); MoviePO moviePO = mapper.MapDoToPo(movieDO); response = View(moviePO); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Movie"); } } else { response = RedirectToAction("Index", "Movie"); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
public ActionResult DeleteMovie(int id) { ActionResult response; //Only Admins can delete movies. if (Session["Role"] != null) { if ((int)Session["Role"] == 3 && id > 0) { try { MovieDO movie = movieDataAccess.ViewMovie(id); MoviePO deletedMovie = mapper.MapDoToPo(movie); movieDataAccess.DeleteMovie(deletedMovie.MovieId); response = RedirectToAction("Index", "Movie"); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Movie"); } } else { response = RedirectToAction("Index", "Movie"); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
public MovieDO MapReaderToSingle(SqlDataReader reader) { MovieDO result = new MovieDO(); //Checks to make sure there is some sort of value. if (reader["MovieId"] != DBNull.Value) { result.MovieId = (long)reader["MovieId"]; } if (reader["Title"] != DBNull.Value) { result.Title = (string)reader["Title"]; } if (reader["Director"] != DBNull.Value) { result.Director = (string)reader["Director"]; } if (reader["MoneyMadeOpeningWeekend"] != DBNull.Value) { result.OpeningWeekend = (string)reader["MoneyMadeOpeningWeekend"]; } if (reader["YearReleased"] != DBNull.Value) { result.YearReleased = (short)reader["YearReleased"]; } return(result); }
private async void btnAddEntry_Click(object sender, RoutedEventArgs e) { Episode episode = null; bool isSeries = Search.Type != "movie"; if (isSeries) { int season = Int32.Parse(txtSeason.Text); int series = Int32.Parse(txtEpisode.Text); if (!tvdb.EpisodeExists(season, series)) { await new MessageDialog("That episode does not exist.").ShowAsync(); return; } episode = EpisodeDO.FindOrCreate(season, series); } Movie movie = MovieDO.FindOrCreate(Search.ImdbID, Search.Title, Search.Year); bool created = RecordDO.TryCreate(isSeries, DateTime.Now, movie, Registry.Instance.User, episode); string message = created ? String.Format("{0} successfully added at {1}.", Search.Title, DateTime.Now) : String.Format("{0} already exists!", Search.Title); await new MessageDialog(message).ShowAsync(); }
//Update Movie public void UpdateMovie(MovieDO movie) { try { using (SqlConnection connection = new SqlConnection(connectionStrings)) using (SqlCommand updateMovie = new SqlCommand("UPDATE_MOVIE", connection)) { updateMovie.CommandType = CommandType.StoredProcedure; updateMovie.Parameters.AddWithValue("@MovieId", movie.MovieId); updateMovie.Parameters.AddWithValue("@Title", movie.Title); updateMovie.Parameters.AddWithValue("@Director", movie.Director); updateMovie.Parameters.AddWithValue("@MoneyMadeOpeningWeekend", movie.OpeningWeekend); updateMovie.Parameters.AddWithValue("@YearReleased", movie.YearReleased); connection.Open(); updateMovie.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 MoviePO MapDoToPo(MovieDO from) { MoviePO to = new MoviePO(); to.MovieId = from.MovieId; to.Title = from.Title; to.Director = from.Director; to.OpeningWeekend = from.OpeningWeekend; to.YearReleased = from.YearReleased; return(to); }
public static MovieDO MoviePOtoDO(MoviePO from) { MovieDO to = new MovieDO(); to.MovieID = from.MovieID; to.Title = from.Title; to.Rating = from.Rating; to.Runtime = from.Runtime; to.Director = from.Director; to.Synopsis = from.Synopsis; return(to); }
public ActionResult EditMovie(MovieAddEditModel model) { int movieId = model.MovieId; MovieDO _movie = MovieBL.GetMovie(movieId); MovieNameDO _movieName = MovieNameBL.GetAllDOByMovieID(movieId).SingleOrDefault(q => q.IsDefault == true); //MovieArchiveDO _movieArchive = MovieArchiveBL.GetAllDOByMovieID(movieId).SingleOrDefault(); //if (_movieArchive == null) _movieArchive = new MovieArchiveDO() { MovieID = movieId }; _movieName.LanguageID = ParseHelper.ToInt32(model.NameLanguageID); _movieName.Name = model.MovieName.Name; //_movieArchive.ArchiveID = Parse.ToInt32(model.ArchiveID); //_movieArchive.Resolution = model.ArchiveResolution; //_movieArchive.FileExtension = model.ArchiveFileExtension; //_movieArchive.Path = model.MovieArchive.Path; //if imdbid is changed, we need to reset imdb things first. string previousImdbId = _movie.ImdbID; if (string.IsNullOrEmpty(previousImdbId) == false && model.Movie.ImdbID != previousImdbId) { MovieBL.ResetImdbInformation(model.MovieId); _movie = MovieBL.GetMovie(movieId); _movie.ImdbID = model.Movie.ImdbID; } //save movie MovieBL.Save(_movie, UserID); //save the name MovieNameBL.Save(_movieName, UserID); //if (model.ArchiveExists == true) //{ // //save the archive // MovieArchiveBL.Save(_movieArchive, UserID); //} switch (model.Submit) { case "SubmitAndNavigateToMovie": return(RedirectToAction("DetailView", "Movie", new { id = movieId })); case "SubmitAndClearForm": default: return(RedirectToAction("AddMovie")); } }
//Update specific movie method public void UpdateMovieById(MovieDO movieDO) { //Setting to null SqlConnection connectionToSql = null; SqlCommand storedProcedure = null; try { //Instantiating the sqlconnection connectionToSql = new SqlConnection(_ConnectionString); //Instantiating my sqlcommand to get my procedure storedProcedure = new SqlCommand("UPDATE_MOVIE_BY_ID", connectionToSql); storedProcedure.CommandType = CommandType.StoredProcedure; //Using info from the database, the properties are put into the table storedProcedure.Parameters.AddWithValue("@MovieID", movieDO.MovieID); storedProcedure.Parameters.AddWithValue("@Title", movieDO.Title); storedProcedure.Parameters.AddWithValue("@Rating", movieDO.Rating); storedProcedure.Parameters.AddWithValue("@Runtime", movieDO.Runtime); storedProcedure.Parameters.AddWithValue("@Director", movieDO.Director); storedProcedure.Parameters.AddWithValue("@Synopsis", movieDO.Synopsis); //Opening the connection connectionToSql.Open(); //Not getting anything back storedProcedure.ExecuteNonQuery(); } catch (Exception exception) { //If there's an error, it is logged and thrown _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace); throw exception; } finally { //If there was a connection, close it and get rid of it if (connectionToSql != null) { connectionToSql.Close(); connectionToSql.Dispose(); } else { } } }
//Adding a movie method public void AddNewMovie(MovieDO movieDO) { //Setting to null SqlConnection connectionToSql = null; SqlCommand storedProcedure = null; try { //Instantiating connection connectionToSql = new SqlConnection(_ConnectionString); //Instantiating my sqlcommand to get my procedure storedProcedure = new SqlCommand("ADD_MOVIE", connectionToSql); storedProcedure.CommandType = CommandType.StoredProcedure; //Adding the properties of the object to the properties in the database storedProcedure.Parameters.AddWithValue("@Title", movieDO.Title); storedProcedure.Parameters.AddWithValue("@Rating", movieDO.Rating); storedProcedure.Parameters.AddWithValue("@Runtime", movieDO.Runtime); storedProcedure.Parameters.AddWithValue("@Director", movieDO.Director); storedProcedure.Parameters.AddWithValue("@Synopsis", movieDO.Synopsis); //Opening the connection connectionToSql.Open(); //Not getting anything back storedProcedure.ExecuteNonQuery(); } catch (Exception exception) { //If there's an exception, it is logged and thrown here _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace); throw exception; } finally { //If there was a connection to sql, it is closed and disposed here if (connectionToSql != null) { connectionToSql.Close(); connectionToSql.Dispose(); } else { } } }
public ActionResult UpdateMovie(MoviePO form) { ActionResult response; //Admins and Mods can update movies. if (Session["Role"] != null) { if ((int)Session["Role"] != 1) { if (ModelState.IsValid) { try { MovieDO movieDO = mapper.MapPoToDo(form); movieDataAccess.UpdateMovie(movieDO); response = RedirectToAction("Index", "Movie"); } catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Index", "Movie"); } } else { response = View(form); } } else { response = RedirectToAction("Index", "Movie"); } } else { response = RedirectToAction("Register", "Account"); } return(response); }
public async Task <IEnumerable <Tuple <string, IEnumerable <TheTVDBSharp.Models.Episode> > > > GetLatestEpisodes() { using (UnitOfWork uow = new UnitOfWork()) { IEnumerable <Record> series = uow.Records.Where(r => r.IsSeries == true); var grouped = series.GroupBy(s => s.MovieID); var res = new List <Tuple <string, IEnumerable <TheTVDBSharp.Models.Episode> > >(); foreach (IGrouping <int, Record> group in grouped) { Movie movie = MovieDO.FindById(group.Key); Episode last = RecordDO.GetLastEpisode(movie.Title); TvdbManager tvdb = new TvdbManager(movie.Title); await tvdb.Load(); res.Add(tvdb.CheckForNewEpisodes(movie.Title, last.Season, last.Serie)); } return(res); } }
public ActionResult UpdateMovie(MoviePO form) { //Setting response to null ActionResult response = null; if (ModelState.IsValid) { try { //Passing in the form to be updated to the DO MovieDO movieDO = Mapping.Mapper.MoviePOtoDO(form); //Passing in the movie to be updated via the update movie method _movieDAO.UpdateMovieById(movieDO); //Setting response to view the updated movie response = RedirectToAction("MovieDetails", "Movie", new { Id = form.MovieID }); } catch (Exception exception) { //Logs if there's an exception _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace); //Setting response to view all movies if there's a problem response = RedirectToAction("ViewAllMovies", "Movie"); } finally { } } else { //If modelstate is a no go, take them back to the form to try again response = View(form); } //Show whichever response happened return(response); }
//View all movies public List <MovieDO> ViewAllMovies() { List <MovieDO> displayMovies = new List <MovieDO>(); try { //Connecting and commanding to the SQL procedure. using (SqlConnection connection = new SqlConnection(connectionStrings)) using (SqlCommand viewMovies = new SqlCommand("VIEW_ALL_MOVIES", connection)) { viewMovies.CommandType = CommandType.StoredProcedure; connection.Open(); using (SqlDataReader sqlDataReader = viewMovies.ExecuteReader()) { while (sqlDataReader.Read()) { MovieDO movie = mapper.MapReaderToSingle(sqlDataReader); displayMovies.Add(movie); } } } } //For SQL Exceptions catch (SqlException sqlex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } //For regular Exceptions. catch (Exception ex) { logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } return(displayMovies); }
public static int Save(MovieDO movieDO, int userID) { Repository <MOV_M_Movie> rep = new Repository <MOV_M_Movie>(MArchiveDataContextProvider.Instance); MOV_M_Movie movieToAdd = null; if (movieDO.ID == 0) { movieToAdd = new MOV_M_Movie( ); ObjectMapper.MapObjects(movieDO, movieToAdd, AuditInfo.Fields); rep.InsertOnSubmit(movieToAdd); } else { movieToAdd = rep.GetAll( ).Single(x => x.ID == movieDO.ID); ObjectMapper.MapObjects(movieDO, movieToAdd, AuditInfo.Fields); } rep.DCP.CommitChanges(userID); InvalidateCache(CacheAreaKey); ObjectMapper.MapObjects(movieToAdd, movieDO); return(movieDO.ID); }
//Using list to view all my movies public List <MovieDO> ViewAllMovies() { //Instantiating my list List <MovieDO> movieList = new List <MovieDO>(); //Instantiating my table for movies DataTable movieTable = new DataTable(); //Setting all to null SqlConnection connectionToSql = null; SqlCommand storedProcedure = null; SqlDataAdapter adapter = null; try { //Instantiating connection connectionToSql = new SqlConnection(_ConnectionString); //Instantiating my sqlcommand to get my procedure storedProcedure = new SqlCommand("OBTAIN_MOVIES", connectionToSql); storedProcedure.CommandType = CommandType.StoredProcedure; //Establishing connection to sql connectionToSql.Open(); //Creating my adapter adapter = new SqlDataAdapter(storedProcedure); //Using my datatable to fill the adapter adapter.Fill(movieTable); foreach (DataRow row in movieTable.Rows) { //Instantiating my movie object MovieDO movieDO = new MovieDO(); //Parsing the movieID to string movieDO.MovieID = int.Parse(row["MovieID"].ToString()); //Taking the title of the object and puting it in the table movieDO.Title = row["Title"].ToString().Trim(); //Taking the rating of the object and puting it in the table movieDO.Rating = row["Rating"].ToString().Trim(); //Parsing the runtime to string, to be put in my datatable movieDO.Runtime = int.Parse(row["Runtime"].ToString()); //Taking the director of the object and puting it in the table movieDO.Director = row["Director"].ToString().Trim(); //Taking the description of the object and puting it in the table movieDO.Synopsis = row["Synopsis"].ToString().Trim(); //This is where all of the above is added to the table movieList.Add(movieDO); } } catch (Exception exception) { //If there's an error, it is logged _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace); throw exception; } finally { //If there was a connection, close it and get rid of it if (connectionToSql != null) { connectionToSql.Close(); connectionToSql.Dispose(); } else { } //Getting rid of adapter now if (adapter != null) { adapter.Dispose(); } else { } } //Showing the table, using what was put in return(movieList); }
public async Task AddMovieAsync(MovieDO movie) { await _context.Movies.InsertOneAsync(movie); }
private void getMovieInfoByIdAndSave(string imdbId, MovieDO movie, TextWriter tw, DateTime start) { ImdbModel imdbInfo = new ImdbModel( ); try { imdbInfo = ImdbHelper.getMovieInformation(imdbId, tw, start); logHelper.logLine(tw, "Imdb information parsed successfully. Starting operation 'Basic Info'"); #region Basic Info (not updated in db yet) if (string.IsNullOrEmpty(movie.ImdbID)) { movie.ImdbID = imdbId; } if (string.IsNullOrEmpty(movie.ImdbPoster) && !string.IsNullOrEmpty(imdbInfo.picturePath)) { string savePath = getSavePath( ); string fileName = FileSystemHelper.prepareFileNameForPicture(imdbInfo.picturePath.Substring(imdbInfo.picturePath.LastIndexOf('/')), new MovieNameModel { OriginalName = movie.OriginalName }, savePath); WebRequestHelper.Download(imdbInfo.picturePath, savePath + fileName); movie.ImdbPoster = fileName; } movie.ImdbRating = imdbInfo.imdbRating; if (movie.Year == null || movie.Year == 0) { movie.Year = imdbInfo.year; } #endregion Basic Info logHelper.logLine(tw, "Basic Info inserted"); logHelper.logLine(tw, "Starting operation 'Genres'"); #region types if (MovieTypeBL.GetAllByMovieID(movie.ID).Count() < 1) { try { if (imdbInfo.genres != null) { foreach (string item in imdbInfo.genres) { if (allTypes.ContainsKey(item)) { MovieTypeBL.Save(new MovieTypeDO( ) { MovieID = movie.ID, TypeID = allTypes[item] }, 1); } else { int currentID = TypeBL.Save(new MArchive.Domain.Lookup.TypeDO( ) { Name = item }, 1).ID; //MovieTypeBL.Save( movie.ID, item, 1 ); MovieTypeBL.Save(new MovieTypeDO( ) { MovieID = movie.ID, TypeID = currentID }, 1); allTypes.Add(item, currentID); } } } logHelper.logLine(tw, "Genres inserted"); } catch (Exception ex) { logHelper.logLine(tw, "Genres could not be inserted."); logHelper.logException(tw, ex); logHelper.logLine(tw); } } #endregion types logHelper.logLine(tw, "Starting operation 'Actors'"); #region actors if (MovieActorBL.GetAllByMovieID(movie.ID).Count( ) < 1) { try { if (imdbInfo.cast != null) { foreach (string item in imdbInfo.cast) { if (allActors.ContainsKey(item)) { MovieActorBL.Save(new MovieActorDO( ) { MovieID = movie.ID, ActorID = allActors[item] }, 1); } else { int currentID = ActorBL.Save(new MArchive.Domain.Lookup.ActorDO( ) { Name = item }, 1).ID; MovieActorBL.Save(new MovieActorDO( ) { MovieID = movie.ID, ActorID = currentID }, 1); allActors.Add(item, currentID); } } } logHelper.logLine(tw, "Actors inserted"); } catch (Exception ex) { logHelper.logLine(tw, "Actors could not be inserted."); logHelper.logException(tw, ex); logHelper.logLine(tw); } } #endregion actors logHelper.logLine(tw, "Starting operation 'Languages'"); #region languages if (MovieLanguageBL.GetAllByMovieID(movie.ID).Count( ) < 1) { try { if (imdbInfo.languages != null) { foreach (string item in imdbInfo.languages) { if (allLanguages.ContainsKey(item)) { MovieLanguageBL.Save(new MovieLanguageDO( ) { MovieID = movie.ID, LanguageID = allLanguages[item] }, 1); } else { int currentID = LanguageBL.Save(new MArchive.Domain.Lookup.LanguageDO( ) { Name = item }, 1).ID; MovieLanguageBL.Save(new MovieLanguageDO( ) { MovieID = movie.ID, LanguageID = currentID }, 1); allLanguages.Add(item, currentID); } } } logHelper.logLine(tw, "Languages inserted"); } catch (Exception ex) { logHelper.logLine(tw, "Languages could not be inserted."); logHelper.logException(tw, ex); logHelper.logLine(tw); } } #endregion languages logHelper.logLine(tw, "Starting operation 'Directors'"); #region directors if (MovieDirectorBL.GetAllByMovieID(movie.ID).Count( ) < 1) { try { if (imdbInfo.directors != null) { foreach (string item in imdbInfo.directors) { if (allDirectors.ContainsKey(item)) { MovieDirectorBL.Save(new MovieDirectorDO( ) { MovieID = movie.ID, DirectorID = allDirectors[item] }, 1); } else { int currentID = DirectorBL.Save(new MArchive.Domain.Lookup.DirectorDO( ) { Name = item }, 1).ID; MovieDirectorBL.Save(new MovieDirectorDO( ) { MovieID = movie.ID, DirectorID = currentID }, 1); allDirectors.Add(item, currentID); } } } logHelper.logLine(tw, "Directors inserted"); } catch (Exception ex) { logHelper.logLine(tw, "Directors could not be inserted."); logHelper.logException(tw, ex); logHelper.logLine(tw); } } #endregion directors logHelper.logLine(tw, "Starting operation 'Writers'"); #region writers if (MovieWriterBL.GetAllByMovieID(movie.ID).Count( ) < 1) { try { if (imdbInfo.writers != null) { foreach (string item in imdbInfo.writers) { if (allWriters.ContainsKey(item)) { MovieWriterBL.Save(new MovieWriterDO( ) { MovieID = movie.ID, WriterID = allWriters[item] }, 1); } else { int currentID = WriterBL.Save(new MArchive.Domain.Lookup.WriterDO( ) { Name = item }, 1).ID; MovieWriterBL.Save(new MovieWriterDO( ) { MovieID = movie.ID, WriterID = currentID }, 1); allWriters.Add(item, currentID); } } } logHelper.logLine(tw, "Writers inserted"); } catch (Exception ex) { logHelper.logLine(tw, "Writers could not be inserted."); logHelper.logException(tw, ex); logHelper.logLine(tw); } } #endregion writers logHelper.logLine(tw, "Updating 'movie' table"); movie.ImdbParsed = true; movie.ImdbLastParseDate = movie.UpdateDate = DateTime.Now; MovieBL.Save(movie, 1); logHelper.logLine(tw, "Table update successful"); } catch (Exception ex) { logHelper.logException(tw, ex); } }
private void copyItemToList(List <MovieDO> src, List <MovieDO> dst, int mId) { MovieDO itemToCopy = src.Find(i => i.ID == mId); dst.Add(itemToCopy); }
//Movie details method public MovieDO ViewMovieByMovieId(int IdInput) { //Setting all to null MovieDO movieDO = null; SqlConnection connectionToSql = null; SqlCommand storedProcedure = null; SqlDataAdapter adapter = null; DataTable movieTable = new DataTable(); try { //Instantiating connection to sql connectionToSql = new SqlConnection(_ConnectionString); //Instantiating my sqlcommand to get my procedure storedProcedure = new SqlCommand("OBTAIN_MOVIE_BY_MOVIE_ID", connectionToSql); storedProcedure.CommandType = CommandType.StoredProcedure; //Throwing the movieID into the procedure to get the details storedProcedure.Parameters.AddWithValue("@MovieID", IdInput); //Opening connection connectionToSql.Open(); //Creating my adapter adapter = new SqlDataAdapter(storedProcedure); //Using my datatable to fill the adapter adapter.Fill(movieTable); if (movieTable.Rows.Count > 0) { //Setting up my table DataRow row = movieTable.Rows[0]; //Instantiating my object movieDO = new MovieDO(); //Using info from the database, the properties are put into the table movieDO.MovieID = int.Parse(row["MovieID"].ToString()); movieDO.Title = row["Title"].ToString().Trim(); movieDO.Rating = row["Rating"].ToString().Trim(); movieDO.Runtime = int.Parse(row["Runtime"].ToString()); movieDO.Director = row["Director"].ToString().Trim(); movieDO.Synopsis = row["Synopsis"].ToString().Trim(); } else { } } catch (Exception exception) { //If there's an error, it is logged and thrown _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace); throw exception; } finally { //If there was a connection, close it and get rid of it if (connectionToSql != null) { connectionToSql.Close(); connectionToSql.Dispose(); } else { } //Getting rid of adapter if (adapter != null) { adapter.Dispose(); } else { } } //Showing the finished movie return(movieDO); }
//Seeing movies an actor has been in...method public List <MovieDO> ViewMoviesByActorID(int IdInput) { //Setting all to null List <MovieDO> movieList = new List <MovieDO>(); SqlConnection connectionToSql = null; SqlCommand storedProcedure = null; SqlDataAdapter adapter = null; DataTable movieTable = new DataTable(); try { //Instantiating connection to sql connectionToSql = new SqlConnection(_ConnectionString); //Instantiating my sqlcommand to get my procedure storedProcedure = new SqlCommand("OBTAIN_MOVIE_BY_ACTOR_ID", connectionToSql); storedProcedure.CommandType = CommandType.StoredProcedure; //Throwing the actorID into the procedure to get the details storedProcedure.Parameters.AddWithValue("@ActorID", IdInput); //Opening connection connectionToSql.Open(); //Instantiating my adapter adapter = new SqlDataAdapter(storedProcedure); var counter = adapter.Fill(movieTable); foreach (DataRow firstRow in movieTable.Rows) { MovieDO movieDO = new MovieDO(); if (int.TryParse(firstRow["MovieID"].ToString(), out counter)) { movieDO.MovieID = int.Parse(firstRow["MovieID"].ToString()); movieDO.Title = firstRow["Title"].ToString().Trim(); movieDO.Rating = firstRow["Rating"].ToString().Trim(); movieDO.Runtime = int.Parse(firstRow["Runtime"].ToString()); } else { } movieDO.Director = firstRow["Director"].ToString().Trim(); movieDO.Synopsis = firstRow["Synopsis"].ToString().Trim(); //Adding the individual movie to the list movieList.Add(movieDO); } } catch (Exception exception) { //If there's an error, it is logged and thrown _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace); throw exception; } finally { //If there was a connection to sql, it is closed and disposed here if (connectionToSql != null) { connectionToSql.Close(); connectionToSql.Dispose(); } else { } //Getting rid of adapter if (adapter != null) { adapter.Dispose(); } else { } } //Showing the table, using what was put in return(movieList); }