aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2018-01-31 10:11:27 +0200
committerShlomo Hecht <shlomo@twine-s.com>2018-01-31 10:11:27 +0200
commitb55483f9f095b699728e0b587ceebfdf6409a48a (patch)
tree1d424d3fc9f75154ecae30806b952fdfb029fce9 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs
parente027cb9fdd17fe3be7bb2c385dc37061a7eea8bb (diff)
parent2fa92ca3654ebb274482f9bad86231028d357e5a (diff)
downloadTango-b55483f9f095b699728e0b587ceebfdf6409a48a.tar.gz
Tango-b55483f9f095b699728e0b587ceebfdf6409a48a.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
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.cs30
1 files changed, 15 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 bc8d54ce9..d6de58de4 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
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
-using Tango.DAL.Observables;
+using Tango.Integration.Observables;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.DB.Managers;
using Tango.SharedUI;
@@ -140,7 +140,7 @@ namespace Tango.MachineStudio.DB.ViewModels
base.OnValidating();
ValidationErrors.Clear();
- foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => !x.PropertyType.IsGenericType && x.PropertyType.IsClass && !x.Name.Contains("Guid")))
+ foreach (var prop in typeof(T).GetPropertiesWithAttribute<EntityFieldNameAttribute>(BindingFlags.Public | BindingFlags.Instance).Where(x => !x.PropertyType.IsGenericType && x.PropertyType.IsClass && !x.Name.Contains("Guid")))
{
if (prop.GetValue(EditEntity) == null)
{
@@ -156,21 +156,12 @@ namespace Tango.MachineStudio.DB.ViewModels
{
using (_notification.PushTaskItem("Saving changes to database..."))
{
- 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)));
- return;
- }
-
try
{
- await SelectedEntity.SoftDeleteAsync();
+ await SelectedEntity.DeleteAsync();
}
catch (Exception ex)
{
- SelectedEntity.Deleted = false;
Adapter.Invalidate();
_notification.ShowError("Could not delete entity.");
}
@@ -227,12 +218,21 @@ namespace Tango.MachineStudio.DB.ViewModels
using (_notification.PushTaskItem("Saving changes to database..."))
{
+ if (mode == DialogOpenMode.Adding)
+ {
+ entity.Attach();
+ }
+
try
{
await entity.SaveAsync();
}
catch (DbUpdateException ex)
{
+ if (mode == DialogOpenMode.Adding)
+ {
+ entity.Detach();
+ }
Adapter.Invalidate();
_notification.ShowError("Could not save entity." + Environment.NewLine + ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : ex.InnerException.Message);
}
@@ -299,13 +299,13 @@ namespace Tango.MachineStudio.DB.ViewModels
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))
+ foreach (var prop in entity.GetType().GetPropertiesWithAttribute<EntityFieldNameAttribute>(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))))
+ foreach (var innerProp in obj.GetType().GetPropertiesWithAttribute<EntityFieldNameAttribute>(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);
@@ -323,7 +323,7 @@ namespace Tango.MachineStudio.DB.ViewModels
return
entity.
GetType().
- GetProperties(BindingFlags.Public | BindingFlags.Instance).
+ GetPropertiesWithAttribute<EntityFieldNameAttribute>(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()).