aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-03-11 14:03:02 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-03-11 14:03:02 +0200
commitc923d6611ffa64605879779c490a979e03daa189 (patch)
tree8fedfe9963847146018c18ceee9cce7e0d0d579e /Software/Visual_Studio/Tango.BL/ObservableEntity.cs
parent4188ea39897f5aa3bc4be5a44358b79436baf0b4 (diff)
downloadTango-c923d6611ffa64605879779c490a979e03daa189.tar.gz
Tango-c923d6611ffa64605879779c490a979e03daa189.zip
Working on Users & Roles module !
Diffstat (limited to 'Software/Visual_Studio/Tango.BL/ObservableEntity.cs')
-rw-r--r--Software/Visual_Studio/Tango.BL/ObservableEntity.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
index add6877cb..43d5c06de 100644
--- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
+++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
@@ -123,6 +123,18 @@ namespace Tango.BL
{
if (context == ObservablesEntitiesAdapter.Instance.Context)
{
+ var tableName = this.GetType().GetCustomAttribute<TableAttribute>().Name;
+
+ String propName = tableName.FromDalNameToTitleCase();
+
+ DbSet<T> set = ObservablesEntitiesAdapter.Instance.Context.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.Public).GetValue(context) as DbSet<T>;
+ ObservableCollection<T> obs = ObservablesEntitiesAdapter.Instance.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.Public).GetValue(ObservablesEntitiesAdapter.Instance) as ObservableCollection<T>;
+
+ if (!obs.Contains(this as T))
+ {
+ set.Add(this as T);
+ }
+
ObservablesEntitiesAdapter.Instance.SaveChanges();
}
else
@@ -284,6 +296,11 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa
return me == other;
}
+ public Task DeleteCascadeAsync(ObservablesContext context)
+ {
+ return context.Database.ExecuteSqlCommandAsync(String.Format("DELETE FROM {0} WHERE GUID='{1}'", this.GetType().GetCustomAttribute<TableAttribute>().Name, Guid));
+ }
+
#region Operator Overloading
//public static bool operator ==(ObservableEntity<T> observable1, ObservableEntity<T> observable2)