aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Observables/IObservableEntity.cs
blob: eb16d150d6216d410206261bff33cfe8efa8fd30 (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
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.Integration.Observables
{
    /// <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)]
        Int32 ID { get; set; }

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

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

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

        /// <summary>
        /// Saves the changes on this entity to database using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        void Save(DbContext context);

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

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

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

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

        /// <summary>
        /// Deletes this entity from the database.
        /// </summary>
        void Delete();

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

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