Exemple #1
0
        /// <summary>
        /// Set the default values for the new transaction
        /// </summary>
        public void InitializeNewTransaction()
        {
            DateTime transactionDate = DateTime.Today;

            if (CurrentTransaction != null)
            {
                transactionDate = CurrentTransaction.TransactionDate;
            }
            CurrentTransaction = new Transactions
            {
                Amount          = 0,
                TransactionDate = transactionDate
            };
            SelectedCategoryDirection = CategoryDirections.First(cd => cd.DirectionID < 1);
        }
        /// <summary>
        /// Initialize properties
        /// </summary>
        /// <param name="transaction">Transaction to modify</param>
        public ModifyTransactionViewModel(Transactions transaction)
        {
            InitializeCategories();

            windowService = new WindowService();

            SelectedTransaction = transaction;

            // Setting the given values to bounded properties
            CurrentTransaction = new Transactions();
            CurrentTransaction.Copy(transaction);

            SelectedCategoryDirection = CategoryDirections.First(cd => cd.DirectionID == SelectedTransaction.Categories.CategoryDirections.DirectionID);
            SelectedCategory          = SelectedCategoryDirection.Categories.First(c => c.CategoryID == SelectedTransaction.CategoryID);

            // Creating Commands
            ModifyCommand = new RelayCommand(
                p => ModifyTransaction(p as IClosable),
                p => CanModify());
            CloseCommand = new RelayCommand(
                p => windowService.CloseWindow(p as IClosable));
        }
Exemple #3
0
        /// <summary>
        /// Initializes the categories
        /// </summary>
        public void InitializeCategories()
        {
            using (var db = new DataModel())
            {
                db.CategoryDirections.Include(c => c.Categories).Load();
                CategoryDirections = new ObservableCollection <CategoryDirections>(db.CategoryDirections.Local.OrderBy(o => o.DirectionName));

                CategoryDirections SelectCD = new CategoryDirections()
                {
                    DirectionID   = 0,
                    DirectionName = "Válassz...",
                    Categories    = new ObservableCollection <Categories>
                    {
                        new Categories
                        {
                            CategoryID   = 0,
                            CategoryName = "Válassz..."
                        }
                    }
                };

                int SelectCategoryID = -1;
                foreach (var dir in CategoryDirections)
                {
                    dir.Categories = new ObservableCollection <Categories>(dir.Categories.OrderBy(o => o.CategoryName));
                    dir.Categories.Add(new Categories
                    {
                        CategoryID   = SelectCategoryID,
                        CategoryName = "Válassz..."
                    });
                    SelectCategoryID--;
                }
                CategoryDirections.Add(SelectCD);

                SelectedCategoryDirection = CategoryDirections.Where(cd => cd.DirectionID == 0).First();
            }
        }
Exemple #4
0
 /// <summary>
 /// Copy only the attributes from an other direction
 /// </summary>
 /// <param name="original">The direction to copy from</param>
 public void Copy(CategoryDirections original)
 {
     DirectionID   = original.DirectionID;
     DirectionName = original.DirectionName;
 }
Exemple #5
0
        /// <summary>
        /// Initialize the viewmodel when it is created.
        /// </summary>
        private void Initialize(InteractionMode interactionMode, UserCategory userCategory)
        {
            switch (interactionMode)
            {
            case InteractionMode.Menu:
                Name = "Kategóriák karbantartása";
                break;

            case InteractionMode.Modify:
                Name             = "Kategória módosítása";
                SelectedCategory = new UserCategory();
                SelectedCategory.Copy(userCategory);
                OKCommand = new RelayCommand(
                    p => Modify(p as IClosable),
                    p => IsAttributesFilled());
                break;

            case InteractionMode.Create:
                Name             = "Kategória létrehozása";
                SelectedCategory = new UserCategory()
                {
                    Category = new Categories()
                    {
                        CategoryDirections = new CategoryDirections()
                    },
                    Priority = 1
                };
                OKCommand = new RelayCommand(
                    p => Create(p as IClosable),
                    p => IsAttributesFilled());
                break;

            default:
                break;
            }

            IsModified = false;

            windowService = new WindowService();

            AddCategoryCommand = new RelayCommand(
                p => CreateInteractive());

            CloseCommand = new RelayCommand(
                p => windowService.CloseWindow(p as IClosable));

            ModifyCategoryCommand = new RelayCommand(
                p => ModifyInteractive(),
                p => IsSelected(true));

            DeleteCategoryCommand = new RelayCommand(
                p => Delete(),
                p => IsSelected(false));

            // load the categories for the logged in user
            using (var db = new DataModel())
            {
                UserCategories = new ObservableCollection <UserCategory>(db
                                                                         .UserCategory
                                                                         .Include(c => c.Category)
                                                                         .Include(c => c.Category.CategoryDirections)
                                                                         .Include(c => c.User)
                                                                         .Where(uc => uc.UserID == MainViewModel.CurrentUser.UserID)
                                                                         .ToList());

                CategoryDirections = new ObservableCollection <CategoryDirections>(db
                                                                                   .CategoryDirections
                                                                                   .OrderBy(cd => cd.DirectionName)
                                                                                   .ToList());
                if (interactionMode == InteractionMode.Create)
                {
                    var SelectCD = new CategoryDirections()
                    {
                        DirectionID   = 0,
                        DirectionName = "Válassz..."
                    };
                    CategoryDirections.Add(SelectCD);
                    SelectedCategory.Category.CategoryDirections = CategoryDirections.First(cd => cd.DirectionID == 0);
                }

                if (interactionMode == InteractionMode.Modify)
                {
                    // select the categorydirection from the collection
                    SelectedCategory.Category.CategoryDirections = CategoryDirections
                                                                   .First(cd => cd.DirectionID == SelectedCategory.Category.CategoryDirectionID);
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// Reset the search filter to the default values
 /// </summary>
 private void ResetSearchFilter()
 {
     StartDate = new DateTime(DateTime.Today.Year, DateTime.Today.AddMonths(-1).Month, 1);
     EndDate   = DateTime.Today;
     SearchCategoryDirection = CategoryDirections.First(cd => cd.DirectionID == 0);
 }