Bick

Category.cs

Feb 10th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.46 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 Microsoft.Practices.Prism.ViewModel;
  12. using System.Data.Linq.Mapping;
  13. using System.Data.Linq;
  14. using System.Collections;
  15.  
  16. namespace Bick.Budget.Entities.Categories
  17. {
  18.     [Table(Name = "Categories")]
  19.     public class Category : NotificationObject
  20.     {
  21.         #region Fields
  22.         /// <summary>
  23.         /// Stores category ID
  24.         /// </summary>
  25.         private Guid id;
  26.  
  27.         /// <summary>
  28.         /// Stores category name
  29.         /// </summary>
  30.         private string name;
  31.  
  32.         /// <summary>
  33.         /// Stores category type
  34.         /// </summary>
  35.         private ECategoryType type;
  36.  
  37.         /// <summary>
  38.         /// Stores all transactions in category
  39.         /// </summary>
  40.         private EntitySet<Transactions.Transaction> transactions;
  41.         #endregion
  42.  
  43.         #region Constructors
  44.         /// <summary>
  45.         /// Default constructor for Category class
  46.         /// </summary>
  47.         public Category()
  48.         {
  49.             this.ID = Guid.NewGuid();
  50.         }
  51.         #endregion
  52.  
  53.         #region Properties
  54.         /// <summary>
  55.         /// Gets category ID
  56.         /// </summary>
  57.         [Column(IsPrimaryKey = true)]
  58.         public Guid ID
  59.         {
  60.             get
  61.             {
  62.                 return this.id;
  63.             }
  64.  
  65.             private set
  66.             {
  67.                 if (this.id != value)
  68.                 {
  69.                     this.id = value;
  70.                     this.RaisePropertyChanged(() => this.ID);
  71.                 }
  72.             }
  73.         }
  74.  
  75.         /// <summary>
  76.         /// Gets or sets category name
  77.         /// </summary>
  78.         [Column]
  79.         public string Name
  80.         {
  81.             get
  82.             {
  83.                 return this.name;
  84.             }
  85.  
  86.             set
  87.             {
  88.                 if (this.name != value)
  89.                 {
  90.                     this.name = value;
  91.                     this.RaisePropertyChanged(() => this.Name);
  92.                 }
  93.             }
  94.         }
  95.  
  96.         /// <summary>
  97.         /// Gets or sets category type
  98.         /// </summary>
  99.         [Column(DbType = "NVarChar(15)")]
  100.         public ECategoryType Type
  101.         {
  102.             get
  103.             {
  104.                 return this.type;
  105.             }
  106.  
  107.             set
  108.             {
  109.                 if (this.type != value)
  110.                 {
  111.                     this.RaisePropertyChanged(() => this.Type);
  112.                 }
  113.             }
  114.         }
  115.  
  116.         /// <summary>
  117.         /// Gets all transactions in current category
  118.         /// </summary>
  119.         public EntitySet<Transactions.Transaction> Transactions
  120.         {
  121.             get
  122.             {
  123.                 if (this.transactions == null)
  124.                 {
  125.                     this.transactions = new EntitySet<Transactions.Transaction>();
  126.                     this.transactions.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(this.OnTransactionsChanged);
  127.                 }
  128.  
  129.                 return this.transactions;
  130.             }
  131.  
  132.             private set
  133.             {
  134.                 if (this.transactions != value)
  135.                 {
  136.                     this.transactions = value;
  137.                     this.RaisePropertyChanged(() => this.Transactions);
  138.                 }
  139.             }
  140.         }
  141.  
  142.         /// <summary>
  143.         /// Gets list of transactions that was added to current category in one pack
  144.         /// </summary>
  145.         public IList AddedTransactions
  146.         {
  147.             get;
  148.             private set;
  149.         }
  150.         #endregion
  151.  
  152.         /// <summary>
  153.         /// Handles changes in category's transactions
  154.         /// </summary>
  155.         /// <param name="sender">Sender</param>
  156.         /// <param name="e">Event arguments</param>
  157.         private void OnTransactionsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  158.         {
  159.             this.AddedTransactions = e.NewItems;
  160.             foreach (Transactions.Transaction t in e.NewItems)
  161.             {
  162.                 t.Category = this;
  163.             }
  164.  
  165.             this.AddedTransactions = null;
  166.             this.RaisePropertyChanged(() => this.Transactions);
  167.         }
  168.     }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment