private async void approveItem_Click(object sender, RoutedEventArgs e) { var todayPlan = (sender as Button).DataContext as TodayPlan; todayPlan.IsAdded = true; _context.Entry(todayPlan).State = EntityState.Modified; await _context.SaveChangesAsync(); Refresh(); }
private void Button_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(TranSum.Text)) { var mb = new FamilyOrganizerMessageBox("The sum is required"); mb.Show(); return; } if (!_intAndFloat.IsMatch(TranSum.Text)) { var mb = new FamilyOrganizerMessageBox("The sum is invalid"); mb.Show(); return; } var sum = Convert.ToDouble(TranSum.Text); var toUser = _currentUser; var transaction = new Transaction { Type = "Deposit", Date = DateTime.Now, Sum = sum, ToUser = toUser }; _context.Transactions.Add(transaction); _currentUser.Balance += sum; _context.Entry(_currentUser).State = EntityState.Modified; var currentBalanceEntry = _context.Balances.OrderByDescending(b => b.Date).FirstOrDefault(); if (currentBalanceEntry == null) { currentBalanceEntry = new Balance { Date = DateTime.Now } } ; var currentBalance = _context.AppUsers.Sum(u => u.Balance); if (currentBalanceEntry.Date.Day == transaction.Date.Day && _context.Balances.Count() > 0) { _context.Balances.Remove(currentBalanceEntry); } _context.Balances.Add(new Balance { Date = transaction.Date, CurrentBalance = currentBalance + sum }); _context.SaveChanges(); TranSum.Text = ""; }
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(); }
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(); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(TranSum.Text)) { var mb = new FamilyOrganizerMessageBox("The sum is required"); mb.Show(); return; } if (!_intAndFloat.IsMatch(TranSum.Text)) { var mb = new FamilyOrganizerMessageBox("The sum is invalid"); mb.Show(); return; } var toUsername = ToUser.SelectedItem?.ToString(); var sum = -Convert.ToDouble(TranSum.Text); var toUser = _currentUser; var type = "Money transfer"; if (_currentUser.Balance < Math.Abs(sum) && (TypeChoice.SelectedItem as ComboBoxItem).Content?.ToString() != "Deposit") { var mb = new FamilyOrganizerMessageBox("You don't have enough money"); mb.Show(); return; } switch ((TypeChoice.SelectedItem as ComboBoxItem)?.Content?.ToString()) { case "Transfer": _currentUser.Balance += sum; _context.Entry(_currentUser).State = EntityState.Modified; toUser = _context.AppUsers.FirstOrDefault(u => u.UserName == toUsername); sum = -sum; break; case "Deposit": sum = -sum; _currentUser.Balance += sum; _context.Entry(_currentUser).State = EntityState.Modified; type = "Deposit"; break; case "Expense": _currentUser.Balance += sum; _context.Entry(_currentUser).State = EntityState.Modified; type = (CategoryChoice.SelectedItem as ComboBoxItem).Content?.ToString(); break; default: return; } var transaction = new Transaction { Type = type, Date = DateTime.Now, Sum = sum, ToUser = toUser }; _context.Transactions.Add(transaction); if (transaction.ToUser != _currentUser) // transfer { toUser.Balance += sum; _context.Entry(toUser).State = EntityState.Modified; _context.Transactions.Add(new Transaction { Type = transaction.Type, Date = transaction.Date, Sum = -transaction.Sum, ToUser = _currentUser }); } else { var currentBalanceEntry = _context.Balances.OrderByDescending(b => b.Date).FirstOrDefault(); if (currentBalanceEntry == null) { currentBalanceEntry = new Balance { Date = DateTime.Now } } ; var currentBalance = _context.AppUsers.Sum(u => u.Balance); if (currentBalanceEntry.Date.Day == transaction.Date.Day && _context.Balances.Count() > 0) { _context.Balances.Remove(currentBalanceEntry); } _context.Balances.Add(new Balance { Date = transaction.Date, CurrentBalance = currentBalance + sum }); } _context.SaveChanges(); TranSum.Text = ""; }