protected void UploadClick(object sender, EventArgs e) { if (!SelectedMovieId.HasValue) { lblSelectedMovie.Text = "Please select a movie"; return; } if (!FileUpload1.HasFiles) { return; } var movie = Movies[SelectedMovieId.Value]; AzureContainer azureContainer = new AzureContainer("StorageConnectionString"); azureContainer.SetContainer(GetMovieContainerName(movie)); bool isNewMoviePhotosAvailable = false; var files = FileUpload1.PostedFiles; using (var dataContext = new ProjectManhattanEntities1()) { foreach (var file in files) { var photoURL = azureContainer.StoreFile(file.FileName, file.InputStream); MoviePhoto moviePhoto = dataContext.MoviePhotoes .Where(m => m.MovieId == SelectedMovieId.Value).ToList() .FirstOrDefault(m => string.Equals(Path.GetFileName(m.MoviePhotoURL), Path.GetFileName(photoURL), StringComparison.CurrentCultureIgnoreCase)); if (moviePhoto == null) { moviePhoto = new MoviePhoto() { MovieId = movie.MovieId, MoviePhotoURL = photoURL, }; dataContext.MoviePhotoes.AddObject(moviePhoto); isNewMoviePhotosAvailable = true; } } if (isNewMoviePhotosAvailable) { dataContext.SaveChanges(); RefreshPhotos(); } } }
public async Task <IActionResult> AddMoviePhoto(int movieId, [FromForm] PhotoForUploadDTO photoForUploadDTO) { var movie = await appRepository.GetMovie(movieId); var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); if (movie == null) { movie = await appRepository.GetMovie(movieId, userId); } if (movie == null) { return(BadRequest("Movie does not exist")); } if (photoForUploadDTO.File.Length > 10 * 1024 * 1024) { return(BadRequest("Max file size should be 10 MB.")); } using (var stream = photoForUploadDTO.File.OpenReadStream()) { if (!IsImage(stream)) { return(BadRequest("The file " + photoForUploadDTO.File.FileName + " is not an image!")); } } var photo = await UploadPhoto(photoForUploadDTO.File); if (photo == null) { return(BadRequest("Unable to upload photo")); } var moviePhoto = new MoviePhoto(); if (movie.IsApproved) { moviePhoto.IsMovieApproved = true; } moviePhoto.Movie = movie; moviePhoto.MovieId = movie.Id; moviePhoto.Photo = photo; moviePhoto.PhotoId = photo.Id; appRepository.Add(moviePhoto); if (await appRepository.SaveAll()) { return(CreatedAtRoute("GetMoviePhoto", new{ movieId = movie.Id, photoId = photo.Id }, moviePhoto)); } return(BadRequest("Unable to add photo")); }
protected void btnSyncMoviePhotos_OnClick(object sender, EventArgs e) { AzureContainer azureContainer = new AzureContainer("StorageConnectionString"); using (var dataContext = new ProjectManhattanEntities1()) { var movies = dataContext.Movies .Include("MoviePhotoes") .ToList(); bool isNewMoviePhotosAvailable = false; foreach (var movie in movies) { var containerName = GetMovieContainerName(movie); var existingPhotosInDB = new HashSet <string>(movie.MoviePhotoes.Select(m => m.MoviePhotoURL)); foreach (var uri in azureContainer.GetListFiles(containerName)) { var photoURL = uri.OriginalString; if (!existingPhotosInDB.Contains(photoURL)) { //Insert the missing movie photo MoviePhoto moviePhoto = new MoviePhoto() { MovieId = movie.MovieId, MoviePhotoURL = photoURL, }; dataContext.MoviePhotoes.AddObject(moviePhoto); isNewMoviePhotosAvailable = true; } } } if (isNewMoviePhotosAvailable) { dataContext.SaveChanges(); } } }
private void lstSonuc_SelectedIndexChanged(object sender, EventArgs e) { lstDirectors.Items.Clear(); lstWriters.Items.Clear(); lstStars.Items.Clear(); if (Baglanti.State == ConnectionState.Closed) { Baglanti.Open(); } SqlCommand commandcheck = new SqlCommand("SELECT * FROM Movie where Name='" + lstSonuc.SelectedItem.ToString() + "'", Baglanti); SqlDataReader rdrcheck = commandcheck.ExecuteReader(); if (rdrcheck.Read()) { Baglanti.Close(); if (Baglanti.State == ConnectionState.Closed) { Baglanti.Open(); } SqlCommand command = new SqlCommand("SELECT * FROM Movie where Name='" + lstSonuc.SelectedItem.ToString() + "'", Baglanti); SqlDataReader rdr = command.ExecuteReader(); while (rdr.Read()) { lblDescription.Text = rdr["Description"].ToString(); MoviePhoto.Load(rdr["Image"].ToString()); } rdr.Close(); Baglanti.Close(); if (Baglanti.State == ConnectionState.Closed) { Baglanti.Open(); } SqlCommand commandDirectors = new SqlCommand("SELECT C.Name, M.Name , R.Name FROM Cast C , Movie M, MovieCastRole MCR,Role r WHERE C.Id = MCR.CastId AND M.Id = MCR.MovieId AND R.Id = MCR.RoleId AND R.ID = 1 AND M.Name='" + lstSonuc.SelectedItem.ToString() + "'", Baglanti); SqlDataReader rdrDirectors = commandDirectors.ExecuteReader(); while (rdrDirectors.Read()) { lstDirectors.Items.Add(rdrDirectors["Name"].ToString()); } rdrDirectors.Close(); Baglanti.Close(); if (Baglanti.State == ConnectionState.Closed) { Baglanti.Open(); } SqlCommand commandWriter = new SqlCommand("SELECT C.Name, M.Name , R.Name FROM Cast C , Movie M, MovieCastRole MCR,Role r WHERE C.Id = MCR.CastId AND M.Id = MCR.MovieId AND R.Id = MCR.RoleId AND R.ID = 2 AND M.Name='" + lstSonuc.SelectedItem.ToString() + "'", Baglanti); SqlDataReader rdrWriter = commandWriter.ExecuteReader(); while (rdrWriter.Read()) { lstWriters.Items.Add(rdrWriter["Name"].ToString()); } rdrWriter.Close(); Baglanti.Close(); if (Baglanti.State == ConnectionState.Closed) { Baglanti.Open(); } SqlCommand commandStars = new SqlCommand("SELECT C.Name, M.Name , R.Name FROM Cast C , Movie M, MovieCastRole MCR,Role r WHERE C.Id = MCR.CastId AND M.Id = MCR.MovieId AND R.Id = MCR.RoleId AND R.ID = 3 AND M.Name='" + lstSonuc.SelectedItem.ToString() + "'", Baglanti); SqlDataReader rdrStars = commandStars.ExecuteReader(); while (rdrStars.Read()) { lstStars.Items.Add(rdrStars["Name"].ToString()); } rdrStars.Close(); Baglanti.Close(); } else { Movie movie = (Movie)lstSonuc.SelectedItem; WebClient wc = new WebClient(); string result = wc.DownloadString("https://www.imdb.com" + movie.Link); string firstKey = "<div class=\"summary_text\">"; string endKey = "</div>"; int startIndex = result.IndexOf(firstKey) + firstKey.Length; int endIndex = result.IndexOf(endKey, startIndex); result = result.Substring(startIndex, endIndex - startIndex).Trim(); lblDescription.Text = result.ToString().Trim(); result = wc.DownloadString("https://www.imdb.com" + movie.Link); firstKey = "<div class=\"poster\">"; endKey = "</div>"; startIndex = result.IndexOf(firstKey); endIndex = result.IndexOf(endKey, startIndex + firstKey.Length); result = result.Substring(startIndex + firstKey.Length, endIndex - startIndex); firstKey = "src=\""; endKey = "\" />"; startIndex = result.IndexOf(firstKey); endIndex = result.IndexOf(endKey, startIndex + firstKey.Length); movie.Image = result.Substring(startIndex + firstKey.Length, endIndex - (startIndex + firstKey.Length)); // movie classın alanına ekledik MoviePhoto.Load(movie.Image); result = wc.DownloadString("https://www.imdb.com" + movie.Link); firstKey = "\"director\":"; endKey = ",\n \""; startIndex = result.IndexOf(firstKey); Cast cast = new Cast(); if (startIndex > -1) { endIndex = result.IndexOf(endKey, startIndex); result = result.Substring(startIndex, endIndex - startIndex); firstKey = "\"name\": \""; endKey = "\""; startIndex = result.IndexOf(firstKey) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); while (startIndex > firstKey.Length) { cast.Name = result.Substring(startIndex, endIndex - startIndex); lstDirectors.Items.Add(cast.Name); startIndex = result.IndexOf(firstKey, endIndex) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); } } else { lstDirectors.Items.Clear(); } result = wc.DownloadString("https://www.imdb.com" + movie.Link); firstKey = "\"creator\":"; endKey = ",\n \""; startIndex = result.IndexOf(firstKey); if (startIndex > -1) { endIndex = result.IndexOf(endKey, startIndex); result = result.Substring(startIndex, endIndex - startIndex); firstKey = "\"name\": \""; endKey = "\""; startIndex = result.IndexOf(firstKey) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); while (startIndex > firstKey.Length) { cast.Name = result.Substring(startIndex, endIndex - startIndex); lstWriters.Items.Add(cast.Name); startIndex = result.IndexOf(firstKey, endIndex) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); } } else { lstWriters.Items.Clear(); } result = wc.DownloadString("https://www.imdb.com" + movie.Link); firstKey = " \"actor\": ["; endKey = ",\n \""; startIndex = result.IndexOf(firstKey); if (startIndex > -1) { endIndex = result.IndexOf(endKey, startIndex); result = result.Substring(startIndex, endIndex - startIndex); firstKey = "\"name\": \""; endKey = "\""; startIndex = result.IndexOf(firstKey) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); while (startIndex > firstKey.Length) { cast.Name = result.Substring(startIndex, endIndex - startIndex); lstStars.Items.Add(cast.Name); startIndex = result.IndexOf(firstKey, endIndex) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); } } else { lstStars.Items.Clear(); } try { Baglanti.Close(); if (Baglanti.State == ConnectionState.Closed) { Baglanti.Open(); } SqlCommand komut = new SqlCommand("AddMovieAndMovieCastRole", Baglanti); komut.CommandType = CommandType.StoredProcedure; komut.Parameters.AddWithValue("@Name", lstSonuc.SelectedItem.ToString()); komut.Parameters.AddWithValue("@Year", movie.Year); komut.Parameters.AddWithValue("@Description", lblDescription.Text); komut.Parameters.AddWithValue("@Image", movie.Image); komut.Parameters.AddWithValue("@Link", movie.Link); komut.ExecuteNonQuery(); Baglanti.Close(); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } result = wc.DownloadString("https://www.imdb.com" + movie.Link); firstKey = "\"director\":"; endKey = ",\n \""; startIndex = result.IndexOf(firstKey); if (startIndex > -1) { endIndex = result.IndexOf(endKey, startIndex); result = result.Substring(startIndex, endIndex - startIndex); firstKey = "\"name\": \""; endKey = "\""; startIndex = result.IndexOf(firstKey) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); while (startIndex > firstKey.Length) { cast.Name = result.Substring(startIndex, endIndex - startIndex); Baglanti.Open(); string IdSorgu = $"SELECT Id FROM Movie where Link = '{movie.Link}'"; SqlCommand getId = new SqlCommand(IdSorgu, Baglanti); int Id = Convert.ToInt32(getId.ExecuteScalar().ToString()); SqlCommand komutCast = new SqlCommand("AddCastAndMovieCastRole", Baglanti); komutCast.CommandType = CommandType.StoredProcedure; komutCast.Parameters.AddWithValue("@Name", cast.Name); komutCast.Parameters.AddWithValue("@CastPhoto", "Yönetmen Foto"); komutCast.Parameters.AddWithValue("@Bio", "Bio Acıklama"); komutCast.Parameters.AddWithValue("@MovieId", Id); komutCast.Parameters.AddWithValue("@RoleId", 1); komutCast.ExecuteNonQuery(); Baglanti.Close(); startIndex = result.IndexOf(firstKey, endIndex) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); } } else { lstDirectors.Items.Clear(); } result = wc.DownloadString("https://www.imdb.com" + movie.Link); firstKey = "\"creator\":"; endKey = ",\n \""; startIndex = result.IndexOf(firstKey); if (startIndex > -1) { endIndex = result.IndexOf(endKey, startIndex); result = result.Substring(startIndex, endIndex - startIndex); firstKey = "\"name\": \""; endKey = "\""; startIndex = result.IndexOf(firstKey) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); while (startIndex > firstKey.Length) { cast.Name = result.Substring(startIndex, endIndex - startIndex); if (Baglanti.State == ConnectionState.Closed) { Baglanti.Open(); } string IdSorgu = $"SELECT Id FROM Movie where Link = '{movie.Link}'"; SqlCommand getId = new SqlCommand(IdSorgu, Baglanti); int Id = Convert.ToInt32(getId.ExecuteScalar().ToString()); SqlCommand komutCast = new SqlCommand("AddCastAndMovieCastRole", Baglanti); komutCast.CommandType = CommandType.StoredProcedure; komutCast.Parameters.AddWithValue("@Name", cast.Name); komutCast.Parameters.AddWithValue("@CastPhoto", "Yönetmen Foto"); komutCast.Parameters.AddWithValue("@Bio", "Bio Acıklama"); komutCast.Parameters.AddWithValue("@MovieId", Id); komutCast.Parameters.AddWithValue("@RoleId", 2); komutCast.ExecuteNonQuery(); Baglanti.Close(); startIndex = result.IndexOf(firstKey, endIndex) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); } } else { lstWriters.Items.Clear(); } result = wc.DownloadString("https://www.imdb.com" + movie.Link); firstKey = " \"actor\": ["; endKey = ",\n \""; startIndex = result.IndexOf(firstKey); if (startIndex > -1) { endIndex = result.IndexOf(endKey, startIndex); result = result.Substring(startIndex, endIndex - startIndex); firstKey = "\"name\": \""; endKey = "\""; startIndex = result.IndexOf(firstKey) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); while (startIndex > firstKey.Length) { cast.Name = result.Substring(startIndex, endIndex - startIndex); if (Baglanti.State == ConnectionState.Closed) { Baglanti.Open(); } string IdSorgu = $"SELECT Id FROM Movie where Link = '{movie.Link}'"; SqlCommand getId = new SqlCommand(IdSorgu, Baglanti); int Id = Convert.ToInt32(getId.ExecuteScalar().ToString()); SqlCommand komutCast = new SqlCommand("AddCastAndMovieCastRole", Baglanti); komutCast.CommandType = CommandType.StoredProcedure; komutCast.Parameters.AddWithValue("@Name", cast.Name); komutCast.Parameters.AddWithValue("@CastPhoto", "Yönetmen Foto"); komutCast.Parameters.AddWithValue("@Bio", "Bio Acıklama"); komutCast.Parameters.AddWithValue("@MovieId", Id); komutCast.Parameters.AddWithValue("@RoleId", 3); komutCast.ExecuteNonQuery(); Baglanti.Close(); startIndex = result.IndexOf(firstKey, endIndex) + firstKey.Length; endIndex = result.IndexOf(endKey, startIndex); } } else { lstStars.Items.Clear(); } } }