private void LoadserList() { try { var mlist = new PortalServiceManager().GetPortalUserList(); if (mlist == null) { dgPortalUsers.DataSource = new List <portaluser>(); dgPortalUsers.DataBind(); } var userList = Membership.GetAllUsers(); if (userList == null || userList.Count == 0) { ConfirmAlertBox1.ShowMessage("Executive Officer list is empty.", ConfirmAlertBox.PopupMessageType.Error); return; } var executiveOfficerRoleList = (from MembershipUser member in userList where Roles.IsUserInRole(member.UserName, "ExecutiveOfficer") select member).ToList(); if (!executiveOfficerRoleList.Any()) { ConfirmAlertBox1.ShowMessage("The Transaction Approver list could not be retrieved. Your Transaction request notification cannot be sent.\n Approval of your request may be delayed.", ConfirmAlertBox.PopupMessageType.Error); return; } var executiveOfficerList = new List <portaluser>(); foreach (MembershipUser executive in executiveOfficerRoleList) { if (mlist != null) { var executiveOfficer = mlist.Find(m => executive.ProviderUserKey != null && m.UserId == (int)executive.ProviderUserKey); if (executiveOfficer == null || executiveOfficer.PortalUserId < 1) { continue; } executiveOfficerList.Add(executiveOfficer); } } dgPortalUsers.DataSource = executiveOfficerList; dgPortalUsers.DataBind(); } catch (Exception) { dgPortalUsers.DataSource = new List <portaluser>(); dgPortalUsers.DataBind(); } }
private bool LoadFilteredPortalUsers() { try { ErrorDisplay1.ClearError(); dgExpenseTransaction.DataSource = new List <StaffExpenseTransaction>(); dgExpenseTransaction.DataBind(); ddlPortalUser.DataSource = new List <portaluser>(); ddlPortalUser.Items.Insert(0, new ListItem("--List is empty--", "0")); ddlPortalUser.SelectedIndex = 0; ddlStaffPortalUsersVouchers.DataSource = new List <portaluser>(); ddlStaffPortalUsersVouchers.Items.Insert(0, new ListItem("--List is empty--", "0")); ddlStaffPortalUsersVouchers.SelectedIndex = 0; var portalUsersWithRegisteredTransactions = ServiceProvider.Instance().GetStaffExpenseTransactionServices().GetFilteredPortalUsers(); if (portalUsersWithRegisteredTransactions == null || !portalUsersWithRegisteredTransactions.Any()) { ErrorDisplay1.ShowError("Portal User Transaction list is empty."); return(false); } var idsForUsersWithUnApprovedTransactions = portalUsersWithRegisteredTransactions.ElementAt(0).Key.FindAll(m => m > 0).ToList(); var idsForUsersWithApprovedTransactions = portalUsersWithRegisteredTransactions.ElementAt(0).Value.FindAll(m => m > 0).ToList(); var portalUsers = new PortalServiceManager().GetPortalUserList(); if (portalUsers == null || !portalUsers.Any()) { return(false); } var portalUsersWithUnApprovedTransactions = new List <portaluser>(); var portalUsersWithApprovedTransactions = new List <portaluser>(); foreach (var userId in idsForUsersWithUnApprovedTransactions.Where(portaluserId => portalUsersWithUnApprovedTransactions.All(m => m.UserId != portaluserId))) { portalUsersWithUnApprovedTransactions.Add(portalUsers.Find(m => m.UserId == userId)); } foreach (var userId in idsForUsersWithApprovedTransactions.Where(portaluserId => portalUsersWithApprovedTransactions.All(m => m.UserId != portaluserId))) { portalUsersWithApprovedTransactions.Add(portalUsers.Find(m => m.UserId == userId)); } if (portalUsersWithUnApprovedTransactions.Any()) { ddlPortalUser.DataSource = portalUsersWithUnApprovedTransactions; ddlPortalUser.DataTextField = "UserName"; ddlPortalUser.DataValueField = "UserId"; ddlPortalUser.DataBind(); ddlPortalUser.Items.Insert(0, new ListItem("--Select a User--", "0")); ddlPortalUser.SelectedIndex = 0; } if (portalUsersWithApprovedTransactions.Any()) { ddlStaffPortalUsersVouchers.DataSource = portalUsersWithApprovedTransactions; ddlStaffPortalUsersVouchers.DataTextField = "UserName"; ddlStaffPortalUsersVouchers.DataValueField = "UserId"; ddlStaffPortalUsersVouchers.DataBind(); ddlStaffPortalUsersVouchers.Items.Insert(0, new ListItem("--Select a User--", "0")); ddlStaffPortalUsersVouchers.SelectedIndex = 0; } dgExpenseTransaction.DataSource = new List <StaffExpenseTransaction>(); dgExpenseTransaction.DataBind(); SetApprovedTransactionStyle(); Session["_filteredStaffPortalUserList"] = portalUsersWithUnApprovedTransactions; return(true); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); ErrorDisplay1.ShowError("An unknown error was encountered. Please try again soon or contact the Admin."); return(false); } }