Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id)
        {
            Expense expenseToEdit = await _dbContext.Expenses.Include(x => x.Category).FirstOrDefaultAsync(x => x.Id == id);

            var categories = await _dbContext.Categories.ToListAsync();

            var persons = await _dbContext.Persons.ToListAsync();

            BankEditViewModel vm = new BankEditViewModel();

            foreach (Category category in categories)
            {
                vm.Category.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()
                {
                    Value = category.Id.ToString(),
                    Text  = category.Name
                });
            }

            vm.Person = persons.Select(person => new SelectListItem()
            {
                Value = person.Id.ToString(), Text = person.Name
            }).ToList();

            vm.Amount      = expenseToEdit.Amount;
            vm.CategoryId  = expenseToEdit.Category.Id;
            vm.Description = expenseToEdit.Description;
            vm.Date        = expenseToEdit.Date;

            return(View(vm));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(BankEditViewModel viewModel)
        {
            var bank = new Bank {
                Bic = viewModel.Bic, Name = viewModel.Name, RecordDate = DateTime.Now
            };

            await _marketingProvider.Banks.UpsertAsync(bank);

            return(Redirect("/Banks/GetAll"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(string bic)
        {
            var bank = await _marketingProvider.Banks.GetByBicAsync(bic);

            var bankEditViewModel = new BankEditViewModel {
                Bic = bank.Bic, Name = bank.Name
            };

            return(View(bankEditViewModel));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, BankEditViewModel vm)
        {
            Expense changedExpense = await _dbContext.Expenses.Include(x => x.Category).FirstOrDefaultAsync(x => x.Id == id);

            if (changedExpense.BankAppIdentityId == User.FindFirstValue(ClaimTypes.NameIdentifier))
            {
                changedExpense.Persons_Expenses = vm.SelectedPersons.Select(person => new Person_Expense()
                {
                    PersonId = person
                }).ToList();
                changedExpense.CategoryId  = vm.CategoryId;
                changedExpense.Amount      = vm.Amount;
                changedExpense.Description = vm.Description;
                changedExpense.Date        = vm.Date;

                var expense = _dbContext.Expenses.Include(a => a.Persons_Expenses).SingleOrDefault(a => a.Id == id);
                _dbContext.Remove(expense);
                _dbContext.Expenses.Update(changedExpense);
                await _dbContext.SaveChangesAsync();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Delete(BankEditViewModel viewModel)
        {
            await _marketingProvider.Banks.DeleteAsync(viewModel.Bic);

            return(Redirect("/Banks/GetAll"));
        }