private void Window_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { var vm = e.NewValue as VMLogin; if (vm == null) { throw new Exception("Wrong DataContext"); } if (vm.CreateAllTransactionsWindowAction == null) { vm.CreateAllTransactionsWindowAction = x => { Hide(); new AllTransactionsWindow(x).ShowDialog(); Show(); Activate(); Topmost = true; Topmost = false; Focus(); }; } using (var db = new DatabaseContext()) { var transactionCount = db.TransactionUsers.Count(); } }
public MultiuserManager(DatabaseContext db, User user, Transaction transaction) { this.db = db; this.user = user; this.transaction = transaction; allUsers = db.Users.ToList(); LoadTransactionUsersCollection(); }
public void TryLogin() { using (var db = new DatabaseContext()) { var user = (db.Users.Where(x => x.Login == LoginData && x.Password == Password)).FirstOrDefault(); Password = ""; if (user != null) { OnLoginSucceed(user.ID); } else { LoginMessage = "Wrong login/password"; } } }
public DetailedTransaction(TransactionUser transactionUser, DatabaseContext db) { this.transactionUser = transactionUser; this.db = db; multiuserManager = new MultiuserManager( db, transactionUser.User, transactionUser.Transaction); if (transactionUser.Transaction.HouseholdExpence != null) { type = "Household expenses"; } else if (transactionUser.Transaction.Wage != null) { type = "Wage"; } else if (transactionUser.Transaction.Deposit != null) { type = "Income on deposit"; } else if (transactionUser.Transaction.Grant != null) { type = "Scholarship"; } else if (transactionUser.Transaction.OtherIncome != null) { type = "Other income"; } else if (transactionUser.Transaction.Rent != null) { type = "Rent"; } else if (transactionUser.Transaction.Credit != null) { type = "Credit expenses"; } else if (transactionUser.Transaction.LongTermExpence != null) { type = "Long term expenses"; } else if (transactionUser.Transaction.OtherExpence != null) { type = "Other expenses"; } }
public TransactionClass() { db = new DatabaseContext(); }
public void Registrate() { if (string.IsNullOrEmpty(Name)) { OnRegistrationFailed("Name is not set."); Password = PasswordCheck = ""; return; } if (string.IsNullOrEmpty(Login)) { OnRegistrationFailed("Login is not set."); Password = PasswordCheck = ""; return; } if (string.IsNullOrEmpty(Password)) { OnRegistrationFailed("Password is not set."); Password = PasswordCheck = ""; return; } if (Password != PasswordCheck) { OnRegistrationFailed("Passwords do not match."); Password = PasswordCheck = ""; return; } using (var db = new DatabaseContext()) { if (db.Users.FirstOrDefault(x => x.Login == Login) == null) { var user = new User() { Name = Name, Login = Login, Password = Password }; db.Users.Add(user); db.SaveChanges(); OnRegistrationSucced(); return; } } OnRegistrationFailed("This login is already exist. Choose another one."); Password = PasswordCheck = ""; }
private void LoadTransactions() { if (userId == null) { throw new Exception("Cannot load transatcions: user is not set"); } var uId = userId.Value; Debug.WriteLine("Loading transactions for {0}", uId); var db = new DatabaseContext(); var df = DateFilter; var tf = TextFilter; Transactions = new ObservableCollection<TransactionUser>(db.Users.First(x => (x.ID == uId)).TransactionUsers .Where(x => // filter by date (df.From == null || x.Transaction.Date >= df.From) && (df.To == null || x.Transaction.Date <= df.To) // filtetr by text && (!tf.DescriptionChecked || string.IsNullOrEmpty(tf.SearchTerm) || (x.Transaction.Description != null && x.Transaction.Description.ToLower().Contains(tf.SearchTerm))) && (!tf.EverywhereChecked || string.IsNullOrEmpty(tf.SearchTerm) || (x.Transaction.Description != null && x.Transaction.Description.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.User.Name != null && x.Transaction.User.Name.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.Grant != null && x.Transaction.Grant.Grant_type != null && x.Transaction.Grant.Grant_type.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.HouseholdExpence != null && x.Transaction.HouseholdExpence.Comment != null && x.Transaction.HouseholdExpence.Comment.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.HouseholdExpence != null && x.Transaction.HouseholdExpence.HE_type != null && x.Transaction.HouseholdExpence.HE_type.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.LongTermExpence != null && x.Transaction.LongTermExpence.LtE_type != null && x.Transaction.LongTermExpence.LtE_type.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.LongTermExpence != null && x.Transaction.LongTermExpence.Comment != null && x.Transaction.LongTermExpence.Comment.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.OtherExpence != null && x.Transaction.OtherExpence.Comment != null && x.Transaction.OtherExpence.Comment.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.OtherExpence != null && x.Transaction.OtherExpence.OE_type != null && x.Transaction.OtherExpence.OE_type.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.OtherIncome != null && x.Transaction.OtherIncome.Comment != null && x.Transaction.OtherIncome.Comment.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.OtherIncome != null && x.Transaction.OtherIncome.OI_type != null && x.Transaction.OtherIncome.OI_type.ToLower().Contains(tf.SearchTerm)) || (x.Transaction.Wage != null && x.Transaction.Wage.Workplace != null && x.Transaction.Wage.Workplace.ToLower().Contains(tf.SearchTerm))) // filter by type && (( TypeFilter.WageChecked && x.Transaction.Wage != null) || (TypeFilter.HouseholdExpensesChecked && x.Transaction.HouseholdExpence != null) || (TypeFilter.IncomeOnDepositChecked && x.Transaction.Deposit != null) || (TypeFilter.ScholarshipChecked && x.Transaction.Grant != null) || (TypeFilter.OtherIncomeChecked && x.Transaction.OtherIncome != null) || (TypeFilter.RentChecked && x.Transaction.Rent != null) || (TypeFilter.CreditExpensesChecked && x.Transaction.Credit != null) || (TypeFilter.LongTermldExpensesChecked && x.Transaction.LongTermExpence != null) || (TypeFilter.OtherdExpensesChecked && x.Transaction.OtherExpence != null) )) .Select(x => x)); Income = Transactions.Select(t => t.Sum != null ? t.Sum.Value : 0).Where(s => s > 0).Sum(); Expences = Transactions.Select(t => t.Sum != null ? t.Sum.Value : 0).Where(s => s < 0).Sum(); Balance = Transactions.Select(t => t.Sum != null ? t.Sum.Value : 0).Sum(); }
public void DeleteTransaction() { if (SelectedTransaction != null) { using (var db = new DatabaseContext()) { db.TransactionUsers.Remove(db.TransactionUsers.First(x => x.ID_transaction == SelectedTransaction.ID_transaction && x.ID_user == SelectedTransaction.ID_user)); db.SaveChanges(); } LoadTransactions(); } }