private void SaveExpense() { var userRepository = new UserRepository(); var user = userRepository.GetUser(this.User.Identity.Name); var approverName = this.Approver.Text; if (string.IsNullOrEmpty(approverName)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "The approver {0} does not exists", this.Approver.Text)); } var newExpense = new Expense { Id = StorageKey.Now.InvertedTicks, Title = this.ExpenseTitle.Text, CostCenter = user.CostCenter, Approved = false, ReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedItem.Value), UserName = user.UserName, Date = DateTime.Parse(this.ExpenseDate.Text, CultureInfo.CurrentUICulture), ApproverName = approverName }; this.ExpenseItems.ForEach(ei => newExpense.Details.Add(ei)); var expenseRepository = new ExpenseRepository(); expenseRepository.SaveExpense(newExpense); user.PreferredReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedValue); userRepository.UpdateUserPreferredReimbursementMethod(user); }
private void InitializeControls() { var userRepository = new UserRepository(); var user = userRepository.GetUser(this.User.Identity.Name); if (user == null) { throw new InvalidOperationException("User not exists"); } this.ExpenseReimbursementMethod.Items.Add(new ListItem("Check", ReimbursementMethod.Check.ToString())); this.ExpenseReimbursementMethod.Items.Add(new ListItem("Cash", ReimbursementMethod.Cash.ToString())); this.ExpenseReimbursementMethod.Items.Add(new ListItem("Direct Deposit", ReimbursementMethod.DirectDeposit.ToString())); if (user.PreferredReimbursementMethod != ReimbursementMethod.NotSet) { this.ExpenseReimbursementMethod.SelectedValue = user.PreferredReimbursementMethod.ToString(); } this.ExpenseCostCenter.Text = Server.HtmlEncode(user.CostCenter); this.Approver.Text = user.Manager; this.ExpenseItemsGridView.DataSource = this.ExpenseItems; this.ExpenseItemsGridView.DataBind(); }