Bick

Transaction.cs

Feb 10th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.90 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Documents;
  6. using System.Windows.Ink;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Animation;
  10. using System.Windows.Shapes;
  11. using System.Data.Linq.Mapping;
  12. using System.ComponentModel;
  13. using Microsoft.Practices.Prism.ViewModel;
  14. using System.Xml.Serialization;
  15. using System.IO;
  16. using Bick.Budget.Data.ValueTypes;
  17. using System.Data.Linq;
  18. using System.Collections;
  19.  
  20. namespace Bick.Budget.Data.Transactions
  21. {
  22.     /// <summary>
  23.     /// Describes financial transaction
  24.     /// </summary>
  25.     [Table(Name = "Transactions")]
  26.     public class Transaction : NotificationObject
  27.     {
  28.         #region Fields
  29.         /// <summary>
  30.         /// Unique ID for transaction
  31.         /// </summary>
  32.         private Guid id;
  33.  
  34.         /// <summary>
  35.         /// Unique ID for category
  36.         /// </summary>
  37.         private Guid? categoryID;
  38.  
  39.         /// <summary>
  40.         /// Transaction's name
  41.         /// </summary>
  42.         private string name;
  43.  
  44.         /// <summary>
  45.         /// Transaction's description
  46.         /// </summary>
  47.         private string description;
  48.  
  49.         /// <summary>
  50.         /// Amount of transaction
  51.         /// </summary>
  52.         private double amount;
  53.  
  54.         /// <summary>
  55.         /// Transaction added date
  56.         /// </summary>
  57.         private DateTime dateAdded;
  58.  
  59.         /// <summary>
  60.         /// Parent category object
  61.         /// </summary>
  62.         private EntityRef<Categories.Category> category;
  63.         #endregion
  64.  
  65.         #region Constructors
  66.         /// <summary>
  67.         /// Constructor for Transaction object
  68.         /// </summary>
  69.         public Transaction()
  70.         {
  71.             this.ID = Guid.NewGuid();
  72.             this.DateAdded = DateTime.Now;
  73.         }
  74.         #endregion
  75.  
  76.         #region Properties
  77.         #region Columns
  78.         /// <summary>
  79.         /// Gets transaction unique ID
  80.         /// </summary>
  81.         [Column(IsPrimaryKey = true)]
  82.         public Guid ID
  83.         {
  84.             get
  85.             {
  86.                 return this.id;
  87.             }
  88.  
  89.             private set
  90.             {
  91.                 if (this.id != value)
  92.                 {
  93.                     this.id = value;
  94.                     this.RaisePropertyChanged(() => this.ID);
  95.                 }
  96.             }
  97.         }
  98.  
  99.         /// <summary>
  100.         /// Gets transaction parent category ID
  101.         /// </summary>
  102.         [Column(CanBeNull = true)]
  103.         public Guid? CategoryID
  104.         {
  105.             get
  106.             {
  107.                 return this.categoryID;
  108.             }
  109.  
  110.             private set
  111.             {
  112.                 if (this.categoryID != value)
  113.                 {
  114.                     this.categoryID = value;
  115.                     this.RaisePropertyChanged(() => this.CategoryID);
  116.                 }
  117.             }
  118.  
  119.         }
  120.  
  121.         /// <summary>
  122.         /// Gets or sets transaction name
  123.         /// </summary>
  124.         [Column]
  125.         public string Name
  126.         {
  127.             get
  128.             {
  129.                 return this.name;
  130.             }
  131.  
  132.             set
  133.             {
  134.                 if (this.name != value)
  135.                 {
  136.                     this.name = value;
  137.                     this.RaisePropertyChanged(() => this.Name);
  138.                 }
  139.             }
  140.         }
  141.  
  142.         /// <summary>
  143.         /// Gets or sets amount of transaction
  144.         /// </summary>
  145.         [Column]
  146.         [DefaultValue(0)]
  147.         public double Amount
  148.         {
  149.             get
  150.             {
  151.                 return this.amount;
  152.             }
  153.  
  154.             set
  155.             {
  156.                 if (this.amount != value)
  157.                 {
  158.                     this.amount = value;
  159.                     this.RaisePropertyChanged(() => this.Amount);
  160.                 }
  161.             }
  162.         }
  163.  
  164.         /// <summary>
  165.         /// Gets transaction added date
  166.         /// </summary>
  167.         [Column]
  168.         public DateTime DateAdded
  169.         {
  170.             get
  171.             {
  172.                 return this.dateAdded;
  173.             }
  174.  
  175.             private set
  176.             {
  177.                 if (this.dateAdded != value)
  178.                 {
  179.                     this.dateAdded = value;
  180.                     this.RaisePropertyChanged(() => this.DateAdded);
  181.                 }
  182.             }
  183.         }
  184.         #endregion
  185.  
  186.         #region Objects
  187.         /// <summary>
  188.         /// Gets or sets parent <see cref="Category"/> object
  189.         /// </summary>
  190.         [Association(Name = "FK_Transactions_Category", Storage = "category", ThisKey = "CategoryID", IsForeignKey = true)]
  191.         public Categories.Category Category
  192.         {
  193.             get
  194.             {
  195.                 return this.category.Entity;
  196.             }
  197.  
  198.             set
  199.             {
  200.                 Categories.Category previousValue = this.category.Entity;
  201.                 if (((previousValue != value) || (this.category.HasLoadedOrAssignedValue == false)))
  202.                 {
  203.                     if ((previousValue != null))
  204.                     {
  205.                         this.category.Entity = null;
  206.                         previousValue.Transactions.Remove(this);
  207.                     }
  208.  
  209.                     this.category.Entity = value;
  210.                     if ((value != null))
  211.                     {
  212.                         if ((value.AddedTransactions == null) || (!value.AddedTransactions.Contains(this)))
  213.                         {
  214.                             value.Transactions.Add(this);
  215.                         }
  216.  
  217.                         this.CategoryID = value.ID;
  218.                     }
  219.                     else
  220.                     {
  221.                         this.category = new EntityRef<Categories.Category>();
  222.                     }
  223.                 }
  224.             }
  225.         }
  226.         #endregion
  227.         #endregion
  228.     }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment