public static MovieExtendModel ToObject(DataRow reader) { MovieExtendModel movieExtendModel = new MovieExtendModel(); movieExtendModel.imdbID = reader[0].ToString(); movieExtendModel.title = reader[1].ToString(); movieExtendModel.poster = reader[2].ToString(); movieExtendModel.userID = reader[3].ToString(); movieExtendModel.year = int.Parse(reader[4].ToString()); movieExtendModel.plot = reader[5].ToString(); movieExtendModel.website = reader[6].ToString(); movieExtendModel.rated = reader[7].ToString(); movieExtendModel.imdbRating = float.Parse(reader[8].ToString()); try { movieExtendModel.seen = int.Parse(reader[9].ToString()) > 0; } catch (Exception ex) { Debug.WriteLine("trying to parse mysql seen: " + ex.Message); } try { movieExtendModel.seen = bool.Parse(reader[9].ToString()); } catch (Exception ex) { Debug.WriteLine("trying to parse mssql seen: " + ex.Message); } Debug.WriteLine("MovieExtendModel:" + movieExtendModel.ToString()); return(movieExtendModel); }
public HttpResponseMessage UpdateMovie(string id, MovieExtendModel movieModel) { try { if (movieModel == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Data is null.")); } //if (!ModelState.IsValid) //{ // Errors errors = ErrorsHelper.GetErrors(ModelState); // return Request.CreateResponse(HttpStatusCode.BadRequest, errors); //} string uid = base.ControllerContext.RequestContext.Principal.Identity.Name; movieModel.userID = uid; movieModel.imdbID = id; MovieExtendModel updatedMovie = moviesExtendRepository.UpdateMovie(movieModel); return(Request.CreateResponse(HttpStatusCode.OK, updatedMovie)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors)); } }
public List <MovieExtendModel> GetByWord(string word, string userID) { if (word.Equals(string.Empty) || word.Equals("")) { throw new ArgumentOutOfRangeException(); } if (userID.Equals(string.Empty) || userID.Equals("")) { throw new ArgumentOutOfRangeException(); } DataTable dt = new DataTable(); List <MovieExtendModel> arrMovie = new List <MovieExtendModel>(); using (SqlCommand command = new SqlCommand()) { dt = GetMultipleQuery(MovieExtendStringsSql.GetByWord(word, userID)); } foreach (DataRow ms in dt.Rows) { arrMovie.Add(MovieExtendModel.ToObject(ms)); } return(arrMovie); }
public MovieExtendModel GetByTitle(string title, string userID) { if (title.Equals(string.Empty) || title.Equals("")) { throw new ArgumentOutOfRangeException(); } if (userID.Equals(string.Empty) || userID.Equals("")) { throw new ArgumentOutOfRangeException(); } DataTable dt = new DataTable(); MovieExtendModel movieModel = new MovieExtendModel(); using (SqlCommand command = new SqlCommand()) { dt = GetMultipleQuery(MovieExtendStringsSql.GetByTitle(title, userID)); } foreach (DataRow ms in dt.Rows) { movieModel = MovieExtendModel.ToObject(ms); } return(movieModel); }
static public SqlCommand UpdateMovie(MovieExtendModel movieModel) { if (GlobalVariable.queryType == 0) { return(CreateSqlCommand(movieModel, queryMoviesExtendUpdate)); } else { return(CreateSqlCommand(movieModel, procedureMoviesExtendUpdate)); } }
public HttpResponseMessage GetByTitle(string movieTitle) { try { string id = base.ControllerContext.RequestContext.Principal.Identity.Name; MovieExtendModel oneMovie = moviesExtendRepository.GetByTitle(movieTitle, id); return(Request.CreateResponse(HttpStatusCode.OK, oneMovie)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors)); } }
public MovieExtendModel UpdateMovie(MovieExtendModel movieModel) { DataTable dt = new DataTable(); using (SqlCommand command = new SqlCommand()) { dt = GetMultipleQuery(MovieExtendStringsSql.UpdateMovie(movieModel)); } foreach (DataRow ms in dt.Rows) { movieModel = MovieExtendModel.ToObject(ms); } return(movieModel); }
public MovieExtendModel AddMovie(MovieExtendModel movieModel) { if (GlobalVariable.queryType == 0) { MOVy movie = new MOVy { userID = movieModel.userID, movieImdbID = movieModel.imdbID, movieTitle = movieModel.title, moviePoster = movieModel.poster, movieYear = movieModel.year }; MOVIEEXTEND movieExtend = new MOVIEEXTEND { movieImdbID = movieModel.imdbID, moviePlot = movieModel.plot, movieUrl = movieModel.website, movieRated = movieModel.rated, movieImdbRating = movieModel.imdbRating, movieSeen = movieModel.seen, userID = movieModel.userID }; //movieExtend.MOVy = movie; DB.MOVIES.Add(movie); DB.MOVIEEXTENDS.Add(movieExtend); DB.SaveChanges(); return(GetById(movie.movieImdbID, movie.userID)); } else { return(DB.AddExtendedMovie(movieModel.imdbID, movieModel.title, movieModel.poster, movieModel.year, movieModel.userID, movieModel.plot, movieModel.website, movieModel.rated, movieModel.imdbRating, movieModel.seen).Select(m => new MovieExtendModel { userID = m.userID, title = m.movieTitle, poster = m.moviePoster, year = m.movieYear, imdbID = m.movieImdbID, plot = m.moviePlot, website = m.movieUrl, rated = m.movieRated, imdbRating = m.movieImdbRating.Value, seen = m.movieSeen.Value }).SingleOrDefault()); } }
static private SqlCommand CreateSqlCommand(MovieExtendModel movie, string commandText) { SqlCommand command = new SqlCommand(commandText); command.Parameters.AddWithValue("@movieImdbID", movie.imdbID); command.Parameters.AddWithValue("@movieTitle", movie.title); command.Parameters.AddWithValue("@moviePoster", movie.poster); command.Parameters.AddWithValue("@movieYear", movie.year); command.Parameters.AddWithValue("@userId", movie.userID); command.Parameters.AddWithValue("@moviePlot", movie.plot); command.Parameters.AddWithValue("@movieUrl", movie.website); command.Parameters.AddWithValue("@movieRated", movie.rated); command.Parameters.AddWithValue("@movieImdbRating", movie.imdbRating); command.Parameters.AddWithValue("@movieSeen", movie.seen); return(command); }
public MovieExtendModel UpdateMovie(MovieExtendModel movieModel) { _movies.ReplaceOne(movie => movie.imdbID.Equals(movieModel.imdbID) && movie.userID.Equals(movieModel.userID), movieModel); return(_movies.Find <MovieExtendModel>(movie => movie.imdbID.Equals(movieModel.imdbID) && movie.userID.Equals(movieModel.userID)).Project(m => new MovieExtendModel { userID = m.userID, imdbID = m.imdbID, title = m.title, poster = m.poster, year = m.year, plot = m.plot, website = m.website, rated = m.rated, imdbRating = m.imdbRating, seen = m.seen }).FirstOrDefault()); }
public MovieExtendModel UpdateMovie(MovieExtendModel movieModel) { if (GlobalVariable.queryType == 0) { MOVy movie = DB.MOVIES.Where(m => m.movieImdbID.Equals(movieModel.imdbID)).SingleOrDefault(); MOVIEEXTEND movieExtend = DB.MOVIEEXTENDS.Where(m => m.movieImdbID.Equals(movieModel.imdbID)).SingleOrDefault(); if (movie == null) { return(null); } movie.userID = movieModel.userID; movie.movieImdbID = movieModel.imdbID; movie.movieTitle = movieModel.title; movie.moviePoster = movieModel.poster; movie.movieYear = movieModel.year; movieExtend.movieImdbID = movieModel.imdbID; movieExtend.moviePlot = movieModel.plot; movieExtend.movieUrl = movieModel.website; movieExtend.movieRated = movieModel.rated; movieExtend.movieImdbRating = movieModel.imdbRating; movieExtend.movieSeen = movieModel.seen; movieExtend.userID = movieModel.userID; DB.SaveChanges(); return(GetById(movie.movieImdbID, movie.userID)); } else { return(DB.UpdateExtendedMovie(movieModel.imdbID, movieModel.title, movieModel.poster, movieModel.year, movieModel.userID, movieModel.plot, movieModel.website, movieModel.rated, movieModel.imdbRating, movieModel.seen).Select(m => new MovieExtendModel { userID = m.userID, title = m.movieTitle, poster = m.moviePoster, year = m.movieYear, imdbID = m.movieImdbID, plot = m.moviePlot, website = m.movieUrl, rated = m.movieRated, imdbRating = m.movieImdbRating.Value, seen = m.movieSeen.Value }).SingleOrDefault()); } }
public async Task <HttpResponseMessage> GetImdbById(string movieId) { //http://localhost:49270/api/imdbMovies/byId/tt3896198/ string id = base.ControllerContext.RequestContext.Principal.Identity.Name; try { UserModel userModel = usersRepository.GetOneUserById(id); MovieExtendModel oneMovie = await imdbRepository.GetImdbById(userModel.userImdbPass, movieId, id); return(Request.CreateResponse(HttpStatusCode.OK, oneMovie)); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors)); } }
public HttpResponseMessage AddMovie(MovieExtendModel movieModel) { try { HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.Created) { Content = new StringContent(JsonConvert.SerializeObject(moviesExtendRepository.AddMovie(movieModel))) }; return(hrm); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(errors.ToString()) }; return(hrm); } }
public HttpResponseMessage UpdateMovie(string updateById, MovieExtendModel movieModel) { try { movieModel.imdbID = updateById; HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(moviesExtendRepository.UpdateMovie(movieModel))) }; return(hrm); } catch (Exception ex) { Errors errors = ErrorsHelper.GetErrors(ex); HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(errors.ToString()) }; return(hrm); } }
public async Task <MovieExtendModel> GetImdbByTitle(string userPass, string movieTitle, string userId, string type = "", int year = 0, string r = "json", string plot = "short") { //type = movie, series, episode //y = 1981 //r=json, xml //plot = short, full MovieExtendModel movieModel = new MovieExtendModel(); string movie = ""; JObject jmovie = new JObject(); string url = "http://www.omdbapi.com/?" + "apikey=" + userPass + "&t=" + movieTitle; using (HttpClient client = new HttpClient()) { movie = await client.GetStringAsync(url); jmovie = JObject.Parse(movie); } return(createMovieExtendModel(jmovie, userPass, userId)); }
private MovieExtendModel createMovieExtendModel(JObject jmovie, string userPass, string userID) { MovieExtendModel movieModel = new MovieExtendModel(); try { movieModel.imdbID = jmovie.GetValue("imdbID").ToString(); } catch (Exception ex) { Debug.WriteLine("imdbID:" + ex.Message); movieModel.imdbID = ""; } try { movieModel.title = jmovie.GetValue("Title").ToString(); } catch (Exception ex) { Debug.WriteLine("title:" + ex.Message); movieModel.title = ""; } try { movieModel.plot = jmovie.GetValue("Plot").ToString(); } catch (Exception ex) { Debug.WriteLine("plot:" + ex.Message); movieModel.plot = ""; } try { movieModel.website = jmovie.GetValue("Website").ToString(); } catch (Exception ex) { Debug.WriteLine("website:" + ex.Message); movieModel.website = ""; } try { movieModel.rated = jmovie.GetValue("Rated").ToString(); } catch (Exception ex) { Debug.WriteLine("rated:" + ex.Message); movieModel.rated = ""; } movieModel.seen = false; try { movieModel.poster = jmovie.GetValue("Poster").ToString(); } catch (Exception ex) { Debug.WriteLine("poster:" + ex.Message); movieModel.poster = ""; } try { movieModel.userID = userID; } catch (Exception ex) { Debug.WriteLine("userId:" + ex.Message); movieModel.userID = ""; } try { movieModel.year = int.Parse(jmovie.GetValue("Year").ToString()); } catch (Exception ex) { Debug.WriteLine("year:" + ex.Message); movieModel.year = 0; } try { movieModel.imdbRating = float.Parse(jmovie.GetValue("imdbRating").ToString()); } catch (Exception ex) { Debug.WriteLine("imdbRating:" + ex.Message); movieModel.imdbRating = 0; } return(movieModel); }