コード例 #1
0
 public Family(FamilyOrganizerContext familyOrganizerContext, AppUser currentUser)
 {
     InitializeComponent();
     _context              = familyOrganizerContext;
     _currentUser          = currentUser;
     usersList.ItemsSource = _context.AppUsers.Local.ToBindingList().Where(u => u.Id != _currentUser.Id);
 }
コード例 #2
0
        public Diary(FamilyOrganizerContext familyOrganizerContext, AppUser currentUser)
        {
            InitializeComponent();
            _context     = familyOrganizerContext;
            _currentUser = currentUser;

            TaskListRoutine.ItemsSource = _context.TodayPlans.Local.ToBindingList().Where(p => p.IsRoutine == true && _currentUser.Id == p.UserId);
            TasksList.ItemsSource       = _context.TodayPlans.Local.ToBindingList().Where(p => p.IsAdded == true && _currentUser.Id == p.UserId);
        }
コード例 #3
0
 public Register(FamilyOrganizerContext context, bool ToMainWindow = false)
 {
     InitializeComponent();
     _context      = context;
     _toMainWindow = ToMainWindow;
     if (_context.AppUsers.Count() == 0)
     {
         ParentWithCheckBox.Visibility = Visibility.Hidden;
     }
 }
コード例 #4
0
        public ShoppingList(FamilyOrganizerContext context, AppUser currentUser)
        {
            InitializeComponent();

            _context     = context;
            _currentUser = currentUser;

            ShoppingListUnapproved.ItemsSource = _context.ShoppingPlans.Local.ToBindingList().Where(p => !p.Accepted);
            ShoppingListApproved.ItemsSource   = _context.ShoppingPlans.Local.ToBindingList().Where(p => p.Accepted);
        }
コード例 #5
0
        public static void SeedBalances(FamilyOrganizerContext context)
        {
            if (context.Balances.Any())
            {
                return;
            }

            var balancesJson = (File.ReadAllText(@".\DB\Seed\BalancesSeed.json"));
            var balances     = JsonSerializer.Deserialize <IEnumerable <Balance> >(balancesJson);

            context.Balances.AddRange(balances);
            context.SaveChanges();
        }
コード例 #6
0
        public static void SeedTransactions(FamilyOrganizerContext context)
        {
            if (context.Transactions.Any())
            {
                return;
            }

            var transactionsJson = (File.ReadAllText(@".\DB\Seed\TransactionsSeed.json"));
            var transactions     = JsonSerializer.Deserialize <IEnumerable <Transaction> >(transactionsJson);

            context.Transactions.AddRange(transactions);
            context.SaveChanges();
        }
コード例 #7
0
        private async void DeleteUser_Click(object sender, RoutedEventArgs e)
        {
            var currentUser = DataContext as AppUser;

            if (_context == null)
            {
                var a = VisualTreeHelper.GetParent(this);
                while (!(a is Family))
                {
                    a = VisualTreeHelper.GetParent(a);
                }

                _context = (a as Family)._context;
            }

            if (!await _context.AppUsers.AnyAsync(u => u.Id == currentUser.Id))
            {
                return;
            }

            _context.AppUsers.Remove(currentUser);
            var currentBalance = await _context.AppUsers.Where(u => u.UserName != currentUser.UserName).SumAsync(u => u.Balance);

            var currentBalanceEntry = await _context.Balances.OrderByDescending(b => b.Date).FirstOrDefaultAsync();

            if (currentBalanceEntry == null)
            {
                currentBalanceEntry = new Balance {
                    CurrentBalance = 0, Date = DateTime.Now
                }
            }
            ;

            if (currentBalanceEntry.Date.Day == DateTime.Now.Day && _context.Balances.Count() > 0)
            {
                _context.Balances.Remove(currentBalanceEntry);
            }

            _context.Balances.Add(new Balance
            {
                Date           = DateTime.Now,
                CurrentBalance = currentBalance
            });

            await _context.SaveChangesAsync();

            var mb = new FamilyOrganizerMessageBox("Refresh the page to see the changes");

            mb.Show();
        }
コード例 #8
0
        public General(FamilyOrganizerContext familyOrganizerContext, AppUser currentUser)
        {
            InitializeComponent();

            _context                 = familyOrganizerContext;
            _currentUser             = currentUser;
            commentsList.ItemsSource = _context.Comments.Local.ToBindingList();

            WelcomeLabel.Content     = _currentUser.UserName;
            ProfileImage.DataContext = _currentUser;
            Role.Content             = _currentUser.Role;
            Balance.Content          = currentUser.Balance;

            Comments.ScrollToEnd();
        }
コード例 #9
0
        public MainWindow(FamilyOrganizerContext familyOrganizerContext, AppUser currentUser)
        {
            InitializeComponent();

            _context     = familyOrganizerContext;
            _currentUser = currentUser;
            DataContext  = _context.AppUsers.Local.ToBindingList();

            LV.SelectedIndex = 0;

            if (_currentUser.Role != "Parent")
            {
                FamilyTab.Visibility = Visibility.Collapsed;
                StatsTab.Visibility  = Visibility.Collapsed;
            }
        }
コード例 #10
0
        public AddTransaction(FamilyOrganizerContext context, AppUser currentUser)
        {
            InitializeComponent();
            _context           = context;
            _currentUser       = currentUser;
            ToUser.ItemsSource = _context.AppUsers.Where(u => u.UserName != _currentUser.UserName)
                                 .Select(u => u.UserName).ToList();

            if (_context.AppUsers.Count() <= 1)
            {
                TransferItem.IsEnabled = false;
            }
            if (_currentUser.Role == "Child")
            {
                DepositItem.IsEnabled = false;
            }
        }
コード例 #11
0
        public Edit(FamilyOrganizerContext familyOrganizerContext, AppUser currentUser)
        {
            InitializeComponent();
            _context     = familyOrganizerContext;
            _currentUser = currentUser;

            BitmapImage icon = new BitmapImage();

            icon.BeginInit();
            icon.UriSource = new Uri(_currentUser.Photo.Source, UriKind.Relative);
            icon.EndInit();
            ProfileAvatar.Source = icon;

            PhotoId = _currentUser.PhotoId;

            TextBoxCurrentUsername.Text = _currentUser.UserName;
        }
コード例 #12
0
        public Money(FamilyOrganizerContext familyOrganizerContext, AppUser currentUser)
        {
            InitializeComponent();


            _context     = familyOrganizerContext;
            _currentUser = currentUser;

            YearComboBox.ItemsSource = _context.Transactions.Select(b => b.Date.Year).Distinct()
                                       .ToList();

            MonthComboBox.ItemsSource = _context.Transactions.Select(b => b.Date.Month).Distinct()
                                        .ToList();

            YearComboBox.SelectedIndex  = 0;
            MonthComboBox.SelectedIndex = 0;

            SelectTransactions();
        }
コード例 #13
0
        public Statistics(FamilyOrganizerContext familyOrganizerContext, AppUser currentUser)
        {
            InitializeComponent();

            _context     = familyOrganizerContext;
            _currentUser = currentUser;

            YearComboBox.ItemsSource = _context.Balances.Select(b => b.Date.Year).Distinct()
                                       .ToList();

            MonthComboBox.ItemsSource = _context.Balances.Select(b => b.Date.Month).Distinct()
                                        .ToList();

            YearComboBox.SelectedIndex  = 0;
            MonthComboBox.SelectedIndex = 0;

            Chart();

            PieChart();

            DataContext = this;
        }
コード例 #14
0
        private async void AddMoney_Click(object sender, RoutedEventArgs e)
        {
            var currentUser = DataContext as AppUser;

            if (_context == null)
            {
                var a = VisualTreeHelper.GetParent(this);
                while (!(a is Family))
                {
                    a = VisualTreeHelper.GetParent(a);
                }

                _context = (a as Family)._context;
            }

            if (!await _context.AppUsers.AnyAsync(u => u.Id == currentUser.Id))
            {
                return;
            }

            AddMoneyAdmin ama = new AddMoneyAdmin(_context, currentUser);

            ama.Show();
        }
コード例 #15
0
 public AddMoneyAdmin(FamilyOrganizerContext context, AppUser currentUser)
 {
     InitializeComponent();
     _context     = context;
     _currentUser = currentUser;
 }
コード例 #16
0
 public Login(FamilyOrganizerContext context)
 {
     InitializeComponent();
     this.context = context;
 }
コード例 #17
0
        protected override async void OnStartup(StartupEventArgs e)
        {
            try
            {
                if (mutex.WaitOne(0))
                {
                    mutexAccessed = true;
                }
            }
            catch (AbandonedMutexException)
            {
                mutexAccessed = true;
            }

            if (mutexAccessed)
            {
                base.OnStartup(e);
            }
            else
            {
                MessageBox.Show("FamilyOrganizer is running");
                Shutdown();
                return;
            }

            var ss = new SplashScreen();

            ss.Show();
            Context = new FamilyOrganizerContext();
            await Context.Photos.LoadAsync();

            await Context.AppUsers.LoadAsync();

            await Context.Transactions.LoadAsync();

            await Context.Balances.LoadAsync();

            await Context.Comments.LoadAsync();

            await Context.ShoppingPlans.LoadAsync();

            await Context.TodayPlans.LoadAsync();


            //Seed.SeedTransactions(Context);
            //Seed.SeedBalances(Context);
            //Seed.SeedPhotos(Context);


            if (Context.AppUsers.Count() == 0)
            {
                var r = new Register(Context, true);
                r.Show();
            }
            else
            {
                var l = new Login(Context);
                l.Show();
            }
            ss.Close();
        }