public async Task <IActionResult> Edit(int id, [Bind("Id,AccountName,IsActivated")] InternalAccountViewModel accountViewModel)
        {
            if (id != accountViewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _gLAccountService.EditInternalAccountAsync(accountViewModel);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await _gLAccountService.GLAccountExists(accountViewModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(accountViewModel));
        }
        public async Task EditInternalAccountAsync(InternalAccountViewModel accountViewModel)
        {
            var account = await _context.GLAccounts.FindAsync(accountViewModel.Id);

            account.AccountName = accountViewModel.AccountName;
            account.IsActivated = accountViewModel.IsActivated;
            _context.Update(account);
            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("CategoryId,AccountName,IsActivated")] InternalAccountViewModel accountViewModel)
        {
            if (ModelState.IsValid)
            {
                await _gLAccountService.AddInternalAccountAsync(accountViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(accountViewModel));
        }
        public InternalAccountViewModel GetAddInternalAccount()
        {
            var accountViewModel = new InternalAccountViewModel();
            var categories       = _context.GLCategories.ToList();

            foreach (var category in categories)
            {
                accountViewModel.GLCategories.Add(new SelectListItem()
                {
                    Text  = category.Name,
                    Value = category.GLCategoryId.ToString()
                });
            }
            return(accountViewModel);
        }
        public async Task AddInternalAccountAsync(InternalAccountViewModel accountViewModel)
        {
            var categoryId = int.Parse(accountViewModel.CategoryId);
            var category   = await _context.GLCategories.FindAsync(categoryId);

            var account = new InternalAccount
            {
                AccountCode  = GenerateInternalAccountCode(category.Type),
                AccountName  = accountViewModel.AccountName,
                GLCategoryId = categoryId,
                IsActivated  = accountViewModel.IsActivated
            };

            _context.Add(account);
            await _context.SaveChangesAsync();
        }
        public async Task <InternalAccountViewModel> GetEditInternalAccount(int id)
        {
            var account = await RetrieveInternalAccountAsync(id);

            var accountViewModel = new InternalAccountViewModel()
            {
                AccountName = account.AccountName,
                AccountCode = account.AccountCode,
                IsActivated = account.IsActivated,
                CategoryId  = account.GLCategoryId.ToString(),
                Id          = account.GLAccountId
            };

            accountViewModel.GLCategories.Add(new SelectListItem()
            {
                Text  = account.GLCategory.Name,
                Value = account.GLCategory.GLCategoryId.ToString()
            });
            return(accountViewModel);
        }