protected void btnSearch_Click(object sender, EventArgs e)
        {
            Expression<Func<Claim, bool>> predicate = null;
            List<AdjusterView> adjusters = null;
            List<LeadView> leads = null;

            predicate = buildPredicate();

            using (ClaimManager repository = new ClaimManager()) {
                leads = repository.Search(predicate).orderBy("ClaimantLastName").ToList();
            }

            gvSearchResult.DataSource = leads;
            gvSearchResult.DataBind();

            if (leads != null && leads.Count > 0) {
                pnlResult.Visible = true;
                pnlToolbar.Visible = true;

                // load adjusters
                adjusters = AdjusterManager.GetClaimAssigned(clientID);

                gvAdjusters.DataSource = adjusters;
                gvAdjusters.DataBind();

                CollectionManager.FillCollection(ddlAdjuster, "AdjusterID", "AdjusterName", adjusters);
            }
        }
        public List<LeadView> getLeadList()
        {
            List<LeadView> leadArr = new List<LeadView>();

            int myClaimID = SessionHelper.getClaimID();
            var predicate = buildPredicateList();

            using (ClaimManager repository = new ClaimManager())
            {
                leadArr = repository.Search(predicate);
            }

            return leadArr;
        }
        protected void gvUserLeads_Sorting(object sender, GridViewSortEventArgs e)
        {
            List<LeadView> results = null;
            bool descending = false;

            if (ViewState[e.SortExpression] == null)
                descending = false;
            else
                descending = !(bool)ViewState[e.SortExpression];

            ViewState[e.SortExpression] = descending;

            ViewState["lastSortExpression"] = e.SortExpression;
            ViewState["lastSortDirection"] = descending;

            Expression<Func<vw_Lead_Search, bool>> predicate = buildPredicate();

            using (ClaimManager repository = new ClaimManager())
            {
                results = repository.Search(predicate, e.SortExpression, descending);
            }

            gvUserLeads.DataSource = results;
            gvUserLeads.DataBind();
        }
        protected void gvUserLeads_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            List<LeadView> results = null;

            gvUserLeads.PageIndex = e.NewPageIndex;

            string sortExpression = ViewState["lastSortExpression"] == null ? "ClaimantLastName" : ViewState["lastSortExpression"].ToString();
            bool descending = ViewState["lastSortDirection"] == null ? false : (bool)ViewState["lastSortDirection"];

            Expression<Func<vw_Lead_Search, bool>> predicate = buildPredicate();

            using (ClaimManager repository = new ClaimManager())
            {
                results = repository.Search(predicate, sortExpression, descending);
            }

            gvUserLeads.DataSource = results;
            gvUserLeads.DataBind();
        }
        private void checkUserSearchFromMasterPage()
        {
            int adjustID = 0;
            AdjusterMaster adjuster = null;
            int carrierID = 0;
            int clientID = 0;
            int foundCount = 0;
            int userID = 0;
            string keyword = null;
            Expression<Func<vw_Lead_Search, bool>> predicate = null;
            CRM.Data.Entities.SecUser secUser = null;

            if (Request.Params["s"] != null)
            {
                keyword = Request.Params["s"].ToString();

                clientID = SessionHelper.getClientId();
                userID = SessionHelper.getUserId();

                predicate = PredicateBuilder.True<CRM.Data.Entities.vw_Lead_Search>();

                // mandatory filters

                //predicate = predicate.And(x => x.IsActive == true);		// active claims
                predicate = predicate.And(x => x.ClientID == clientID);	// client leads
                predicate = predicate.And(x => x.Status == 1);			// active lead
                //predicate = predicate.And(x => x.UserID != 0);			// user created lead

                predicate = predicate.And(x => x.AdjusterClaimNumber.Contains(keyword) ||
                                        x.ContractorName.Contains(keyword) ||
                                        x.AppraiserName.Contains(keyword) ||
                                        x.UmpireName.Contains(keyword) ||
                                        x.InsuredName.Contains(keyword) ||
                                        x.LossAddress.Contains(keyword) ||
                                        x.PolicyNumber.Contains(keyword) ||
                                        x.InsurerClaimNumber.Contains(keyword)||
                                        x.ProducerName.Contains(keyword));

                //if (DateTime.TryParse(keyword, out fromDate)) {
                //	//predicate = predicate.And(Lead => Lead.OriginalLeadDate >= txtDateFrom.Date);
                //	predicate = predicate.Or(x => x.LossDate >= fromDate);
                //}

                //if (DateTime.TryParse(keyword, out toDate)) {
                //	//predicate = predicate.And(Lead => Lead.OriginalLeadDate <= txtDateTo.Date);
                //	predicate = predicate.Or(x => x.LossDate <= toDate);
                //}

                switch (roleID)
                {
                    case (int)UserRole.Administrator:
                        break;

                    case (int)UserRole.Client:
                    case (int)UserRole.SiteAdministrator:
                        // 2014-03-11
                        //predicate = predicate.And(Lead => Lead.ClientID == clientID);
                        break;

                    case (int)UserRole.Adjuster:
                        // get all leads assigned to adjuster
                        adjuster = AdjusterManager.GetAdjusterByUserID(userID);

                        if (adjuster != null)
                        {
                            adjustID = adjuster.AdjusterId;

                            predicate = predicate.And(x => x.AdjusterId == adjustID);
                        }
                        else
                        {
                            predicate = predicate.And(x => x.UserId == userID);
                        }
                        break;

                    default:
                        // check account is related to carrier. if so, include those leads whose policy has been assinged this carrier
                        secUser = SecUserManager.GetById(userID);
                        if (secUser != null && secUser.CarrierID != null)
                        {
                            carrierID = secUser.CarrierID ?? 0;
                            predicate = predicate.And(x => x.CarrierID == carrierID);
                        }
                        else if (secUser.isViewAllClaims ?? false)
                        {
                            // allow user to see all claims
                        }
                        else
                        {
                            // get all leads created by user
                            predicate = predicate.And(x => x.UserId == userID);
                        }
                        break;
                }

                // do search
                using (ClaimManager repository = new ClaimManager())
                {
                    objLead = repository.Search(predicate);
                }

                if (objLead != null && objLead.Count > 0)
                {
                    pnlSearchResult.Visible = true;

                    foundCount = objLead.Count;

                    customizeFieldColumns(gvUserLeads);
                }

                gvUserLeads.DataSource = objLead;
                gvUserLeads.DataBind();

                lblSearchResult.Text = string.Format("{0} claims found.", objLead.Count);
                lblSearchResult.Visible = true;

                //updateDashboard();
            }
        }
        private int bindLeads()
        {
            //gonna have to add something here that says if user role is adjuster, do something different - OC9/4/14
            int resultCount = 0;
            int myClaimID = SessionHelper.getClaimID();
            var predicate = buildPredicate();

            using (ClaimManager repository = new ClaimManager())
            {
                objLead = repository.Search(predicate);
            }

            if (objLead != null && objLead.Count > 0)
            {
                pnlSearchResult.Visible = true;

                gvUserLeads.DataSource = objLead;
                gvUserLeads.DataBind();

                resultCount = objLead.Count;
            }
            else
            {
                gvUserLeads.DataSource = null;
                gvUserLeads.DataBind();
            }

            lblSearchResult.Text = string.Format("{0} claims found.", resultCount);
            lblSearchResult.Visible = true;

            customizeFieldColumns(gvUserLeads);

            updateDashboard();

            return resultCount;
        }