aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/IObservableEntity.cs
blob: dcb7ad5dad7286816bfb8ef1572ae2ef45872044 (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
102
using System;
using System.Collections.Generic;
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.Core;

namespace Tango.BL
{
    /// <summary>
    /// Represents an observable database entity.
    /// </summary>
    public interface IObservableEntity : IParameterized
    {
        /// <summary>
        /// Occurs after this observable has been saved.
        /// </summary>
        event EventHandler Saved;

        /// <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]
        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 from the database.
        /// </summary>
        void Delete(ObservablesContext context);

        /// <summary>
        /// Deletes this entity without saving changes to data base.
        /// </summary>
        void DefferedDelete(ObservablesContext context);

        /// <summary>
        /// Deletes this entity from the database.
        /// </summary>
        Task DeleteAsync(ObservablesContext context);

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

        /// <summary>
        /// Performs entity field validation.
        /// Will throw an exception with the proper message if one of the fields is invalid.
        /// </summary>
        /// <param name="context">The context.</param>
        void Validate(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;
    }
}