private bool LoadPortalUsers() { var userList = new PortalServiceManager().GetPortalUserList(); if (userList == null || !userList.Any()) { return(false); } Session["_userList"] = userList; return(true); }
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); } }