Exemple #1
0
 public void Update(Income income)
 {
     //TODO -there should be tests that cover this, but what happens if the item is a new item?
     CleanUpForEF(income);
     _context.Incomes.Attach(income);
     _context.SaveChanges();
 }
Exemple #2
0
 public void Save(Income incomeToSave)
 {
     Contract.Requires<ArgumentNullException>(incomeToSave != null, "The income must not be null");
     Contract.Requires<ArgumentNullException>(incomeToSave.CategoryId > 0, "There must be a category selected");
     Contract.Requires<ArgumentNullException>(incomeToSave.PaymentMethodId > 0, "There must be a payment method selected");
     _repository.Save(incomeToSave);
 }
Exemple #3
0
 public void Create(Income income)
 {
     if (income == null)
     {
         return;
     }
     CleanUpForEF(income);
     _context.Incomes.Add(income);
     _context.SaveChanges();
 }
Exemple #4
0
 public void Save(Income income)
 {
     if (income.Id != 0)
     {
         Update(income);
     }
     else
     {
         Create(income);
     }
 }
Exemple #5
0
        /// <summary>
        ///     Sets the intial state and current state expense properties of the form
        /// </summary>
        /// <param name="income">The income the form was opened for</param>
        public IncomeViewer(Income income)
        {
            InitializeComponent();

            currentIncome = income;
            originalIncome = currentIncome.Copy();

            _dataContext = new AccountingDataContext();
            _incomeService = new IncomeService(new IncomeRepository(_dataContext));
            _incomeCategoryService = new IncomeCategoryService(new IncomeCategoryRepository(_dataContext));
            _paymentMethodService = new PaymentMethodService(new PaymentMethodRepository(_dataContext));
        }
Exemple #6
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
            currentIncome = originalIncome.Copy();

            // Resets the data bindings
            SetDataBindings();
        }
Exemple #7
0
        /// <summary>
        ///     Saves the new income 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.IsDecimal())
            {
                MessageBox.Show("The amount must be in numbers",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1);
                txtAmount.Text = "";
            }
            // Otherwise saves the new income
            else
            {
                var newIncome = new Income(decimal.Parse(txtAmount.Text), dtPick.Value, Convert.ToInt32(cmbCategory.SelectedValue), Convert.ToInt32(cmbPayment.SelectedValue), txtDetail.Text);

                _incomeService.Create(newIncome);

                // Asks if more data is being entered
                DialogResult = MessageBox.Show("The entry was saved" +
                                               "\nDo you want to add another income? ",
                    "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 = "";
                }
            }
        }
Exemple #8
0
 public void Save(Income incomeToSave)
 {
     _repository.Save(incomeToSave);
 }
Exemple #9
0
 public void Create(Income newIncome)
 {
     _repository.Create(newIncome);
 }
Exemple #10
0
 private void CleanUpForEF(Income income)
 {
     if (income.CategoryId > 0)
     {
         income.Category = null;
     }
     if (income.PaymentMethodId > 0)
     {
         income.Method = null;
     }
 }
 private void CreateNewIncome(DateTime dtCurrentSaveDate)
 {
     Income newIncome =
             new Income(decimal.Parse(this.txtAmount.Text), dtCurrentSaveDate,
                         _incomeCategoryService.LoadById(Convert.ToInt32(this.cmbCategory.SelectedValue)),
                         _paymentMethodService.LoadById(Convert.ToInt32(this.cmbPayment.SelectedValue)),
                         this.txtDetail.Text);
 }
Exemple #12
0
 public void Update(Income income)
 {
     _context.Incomes.Attach(income);
     _context.SaveChanges();
 }
Exemple #13
0
 public void Create(Income income)
 {
     _context.Incomes.Add(income);
     _context.SaveChanges();
 }
 private void CreateNewIncome(DateTime dtCurrentSaveDate)
 {
     Income newIncome = new Income(decimal.Parse(txtAmount.Text), dtCurrentSaveDate, Convert.ToInt32(cmbCategory.SelectedValue), Convert.ToInt32(cmbPayment.SelectedValue), txtDetail.Text);
 }