aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/IObservableEntity.cs
blob: 6844108d6faf553ba934c15fcc571cb4a638d322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using LiteDB;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Serialization;
using Tango.Core;
using Tango.Core.Json;

namespace Tango.BL
{
    /// <summary>
    /// Represents an observable database entity.
    /// </summary>
    public interface IObservableEntity : INotifyDataErrorInfo, IParameterized , ISerializableEntity
    {
        /// <summary>
        /// Occurs after this observable has been modified and saved by this entity context or another.
        /// </summary>
        event EventHandler<ObservableModifiedEventArgs> Modified;

        /// <summary>
        /// Gets or sets the entity identifier.
        /// </summary>
        [Column("ID")]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        [ParameterIgnore]
        Int32 ID { get; set; }

        /// <summary>
        /// Gets or sets the entity unique identifier.
        /// </summary>
        [Key]
        [Column("GUID")]
        [ParameterIgnore]
        [BsonId]
        String Guid { get; set; }

        /// <summary>
        /// Gets or sets the entity last updated data and time.
        /// </summary>
        [Column("LAST_UPDATED")]
        [ParameterIgnore]
        DateTime LastUpdated { get; set; }

        /// <summary>
        /// Saves the changes on this entity to database.
        /// </summary>
        void Save(ObservablesContext context);

        /// <summary>
        /// Attaches this observable to the proper DbSet.
        /// </summary>
        void Attach(ObservablesContext context);

        /// <summary>
        /// Detaches this observable from the proper DbSet.
        /// </summary>
        void Detach(ObservablesContext context);

        /// <summary>
        /// Saves the changes on this entity to database asynchronously.
        /// </summary>
        /// <returns></returns>
        Task SaveAsync(ObservablesContext context);

        /// <summary>
        /// Deletes this entity using an SQL statement which will cause the database delete  cascade effect.
        /// </summary>
        Task DeleteCascadeAsync(ObservablesContext context);

        /// <summary>
        /// Gets the database set containing this entity.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        DbSet<T> GetDbSet<T>(ObservablesContext context) where T : class, IObservableEntity;

        /// <summary>
        /// Raises the <see cref="Modified"/> event.
        /// </summary>
        void RaiseModified(ObservablesContext context, IObservableEntity source, IObservableEntity target);

        /// <summary>
        /// Removes this entity and all dependent entities from the specified db context.
        /// </summary>
        /// <param name="context">The context.</param>
        void Delete(ObservablesContext context);

        /// <summary>
        /// Called when before entity is saved by the context.
        /// </summary>
        void OnBeforeSave();
    }
}