diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs index b6d77748e..bc8d54ce9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs @@ -8,7 +8,6 @@ using Tango.DAL.Observables; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.DB.Managers; using Tango.SharedUI; -using Tango.MachineStudio.DB.ExtensionMethods; using System.Data.Entity.Infrastructure; using GalaSoft.MvvmLight.Messaging; using Tango.MachineStudio.DB.Messages; @@ -21,7 +20,7 @@ namespace Tango.MachineStudio.DB.ViewModels { public abstract class DbTableViewModel<T> : ViewModel, IShutdownRequestBlocker where T : class, IObservableEntity { - private INotificationProvider _notification; + protected INotificationProvider _notification; /// <summary> /// Initializes a new instance of the <see cref="DbTableViewModel"/> class. @@ -157,18 +156,17 @@ namespace Tango.MachineStudio.DB.ViewModels { using (_notification.PushTaskItem("Saving changes to database...")) { - var dependenctEntities = SelectedEntity.GetDependentEntitiesNameAndGuid(); + var dependenctEntities = SelectedEntity.GetDependentEntitiesNameAndGuid(); if (dependenctEntities.Count > 0) { - _notification.ShowError("The selected entity is being used by " + dependenctEntities.Count + " other entities." + Environment.NewLine + "Please delete any dependencies and try again." + Environment.NewLine + Environment.NewLine + String.Join(Environment.NewLine,dependenctEntities.Select(x => x.Key + ", ID: " + x.Value))); + _notification.ShowError("The selected entity is being used by " + dependenctEntities.Count + " other entities." + Environment.NewLine + "Please delete any dependencies and try again." + Environment.NewLine + Environment.NewLine + String.Join(Environment.NewLine, dependenctEntities.Select(x => x.Key + ", ID: " + x.Value))); return; } try { - SelectedEntity.Deleted = true; - await SelectedEntity.SaveAsync(); + await SelectedEntity.SoftDeleteAsync(); } catch (Exception ex) { @@ -295,18 +293,44 @@ namespace Tango.MachineStudio.DB.ViewModels collectionView.Filter = (entity) => { - return - entity. - GetType(). - GetProperties(BindingFlags.Public | BindingFlags.Instance). - Where(x => x.Name != "Deleted" && x.Name != "ID" && x.Name != "LastUpdated"). - Where(x => !x.PropertyType.IsGenericType && (x.PropertyType.IsClass || x.PropertyType == typeof(String))). - Select(prop => prop.GetValue(entity).ToString()). - ToList(). - Any(x => x.ToLower().Contains(filter.ToLower())); + return FilterEntity((T)entity, filter); }; } + private bool FilterEntity(T entity, String filter) + { + foreach (var prop in entity.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsClass && x.PropertyType != typeof(String) && x.PropertyType != typeof(byte[]) && !x.PropertyType.IsGenericType)) + { + object obj = prop.GetValue(entity); + + if (obj != null) + { + foreach (var innerProp in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.Name != "Deleted" && x.Name != "ID" && x.Name != "LastUpdated").Where(x => !x.PropertyType.IsGenericType && (x.PropertyType.IsClass || x.PropertyType == typeof(String)))) + { + object value = innerProp.GetValue(obj); + + if (value != null) + { + if (value.ToString().ToLower().Contains(filter.ToLower())) + { + return true; + } + } + } + } + } + + return + entity. + GetType(). + GetProperties(BindingFlags.Public | BindingFlags.Instance). + Where(x => x.Name != "Deleted" && x.Name != "ID" && x.Name != "LastUpdated"). + Where(x => !x.PropertyType.IsGenericType && (x.PropertyType.IsClass || x.PropertyType == typeof(String))). + Select(prop => prop.GetValue(entity).ToString()). + ToList(). + Any(x => x.ToLower().Contains(filter.ToLower())); + } + protected virtual void InitializeEntity(T entity) { |
