Esempio n. 1
0
        private async void deleteItem_Click(object sender, RoutedEventArgs e)
        {
            var todayPlan = (sender as Button).DataContext as TodayPlan;

            _context.TodayPlans.Remove(todayPlan);
            await _context.SaveChangesAsync();

            Refresh();
        }
Esempio n. 2
0
        private async void approveItem_Click(object sender, RoutedEventArgs e)
        {
            var shoppingplan = (sender as Button).DataContext as ShoppingPlan;

            shoppingplan.Accepted = true;
            _context.Entry(shoppingplan).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            Refresh();
        }
Esempio n. 3
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();
        }
        private async void saveLogin_Click(object sender, RoutedEventArgs e)
        {
            var username = TextBoxCurrentUsername.Text;
            var password = TextBoxPassword.Password;

            if (string.IsNullOrWhiteSpace(username))
            {
                var mb = new FamilyOrganizerMessageBox("Username cannot be empty");
                mb.Show();
                return;
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                var mb = new FamilyOrganizerMessageBox("Invalid password");
                mb.Show();
                return;
            }

            if (_context.AppUsers.Any(u => u.UserName == username && u.UserName != _currentUser.UserName))
            {
                var mb = new FamilyOrganizerMessageBox("Username is taken");
                mb.Show();
                return;
            }

            var hashedPassword = PasswordHash.CreateHash(password);

            if (password != "k*7m\\Z!~")
            {
                _currentUser.Password = hashedPassword;
            }

            _currentUser.UserName = username;
            _currentUser.Photo    = await _context.Photos.FirstOrDefaultAsync(p => p.Id == PhotoId);

            _context.Entry(_currentUser).State = EntityState.Modified;
            if (await _context.SaveChangesAsync() > 0)
            {
                var mb = new FamilyOrganizerMessageBox("Your changes have been applied");
                mb.Show();
            }
        }
Esempio n. 5
0
        private async void sendMessage_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(MessageInput.Text) || MessageInput.Text == "Start typing...")
            {
                return;
            }

            var comment = new Comment
            {
                Content = MessageInput.Text,
                User    = _currentUser
            };

            _context.Comments.Add(comment);
            await _context.SaveChangesAsync();

            MessageInput.Text = "";
            Comments.ScrollToEnd();
            MessageInput.Text       = "Start typing...";
            MessageInput.Foreground = Brushes.Gray;
            sendMessage.Focus();
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var username = UsernameRegister.Text;

            if (string.IsNullOrEmpty(username))
            {
                var mb = new FamilyOrganizerMessageBox("Username is required");
                mb.Show();
                return;
            }

            if (string.IsNullOrEmpty(PasswordRegister.Password))
            {
                var mb = new FamilyOrganizerMessageBox("Password is required");
                mb.Show();
                return;
            }

            if (PasswordRegister.Password.Length < 6)
            {
                var mb = new FamilyOrganizerMessageBox("Minimum password length is 6");
                mb.Show();
                return;
            }

            if (_context.AppUsers.Any(u => u.UserName == username))
            {
                var mb = new FamilyOrganizerMessageBox("The username is taken");
                mb.Show();
                return;
            }

            if (_context.AppUsers.Count() == 0)
            {
                Checked = true;
            }

            var hashedPassword = PasswordHash.CreateHash(PasswordRegister.Password);

            var user = new AppUser
            {
                UserName = username,
                Password = hashedPassword,
                Role     = Checked ? "Parent" : "Child"
            };

            _context.AppUsers.Add(user);

            await _context.SaveChangesAsync();

            if (_toMainWindow)
            {
                var mv = new MainWindow(_context, user);
                mv.Show();
            }
            else
            {
                var mb = new FamilyOrganizerMessageBox("Refresh the page to see the changes");
                mb.Show();
            }

            Close();
        }