Example #1
0
        public async Task <IActionResult> RemoveBankAccount([FromBody] BankAccountIdViewModel model)
        {
            string id   = User.FindFirst("id").Value;
            User   user = await UserManager.FindByIdAsync(id);

            if (user == null)
            {
                return(Unauthorized());
            }

            BankAccount account = user.BankAccounts.FirstOrDefault(b => b.Id == Guid.Parse(model.Id));

            if (account == null)
            {
                return(NotFound($"No Bank Account exists with id {model.Id}"));
            }

            account.IsActive = false;

            if (account.IsDefault)
            {
                account.IsDefault = false;
                BankAccount nextAccount = user.BankAccounts.FirstOrDefault(b => b.IsActive);
                if (nextAccount != null)
                {
                    nextAccount.IsDefault = true;
                }
            }

            bool success = await DataContext.Store.UpdateOneAsync(user);

            return(Ok());
        }
Example #2
0
        public async Task <IActionResult> RemoveBankAccount([FromBody] BankAccountIdViewModel model)
        {
            User user = DataContext.PlatformAccount;

            BankAccount account = user.BankAccounts.FirstOrDefault(b => b.Id == Guid.Parse(model.Id));

            if (account == null)
            {
                return(NotFound($"No Bank Account exists with id {model.Id}"));
            }

            account.IsActive = false;

            bool success = await DataContext.Store.UpdateOneAsync(user);

            return(Ok());
        }