Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Ink;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using Microsoft.Practices.Prism.ViewModel;
- using System.Data.Linq.Mapping;
- using System.Data.Linq;
- using System.Collections;
- namespace Bick.Budget.Entities.Categories
- {
- [Table(Name = "Categories")]
- public class Category : NotificationObject
- {
- #region Fields
- /// <summary>
- /// Stores category ID
- /// </summary>
- private Guid id;
- /// <summary>
- /// Stores category name
- /// </summary>
- private string name;
- /// <summary>
- /// Stores category type
- /// </summary>
- private ECategoryType type;
- /// <summary>
- /// Stores all transactions in category
- /// </summary>
- private EntitySet<Transactions.Transaction> transactions;
- #endregion
- #region Constructors
- /// <summary>
- /// Default constructor for Category class
- /// </summary>
- public Category()
- {
- this.ID = Guid.NewGuid();
- this.transactions = new EntitySet<Transactions.Transaction>();
- }
- #endregion
- #region Properties
- /// <summary>
- /// Gets category ID
- /// </summary>
- [Column(IsPrimaryKey = true)]
- public Guid ID
- {
- get
- {
- return this.id;
- }
- private set
- {
- if (this.id != value)
- {
- this.id = value;
- this.RaisePropertyChanged(() => this.ID);
- }
- }
- }
- /// <summary>
- /// Gets or sets category name
- /// </summary>
- [Column]
- public string Name
- {
- get
- {
- return this.name;
- }
- set
- {
- if (this.name != value)
- {
- this.name = value;
- this.RaisePropertyChanged(() => this.Name);
- }
- }
- }
- /// <summary>
- /// Gets or sets category type
- /// </summary>
- [Column(CanBeNull = true, DbType = "NVarChar(15)")]
- public ECategoryType Type
- {
- get
- {
- return this.type;
- }
- set
- {
- if (this.type != value)
- {
- this.type = value;
- this.RaisePropertyChanged(() => this.Type);
- }
- }
- }
- /// <summary>
- /// Gets all transactions in current category
- /// </summary>
- public EntitySet<Transactions.Transaction> Transactions
- {
- get
- {
- if (this.transactions == null)
- {
- this.transactions = new EntitySet<Transactions.Transaction>();
- this.transactions.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(this.OnTransactionsChanged);
- }
- return this.transactions;
- }
- private set
- {
- if (this.transactions != value)
- {
- this.transactions = value;
- this.RaisePropertyChanged(() => this.Transactions);
- }
- }
- }
- /// <summary>
- /// Gets list of transactions that was added to current category in one pack
- /// </summary>
- public IList AddedTransactions
- {
- get;
- private set;
- }
- #endregion
- /// <summary>
- /// Handles changes in category's transactions
- /// </summary>
- /// <param name="sender">Sender</param>
- /// <param name="e">Event arguments</param>
- private void OnTransactionsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
- {
- this.AddedTransactions = e.NewItems;
- foreach (Transactions.Transaction t in e.NewItems)
- {
- t.Category = this;
- }
- this.AddedTransactions = null;
- this.RaisePropertyChanged(() => this.Transactions);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement