diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-18 18:48:16 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-18 18:48:16 +0200 |
| commit | 95b4e14bc4e06ffb94199f5ec4e0d2d9bebceeff (patch) | |
| tree | de29ed87bd7c7b966d35b6f6bc8b13d65313c88c /Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs | |
| parent | 99136fc92c8b75c3783f543051c065c28961d393 (diff) | |
| download | Tango-95b4e14bc4e06ffb94199f5ec4e0d2d9bebceeff.tar.gz Tango-95b4e14bc4e06ffb94199f5ec4e0d2d9bebceeff.zip | |
Working on new developer module.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs index 92dd88f34..d5b218453 100644 --- a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs @@ -18,6 +18,9 @@ using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using System.Runtime.CompilerServices; using System.Data.Entity.Core.Objects; +using Tango.Serialization; +using System.Xml.Serialization; +using Newtonsoft.Json; namespace Tango.Integration.Observables { @@ -65,6 +68,7 @@ namespace Tango.Integration.Observables /// Gets or sets the entity last updated data and time. /// </summary> [Column("LAST_UPDATED")] + [JsonIgnore] public DateTime LastUpdated { get { return _lastUpdated; } @@ -76,6 +80,8 @@ namespace Tango.Integration.Observables /// Gets a bind-able observable collection of the component properties. /// </summary> [NotMapped] + [XmlIgnore] + [JsonIgnore] public ReadOnlyObservableCollection<ParameterItem> Parameters { get { return _parameters; } @@ -108,7 +114,7 @@ namespace Tango.Integration.Observables /// </summary> public virtual void Save() { - GetDbContextFromEntity(this).SaveChanges(); + ObservablesEntitiesAdapter.Instance.SaveChanges(); OnSaved(); } @@ -213,7 +219,7 @@ namespace Tango.Integration.Observables return null; } - + protected virtual void OnSaved() { Saved?.Invoke(this, new EventArgs()); @@ -243,6 +249,29 @@ namespace Tango.Integration.Observables return context; } + public virtual T Clone() + { + return (this as T).CloneEntity() as T; + } + + public void Save(DbContext context) + { + context.SaveChanges(); + OnSaved(); + } + + public Task SaveAsync(DbContext context) + { + return Task.Factory.StartNew(() => Save(context)); + } + + public bool CompareUsingJson(T entity) + { + String me = JsonConvert.SerializeObject(this); + String other = JsonConvert.SerializeObject(entity); + return me == other; + } + #region Operator Overloading //public static bool operator ==(ObservableEntity<T> observable1, ObservableEntity<T> observable2) |
