Exemple #1
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Searched For User", (int)UserActionEnum.Clicked);
            db = new HPSDB();

            // Get the creation dates
            DateTime startDate = (txtSearchStartDate.Text != String.Empty) ? Convert.ToDateTime(txtSearchStartDate.Text) : DateTime.MinValue;
            DateTime endDate   = (txtSearchStartDate.Text != String.Empty) ? Convert.ToDateTime(txtSearchEndDate.Text) : DateTime.MaxValue;

            // Get the normal textboxes
            string firstName = (txtSearchFirstName.Text != String.Empty) ? txtSearchFirstName.Text : String.Empty;
            string lastName  = (txtSearchLastName.Text != String.Empty) ? txtSearchLastName.Text : String.Empty;
            string email     = (txtSearchEmail.Text != String.Empty) ? txtSearchEmail.Text : String.Empty;
            string username  = (txtSearchUserName.Text != String.Empty) ? txtSearchUserName.Text : String.Empty;
            string role      = (ddlSearchUserRole.SelectedValue != "-1") ? ddlSearchUserRole.SelectedValue : String.Empty;

            // Search based on criteria
            var users = db.HPSUsers
                        .Where(f => f.FirstName.Contains(firstName))
                        .Where(l => l.LastName.Contains(lastName))
                        .Where(em => em.AspNetUser.Email.Contains(email))
                        .Where(u => u.AspNetUser.UserName.Contains(username))
                        .Where(s => s.CreatedOn >= startDate && s.CreatedOn <= endDate)
                        .Where(a => a.RoleName.Contains(role))
                        .ToList();


            if (users.Any())
            {
                // Build the results table
                TableBuilder.BuildUsersTable(tblUsers, users, false);
            }
            else
            {
                lblNoResults.Visible = true;
                lblNoResults.Text    = "No results found.";
            }

            // Show the panel
            pnlSearchResults.Visible = true;
        }