Advertisement
Bick

Category.cs

Feb 13th, 2012
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.59 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.             this.transactions = new EntitySet<Transactions.Transaction>();
  51.         }
  52.         #endregion
  53.  
  54.         #region Properties
  55.         /// <summary>
  56.         /// Gets category ID
  57.         /// </summary>
  58.         [Column(IsPrimaryKey = true)]
  59.         public Guid ID
  60.         {
  61.             get
  62.             {
  63.                 return this.id;
  64.             }
  65.  
  66.             private set
  67.             {
  68.                 if (this.id != value)
  69.                 {
  70.                     this.id = value;
  71.                     this.RaisePropertyChanged(() => this.ID);
  72.                 }
  73.             }
  74.         }
  75.  
  76.         /// <summary>
  77.         /// Gets or sets category name
  78.         /// </summary>
  79.         [Column]
  80.         public string Name
  81.         {
  82.             get
  83.             {
  84.                 return this.name;
  85.             }
  86.  
  87.             set
  88.             {
  89.                 if (this.name != value)
  90.                 {
  91.                     this.name = value;
  92.                     this.RaisePropertyChanged(() => this.Name);
  93.                 }
  94.             }
  95.         }
  96.  
  97.         /// <summary>
  98.         /// Gets or sets category type
  99.         /// </summary>
  100.         [Column(CanBeNull = true, DbType = "NVarChar(15)")]
  101.         public ECategoryType Type
  102.         {
  103.             get
  104.             {
  105.                 return this.type;
  106.             }
  107.  
  108.             set
  109.             {
  110.                 if (this.type != value)
  111.                 {
  112.                     this.type = value;
  113.                     this.RaisePropertyChanged(() => this.Type);
  114.                 }
  115.             }
  116.         }
  117.  
  118.         /// <summary>
  119.         /// Gets all transactions in current category
  120.         /// </summary>
  121.         public EntitySet<Transactions.Transaction> Transactions
  122.         {
  123.             get
  124.             {
  125.                 if (this.transactions == null)
  126.                 {
  127.                     this.transactions = new EntitySet<Transactions.Transaction>();
  128.                     this.transactions.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(this.OnTransactionsChanged);
  129.                 }
  130.  
  131.                 return this.transactions;
  132.             }
  133.  
  134.             private set
  135.             {
  136.                 if (this.transactions != value)
  137.                 {
  138.                     this.transactions = value;
  139.                     this.RaisePropertyChanged(() => this.Transactions);
  140.                 }
  141.             }
  142.         }
  143.  
  144.         /// <summary>
  145.         /// Gets list of transactions that was added to current category in one pack
  146.         /// </summary>
  147.         public IList AddedTransactions
  148.         {
  149.             get;
  150.             private set;
  151.         }
  152.         #endregion
  153.  
  154.         /// <summary>
  155.         /// Handles changes in category's transactions
  156.         /// </summary>
  157.         /// <param name="sender">Sender</param>
  158.         /// <param name="e">Event arguments</param>
  159.         private void OnTransactionsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  160.         {
  161.             this.AddedTransactions = e.NewItems;
  162.             foreach (Transactions.Transaction t in e.NewItems)
  163.             {
  164.                 t.Category = this;
  165.             }
  166.  
  167.             this.AddedTransactions = null;
  168.             this.RaisePropertyChanged(() => this.Transactions);
  169.         }
  170.     }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement