Ejemplo n.º 1
0
 public void Save(Expense expenseToSave)
 {
     Contract.Requires<ArgumentNullException>(expenseToSave != null, "The expense must not be null");
     Contract.Requires<ArgumentNullException>(expenseToSave.CategoryId > 0, "There must be a category selected");
     Contract.Requires<ArgumentNullException>(expenseToSave.PaymentMethodId > 0, "There must be a payment method selected");
     _repository.Save(expenseToSave);
 }
Ejemplo n.º 2
0
 public void Create(Expense expense)
 {
     if (expense == null)
     {
         return;
     }
     CleanUpForEF(expense);
     _context.Expenses.Add(expense);
     _context.SaveChanges();
 }
Ejemplo n.º 3
0
 public void Save(Expense expense)
 {
     if (expense.Id != 0)
     {
         Update(expense);
     }
     else
     {
         Create(expense);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     Cancels the edit and leaves the form open
        ///     -clears any changes made
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            // Enables the controls for editing and updates which buttons are visible
            ToggleEnableControls(txtAmount, txtDetail, cmbCategory,
                cmbPayment, dtPick, btnSave, btnEdit, btnCancel, btnDelete);
            ToggleVisibility(btnSave, btnCancel, btnEdit, btnDelete);

            // Makes sure that the expense of the binding has the origional values
            currentExpense = originalExpense.Copy();

            // Resets the data bindings
            SetDataBindings();
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Sets the intial state and current state expense properties of the form
        /// </summary>
        /// <param name="expense">The expense the form was opened for</param>
        public ExpenseViewer(Expense expense)
        {
            currentExpense = expense;

            // Makes a shallow copy of the expense passed in
            originalExpense = currentExpense.Copy();
            InitializeComponent();

            _dataContext = new AccountingDataContext();
            _expenseService = new ExpenseService(new ExpenseRepository(_dataContext));
            _expenseCategoryService = new ExpenseCategoryService(new ExpenseCategoryRepository(_dataContext));
            _paymentMethodService = new PaymentMethodService(new PaymentMethodRepository(_dataContext));
        }
Ejemplo n.º 6
0
        private void SaveNewExpense(DateTime dtCurrentSaveDate)
        {
            var newExpense =
                new Expense(decimal.Parse(txtAmount.Text), dtCurrentSaveDate,
                    _expenseCategoryService.LoadById(Convert.ToInt32(cmbCategory.SelectedValue)),
                    _paymentMethodService.LoadById(Convert.ToInt32(cmbPayment.SelectedValue)),
                    txtDetail.Text);

            _expenseService.Create(newExpense);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Saves the new expense into the cache -validates the amount
        ///     and gives an option to enter more data
        /// </summary>
        /// <param name="sender">Standard sender object</param>
        /// <param name="e">Standard event object</param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            // If the amount is blank
            if (txtAmount.Text == "")
            {
                MessageBox.Show("The amount can not be blank",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1);
            }
            // Checks that the amount is in numbers
            else if (!txtAmount.Text.IsDouble())
            {
                MessageBox.Show("The amount must be in numbers",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1);
                txtAmount.Text = "";
            }
            // Otherwise saves the new expense
            else
            {
                var newExpense =
                    new Expense(decimal.Parse(txtAmount.Text), dtPick.Value,
                        _expenseCategoryService.LoadById(Convert.ToInt32(cmbCategory.SelectedValue)),
                        _paymentMethodService.LoadById(Convert.ToInt32(cmbPayment.SelectedValue)),
                        txtDetail.Text);

                _expenseService.Create(newExpense);

                // Asks if more data is being entered
                DialogResult = MessageBox.Show("The entry was saved" +
                                               "\nDo you want to add another expense? ",
                    "Save successful",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button1);
                if (DialogResult != DialogResult.Yes)
                {
                    Close();
                }
                // If more data is being entered clears the user entered data for the new data
                else
                {
                    // Puts the focus back to the top of the form and resets the selected values
                    cmbCategory.Focus();
                    txtAmount.Text = "";
                    txtDetail.Text = "";
                }
            }
        }
Ejemplo n.º 8
0
 public void Update(Expense expense)
 {
     _context.Expenses.Attach(expense);
     _context.SaveChanges();
 }
Ejemplo n.º 9
0
 public void Create(Expense expense)
 {
     _context.Expenses.Add(expense);
     _context.SaveChanges();
 }
Ejemplo n.º 10
0
 private void CleanUpForEF(Expense expense)
 {
     if (expense.CategoryId > 0)
     {
         expense.Category = null;
     }
     if (expense.PaymentMethodId > 0)
     {
         expense.Method = null;
     }
 }
Ejemplo n.º 11
0
 public void Save(Expense expenseToSave)
 {
     _repository.Save(expenseToSave);
 }
Ejemplo n.º 12
0
 public void Create(Expense newExpense)
 {
     _repository.Create(newExpense);
 }