private void simpleButton1_Click(object sender, EventArgs e) { var obj = accountuserbindingSource.DataSource as List<AccountUser>; foreach (var item in obj) { var accountUser = new AccountUser { AccountID = item.AccountID, UserID = CurrentUser.UserID, //AccountStatus = true }; accountuserRepository.Add(accountUser); } }
private void BtnSaveAccountClick(object sender, EventArgs e) { if (accountlistBox.SelectedItem == null) { ViewHelper.ShowErrorMessage("There is no account to be added."); activityLogger.SaveAction(CurrentUser.UserID, 1, "User Account list", "There is no account to be added."); this.Close(); } accountuserbindingSource.EndEdit(); var obj = accountuserbindingSource.DataSource as List<AccountUser>; try { var selectedItems = accountlistBox.SelectedItems; foreach (var anItem in selectedItems) { var item = anItem as Activity; // check if there is a deactivated account by the same account id var aUser = repository.AccountUsers.FindBy(u => u.UserID == CurrentUser.UserID && u.AccountID == item.ActivityID).FirstOrDefault(); if (aUser != null) { aUser.IsActive = true; repository.AccountUsers.Update(aUser); } else { var accountUser = new AccountUser { AccountID = item.ActivityID, UserID = CurrentUser.UserID, IsActive = true }; repository.AccountUsers.Add(accountUser); } } activityLogger.SaveAction(CurrentUser.UserID, 1, "User Account list", "Account Succesfully Added"); this.Close(); } catch (Exception ex) { ViewHelper.ShowErrorMessage("Unable to create account", ex); errorLogger.SaveError(CurrentUser.UserID, 1, 1, 2, "Add account attempt", "Warehouse", ex); } }