diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-01 10:29:09 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-01 10:29:09 +0300 |
| commit | d5c6067365e12674e95acaef4c4af45eaead8c3e (patch) | |
| tree | 0345d7e407a3e714061dc9bc26152c9efe977bd9 /Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs | |
| parent | 91c672c0b0b01bc68a6adfa2aada337c6488a614 (diff) | |
| download | Tango-d5c6067365e12674e95acaef4c4af45eaead8c3e.tar.gz Tango-d5c6067365e12674e95acaef4c4af45eaead8c3e.zip | |
Implemented notification for observables entities modification..
Diffstat (limited to 'Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index 1473845c5..7c3ade821 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data.Entity; +using System.Data.Entity.Infrastructure; using System.Data.SQLite; using System.IO; using System.Linq; @@ -56,7 +57,8 @@ namespace Tango.BL /// <returns></returns> public static ObservablesContext CreateDefault() { - return CreateDefault(SettingsManager.Default.GetOrCreate<CoreSettings>().DataBaseSource); + var context = CreateDefault(SettingsManager.Default.GetOrCreate<CoreSettings>().DataBaseSource); + return context; } /// <summary> @@ -81,5 +83,39 @@ namespace Tango.BL return new ObservablesContext(source); } } + + /// <summary> + /// Saves all changes made in this context to the underlying database. + /// </summary> + /// <returns> + /// The number of objects written to the underlying database. + /// </returns> + public override int SaveChanges() + { + return base.SaveChanges(); + } + + /// <summary> + /// Extension point allowing the user to override the default behavior of validating only + /// added and modified entities. + /// </summary> + /// <param name="entityEntry">DbEntityEntry instance that is supposed to be validated.</param> + /// <returns> + /// true to proceed with validation; false otherwise. + /// </returns> + protected override bool ShouldValidateEntity(DbEntityEntry entityEntry) + { + if (entityEntry.State == EntityState.Modified && entityEntry.Entity is IObservableEntity) + { + IObservableEntity modified = entityEntry.Entity as IObservableEntity; + + Parallel.ForEach(ObservableEntitiesContainer.RegisteredEntities.Where(x => x.Guid == modified.Guid), (toNotify) => + { + toNotify.RaiseModified(this, modified, toNotify); + }); + } + + return base.ShouldValidateEntity(entityEntry); + } } } |
