public void ScanRootFolder() { var directories1 = Directory.GetDirectories(ConfigurationManager.AppSettings["RootFolder"]); var directories = directories1.Where(d => { var dateTime = new DateTime(); var directory = Path.GetFileName(d); if (directory.Length > 10) { return(DateTime.TryParse(directory.Substring(0, 10), out dateTime)); } else { return(false); } }).ToList(); var folders = _photoEntities.Folder.Include("Attribute").ToList(); foreach (var folder in folders) { var folderModel = new FolderModel(); folderModel.Folder = folder; folderModel.Folders = ItemsSourceAttribute; folderModel.Images = new ObservableCollection <ImageModel>(); folderModel.Status = FolderStatus.Deleted; ItemsSource.Insert(0, folderModel); } var newFolder = false; foreach (var directory in directories) { var folderModel = ItemsSource.FirstOrDefault(f => f.Folder.Name == Path.GetFileName(directory)); if (folderModel == null) { newFolder = true; var folder = new Folder(); folder.Name = directory.Replace(ConfigurationManager.AppSettings["RootFolder"] + "\\", ""); _photoEntities.Folder.AddObject(folder); folderModel = new FolderModel(); folderModel.Folder = folder; folderModel.Folders = ItemsSourceAttribute; folderModel.Images = new ObservableCollection <ImageModel>(); folderModel.Status = FolderStatus.Created; ItemsSource.Insert(0, folderModel); } else { folderModel.Status = FolderStatus.Normal; } } if (newFolder) { _photoEntities.SaveChanges(); } OnPropertyChanged("ItemsSourceView"); }
public void Deleted(FolderModel folderModel) { _photoEntities.Folder.DeleteObject(folderModel.Folder); _photoEntities.SaveChanges(); }