public ServiceReview Delete(int fileId, User currenUser, IFileUploadSystemData data, bool isAdminAction) { FileEntity file = null; if (isAdminAction) { file = data.Files.GetById(fileId); } else { file = currenUser.Files.Where(f => f.Id == fileId).FirstOrDefault();; } string message = string.Empty; if ((file as DirectoryEntity) != null) { var childrenFiles = DFSNestedElementFinder(currenUser, fileId); foreach (var element in childrenFiles) { this.Data.Files.Delete(element.Id); // If element is a Binary file it must be deleted from the file system too if (element.IsDirectory == false) { FileManipulator.DeleteFile(element.Id, element.Type); } } message = string.Format("Directory ({0}) deleted successfully!", file.Name); } else { var binFile = file as BinaryFile; FileManipulator.DeleteFile(binFile.Id, binFile.Type); this.Data.Files.Delete(fileId); message = string.Format("File ({0}) deleted successfully!", binFile.Name); } this.Data.SaveChanges(); return(new ServiceReview(message, file.LocationId, false)); }
private async void ContextMenu1_Click(object sender, RoutedEventArgs e) { var item = sender as MenuItem; if (item == null) { return; } var menu = item.Parent as ContextMenu; switch (item.Header.ToString()) { case "Copy": FileManipulator.CopyFile(selectedListItem); break; case "Paste": FileManipulator.PasteFileBy(ListView1.IsFocused ? _graphics1.Path : _graphics2.Path); break; case "Cut": FileManipulator.CutFile(selectedListItem); break; case "Delete": FileManipulator.DeleteFile(selectedListItem); break; case "Archive": ShowChooseDialog(selectedListItem, myAction.Archive); break; case "Unarchive": UnziperArchives.UnarchiveElemInThread(selectedListItem); break; case "Rename": // Getting the currently selected ListBoxItem // Note that the ListBox must have // IsSynchronizedWithCurrentItem set to True for this to work ListViewCustom myListBox = menu.Name == "ContextMenu1" ? ListView1 : ListView2; ListViewItem myListBoxItem = (ListViewItem)(myListBox.ItemContainerGenerator.ContainerFromItem(selectedListItem)); // Getting the ContentPresenter of myListBoxItem ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(myListBoxItem); // Finding textBlock from the DataTemplate that is set on that ContentPresenter DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; _myTextBox = (TextBox)myDataTemplate.FindName("ItemNameBox", myContentPresenter); // Do something to the DataTemplate-generated TextBlock _myTextBox.IsReadOnly = false; _myTextBox.SelectionStart = 0; _myTextBox.SelectionLength = _myTextBox.Text.Length; KeyDown += Rename_KeyDown; break; case "Statistic": MessageBox.Show(await LogicForUi.ReadStatisticAsync(selectedListItem)); break; case "Decode": selectedListItem.AcceptDecode(new AesVisitor()); break; case "Encode": selectedListItem.AcceptEncode(new AesVisitor()); break; } }