Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CategoryCreatePageViewModel"/> class.
        /// </summary>
        /// <param name="navigationService">The navigation service.</param>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">
        /// navigationService
        /// or
        /// context
        /// </exception>
        public CategoryCreatePageViewModel(
            [NotNull] INavigationService navigationService,
            [NotNull] ILocalDbContext context)
        {
            if (navigationService == null)
            {
                throw new ArgumentNullException(nameof(navigationService));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            this.navigationService = navigationService;
            this.context           = context;

            this.AvailableColor = new List <SolidColorBrush>
            {
                new SolidColorBrush(new Color {
                    A = 255, R = 255, G = 255, B = 0
                }),
                new SolidColorBrush(new Color {
                    A = 255, R = 255, G = 0, B = 255
                }),
                new SolidColorBrush(new Color {
                    A = 255, R = 255, G = 0, B = 0
                }),
                new SolidColorBrush(new Color {
                    A = 255, R = 0, G = 255, B = 255
                })
            };
            this.Color = this.AvailableColor.First();

            this.CreateCategoryCommand = new DelegateCommand(this.CreateCategoryCommandExecute, this.CreateCategoryCommandCanExecute);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HomePageViewModel"/> class.
        /// </summary>
        /// <param name="transactionsRepository">The transactions repository.</param>
        /// <param name="context">The context.</param>
        /// <exception cref="ArgumentNullException">
        /// transactionsRepository
        /// or
        /// context
        /// </exception>
        public HomePageViewModel(
            [NotNull] ITransactionsRepository transactionsRepository,
            [NotNull] ILocalDbContext context)
        {
            if (transactionsRepository == null)
            {
                throw new ArgumentNullException(nameof(transactionsRepository));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            this.transactionsRepository = transactionsRepository;
            this.context = context;

            // Populate categories
            this.context.Categories.ForEach(c => this.Categories.Add(new CategoryViewModel(c)));

            // Populate todays transactions collection
            this.context.Transactions
            .Where(t => t.Date.Date == DateTime.Now.Date)
            .ForEach(t => this.TodaysTransactions.Add(new TransactionViewModel(t)));

            // Populate graph collections
            this.PopulateGraphCollections();

            // Handle empty transactions collection property changed notification
            this.TodaysTransactions.CollectionChanged += (sender, args) =>
                                                         this.OnPropertyChanged(() => this.IsTodaysTransactionsEmpty);

            // Initial clear of quick transaction view model
            this.ClearQuickTransaction();
        }
 /// <summary>
 /// Instantiates a new instance of <see cref="TransactionsRepository"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <exception cref="ArgumentNullException">context</exception>
 public TransactionsRepository(ILocalDbContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     this.context = context;
 }
        /// <summary>
        /// Saves the context.
        /// </summary>
        /// <returns>Returns <c>True</c> if context was saved successfully; <c>False</c> otherwise.</returns>
        public static async Task <bool> TrySaveContextAsync(this ILocalDbContext context)
        {
            try
            {
                await context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                var logger = PrismUnityApplication.Current.Container.Resolve <ILogger>();
                logger.Error(ex, "Failed to save context changes.");
                return(false);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CategoriesPageViewModel"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="navigationService">The navigation service.</param>
        /// <exception cref="ArgumentNullException">
        /// context
        /// or
        /// navigationService
        /// </exception>
        public CategoriesPageViewModel(
            [NotNull] ILocalDbContext context,
            [NotNull] INavigationService navigationService)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (navigationService == null)
            {
                throw new ArgumentNullException(nameof(navigationService));
            }
            this.context           = context;
            this.navigationService = navigationService;

            this.CreateCategoryCommand = new DelegateCommand(this.CreateCategoryCommandExecute);
        }
Beispiel #6
0
        /// <summary>
        /// Seeds the context.
        /// </summary>
        /// <param name="context">The context.</param>
        private async Task SeedContextAsync(ILocalDbContext context)
        {
            // Prepare accounts
            if (!context.Accounts.Any())
            {
                var account = new Account
                {
                    Name = "Account"
                };

                context.Accounts.Add(account);
                await context.SaveChangesAsync();
            }

            // Prepare groups
            if (!context.Groups.Any())
            {
                var shoppingCategory = new Group
                {
                    Name      = "Shopping",
                    AccountId = context.Accounts.First().Id
                };

                context.Groups.Add(shoppingCategory);
                await context.SaveChangesAsync();
            }

            // Prepare categories
            if (!context.Categories.Any())
            {
                var foodCategory = new Category
                {
                    Color   = Colors.Purple.ToString(),
                    Name    = "Food",
                    GroupId = context.Groups.First().Id
                };

                context.Categories.Add(foodCategory);
                await context.SaveChangesAsync();
            }
        }
Beispiel #7
0
 public LocalService(ILocalDbContext context)
 {
 }