// GET /expenses/
        public ActionResult Index()
        {
            var expenseForms = _context.ExpenseForms.ToList();
            var expenseForm  = new ExpenseForm();

            return(View(expenseForms));
        }
        public ActionResult SaveExpenseForm(ExpenseFormViewModel expenseForm)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index"));
            }


            var _user = _userManager.FindById(User.Identity.GetUserId());

            var expenseForms = _context.ExpenseForms.Where(e => e.UserId == _user.Id).ToList();

            if (expenseForm.Id == 0)
            {
                var expenseFormToSave = new ExpenseForm
                {
                    Name      = expenseForm.Name,
                    DateAdded = DateTime.Now,
                    TotalCost = 0,
                    UserId    = _user.Id,
                    User      = _user
                };
                _context.ExpenseForms.Add(expenseFormToSave);
            }
            else
            {
                var _expenseFormInDb = _context.ExpenseForms.First(e => e.Id == expenseForm.Id);
                _expenseFormInDb.Name = expenseForm.Name;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> Update(ExpenseForm expense)
        {
            await _expenseService.Update(expense);

            var viewModel = new ExpenseListViewModel()
            {
                VirtualAccountId = expense.VirtualAccountId,
                Expenses         = await _expenseService.GetAll(expense.VirtualAccountId)
            };

            return(PartialView("_ExpenseList", viewModel));
        }
Esempio n. 4
0
        public async void IsBankAccountCreatePossible()
        {
            var form = new ExpenseForm()
            {
                Amount            = 20.05,
                Name              = "Pączek",
                ExpenseCategoryId = 1,
                VirtualAccountId  = 1
            };
            var result = await _expenseService.Create(form);

            Assert.NotEqual(0, result);
        }
Esempio n. 5
0
        public async Task <int> Create(ExpenseForm form)
        {
            try
            {
                var newEntity    = _mapper.Map <DaoExpense>(form);
                var createdEntry = _context.Expenses.Add(newEntity);
                await _context.SaveChangesAsync();

                return(createdEntry.Entity.Id);
            }
            catch (Exception e)
            {
                throw new RepositoryException(typeof(DaoExpense).Name, eRepositoryExceptionType.Create);
            }
        }
Esempio n. 6
0
        public override void edit(int id)
        {
            Expense Expense = (from p in db.Expense   // consult
                               where p.Id == id
                               select p).FirstOrDefault();

            ExpenseForm ExpenseViewer = new ExpenseForm();

            ExpenseViewer.mainEntity = Expense;
            ExpenseViewer.controller = this;

            if (ExpenseViewer.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                db.SaveChanges();
            }
        }
Esempio n. 7
0
        private void EditTransactionClicked(object sender, RoutedEventArgs e)
        {
            var transaction = this.transactions.Where(t => t.InvoiceNumber == (sender as Button).Tag.ToString()).First <Transactions>();

            if (transaction != null)
            {
                if (transaction is Income)
                {
                    var incomeForm = new IncomeForm(this.dbAccess, (Income)transaction);
                    incomeForm.Show();
                }
                else
                {
                    var expenseForm = new ExpenseForm(this.dbAccess, (Expense)transaction);
                    expenseForm.Show();
                }
            }
        }
Esempio n. 8
0
        public async Task <int> Update(ExpenseForm form)
        {
            try
            {
                var updateEntity = this._mapper.Map <DaoExpenseCategory>(form);

                var updated = await _context.Expenses.FirstOrDefaultAsync(_ => _.Id == updateEntity.Id);

                _context.Entry(updated).CurrentValues.SetValues(updateEntity);

                await _context.SaveChangesAsync();

                return(updated.Id);
            }
            catch (Exception e)
            {
                throw new RepositoryException(typeof(DaoExpense).Name, eRepositoryExceptionType.Update);
            }
        }
Esempio n. 9
0
        public override void add()
        {
            try
            {
                Expense     Expense       = new Expense(); // initilize entity
                ExpenseForm ExpenseViewer = new ExpenseForm();
                ExpenseViewer.mainEntity = Expense;
                ExpenseViewer.controller = this;

                if (ExpenseViewer.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    db.Expense.Add(Expense);
                    db.SaveChanges();
                }
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 10
0
        private void ExpenseButtonClicked(object sender, RoutedEventArgs e)
        {
            var expenseForm = new ExpenseForm(this.dbAccess);

            expenseForm.Show();
        }
Esempio n. 11
0
 public async Task <int> Update(ExpenseForm form)
 {
     return(await _expenseRepository.Update(form));
 }
Esempio n. 12
0
        private void addExpenseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExpenseForm expense = new ExpenseForm();

            expense.Show();
        }
Esempio n. 13
0
        internal static void OpenExpenseForm()
        {
            ExpenseForm ef = new ExpenseForm();

            ef.Show();
        }
Esempio n. 14
0
        private void Expensebutton_Click(object sender, EventArgs e)
        {
            ExpenseForm s = new ExpenseForm();

            s.Show();
        }