public UserBAViewModel GetAllBankAccount(string userId, bool toAttach) { try { List <BankAccount> bankAccounts; var userBaViewModel = new UserBAViewModel(); if (toAttach) //selecciono cuentas de bancos para usuarios { var userIdConverted = Convert.ToInt32(userId); var user = Table .Include(c => c.BankAccounts) .Single(c => c.Id == userIdConverted); bankAccounts = user.BankAccounts.Select(c => c).ToList(); } else //SINO, selecciono todas las cuentas de usuario. { bankAccounts = Context.BankAccounts .Where(c => c.Deleted == false).ToList(); } //Mapeo que se le hace a los dos casos. userBaViewModel.UserId = Convert.ToInt32(userId); userBaViewModel.BankAccounts = bankAccounts; return(userBaViewModel); } catch (Exception ex) { throw new Exception(ex.Message + "User not found. "); } }
public ActionResult DeAttach(string userId, string bankAccountId) { UserBAViewModel userBaViewModel = new UserBAViewModel(); if (ModelState.IsValid) { if (!string.IsNullOrEmpty(bankAccountId) && (!string.IsNullOrEmpty(userId))) { var userIdConvert = Convert.ToInt32(userId); var bAId = Convert.ToInt32(bankAccountId); userBaViewModel = _userRepository.DeAttachBankAccountToUser(userIdConvert, bAId); } } return(PartialView("Sections/BankAccounts", userBaViewModel)); }