Пример #1
0
    private void RefreshPhotos()
    {
        if (!SelectedMovieId.HasValue)
        {
            return;
        }

        var            movie          = Movies[SelectedMovieId.Value];
        var            containerName  = GetMovieContainerName(movie);
        AzureContainer azureContainer = new AzureContainer("StorageConnectionString");
        var            files          = azureContainer.GetListFiles(containerName);

        CheckBoxList1.DataSource = files.Select(f => System.IO.Path.GetFileName(f.OriginalString)).ToList();
        CheckBoxList1.DataBind();
    }
Пример #2
0
    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();
            }
        }
    }