Exemplo n.º 1
0
    protected void btnDeleteSelectedFiles_OnClick(object sender, EventArgs e)
    {
        if (!SelectedMovieId.HasValue)
        {
            lblSelectedMovie.Text = "Please select a movie";
            return;
        }

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

        azureContainer.SetContainer(GetMovieContainerName(movie));

        var items = CheckBoxList1.Items;

        using (var dataContext = new ProjectManhattanEntities1())
        {
            foreach (ListItem item in items)
            {
                if (item.Selected)
                {
                    azureContainer.DeleteFile(item.Text);

                    var moviePhoto = dataContext.MoviePhotoes
                                     .Where(m => m.MovieId == SelectedMovieId.Value).ToList()
                                     .FirstOrDefault(m =>
                                                     string.Equals(Path.GetFileName(m.MoviePhotoURL),
                                                                   item.Text,
                                                                   StringComparison.CurrentCultureIgnoreCase));

                    dataContext.MoviePhotoes.DeleteObject(moviePhoto);
                    dataContext.SaveChanges();
                }
            }
            RefreshPhotos();
        }
    }