public string GetContactSource(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null)
            {
                return(CetLocalizedContactSource(contact.ContactSource));
            }

            return("");
        }
        public string GetDateCrated(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null && contact.CreatedDate.HasValue)
            {
                return(CetLocalizedDateCreated(contact.CreatedDate.Value));
            }

            return("");
        }
        public string GetCity(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null)
            {
                return(contact.City);
            }

            return("");
        }
        public string GetState(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null && !String.IsNullOrEmpty(contact.State))
            {
                return(contact.State);
            }

            return("");
        }
        protected string GetLastName(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null && contact.Name != null && !String.IsNullOrEmpty(contact.Name.Last))
            {
                return(contact.Name.Last);
            }

            return("");
        }
        protected string GetFirstName(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null)
            {
                return(contact.Name.First);
            }

            return("");
        }
        public void SetListDelete()
        {
            List <Contact_V03> ListDelete = new List <Contact_V03>();
            List <Contact_V03> MyContacts = new List <Contact_V03>();

            MyContacts = (List <Contact_V03>)Session["MyContacts"];
            if (Session["ListDelete"] != null)
            {
                ListDelete = (List <Contact_V03>)Session["ListDelete"];
            }

            foreach (GridDataItem grdItem in ContactsRadGrid.Items)
            {
                CheckBox selectCheckBox = (CheckBox)(grdItem.FindControl("SelectorCheckBox"));

                if (null != selectCheckBox && selectCheckBox.Checked)
                {
                    if (MyContacts != null)
                    {
                        foreach (Contact_V03 ContactItems in MyContacts)
                        {
                            if (ContactItems.ContactID == int.Parse(grdItem.GetDataKeyValue("ContactID").ToString()))
                            {
                                if (!ListDelete.Contains(ContactItems))
                                {
                                    ListDelete.Add(ContactItems);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Contact_V03 deleteItem = new Contact_V03();
                    foreach (Contact_V03 ContactItems in ListDelete)
                    {
                        if (ContactItems.ContactID == int.Parse(grdItem.GetDataKeyValue("ContactID").ToString()))
                        {
                            deleteItem = ContactItems;
                        }
                    }
                    ListDelete.Remove(deleteItem);
                }
            }
            selectedResult.Value      = ListDelete.Count.ToString();
            selectedSpan.InnerHtml    = selectedResult.Value.Replace("-", "");
            selectedSpanBot.InnerHtml = selectedResult.Value.Replace("-", "");
            totalSpan.InnerHtml       = totalResults.Value.Replace("-", "");
            totalSpanBot.InnerHtml    = totalResults.Value.Replace("-", "").Replace("-", "");
            Session["ListDelete"]     = ListDelete;
        }
        public string GetEmail(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.PrimaryEmailAddress))
                {
                    return(contact.PrimaryEmailAddress);
                }
            }

            return("");
        }
        public string GetSecondaryPhone(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.MobilePhoneNumber))
                {
                    return(contact.MobilePhoneNumber);
                }
            }

            return("");
        }
        private int sort(Contact_V03 a, Contact_V03 b, string fieldName)
        {
            switch (fieldName)
            {
            case "Fullname":
            case "FullnameNotLinked":
                return(Compare(GetFullName(a), GetFullName(b)));

            case "LastName":
                return(Compare(GetLastName(a), GetLastName(b)));

            case "LastName FirstName":

                if (string.IsNullOrEmpty(GetLastName(a)) && string.IsNullOrEmpty(GetLastName(b)))
                {
                    return(Compare(GetFirstName(a), GetFirstName(b)));
                }
                else
                {
                    return(Compare(GetLastName(a), GetLastName(b)));
                }

            case "ContactSource":
                return(Compare(GetContactSource(a), GetContactSource(b)));

            case "CreateDate":
                return(Compare(a.CreatedDate, b.CreatedDate));

            case "Phone":
                return(Compare(GetPhone(a), GetPhone(b)));

            case "Email":
            case "EmailNotLinked":
                return(Compare(GetEmail(a), GetEmail(b)));

            case "City":
                return(Compare(GetCity(a), GetCity(b)));

            case "State":
                return(Compare(GetState(a), GetState(b)));

            case "ContactType":
                return(Compare(GetContactType(a), GetContactType(b)));

            default:
                return(0);
            }
        }
        protected string GetFullLocalName(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            if (contact != null && contact.LocalName != null)
            {
                string fullLocalName = string.Format("{0} {1}", contact.LocalName.First, contact.LocalName.Last);

                if (fullLocalName.Trim() != string.Empty)
                {
                    return(String.Format(@"<br/> <span class='local-name'>({0})</span>", fullLocalName));
                }
            }

            return("");
        }
        public string GetAddressLines(object dataItem)
        {
            Contact_V03   contact = dataItem as Contact_V03;
            StringBuilder address = new StringBuilder();

            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.StreetAddress1))
                {
                    address.AppendFormat("{0}<br/>", contact.StreetAddress1.Trim());
                }
                if (!String.IsNullOrEmpty(contact.StreetAddress2))
                {
                    address.AppendFormat("{0}<br/>", contact.StreetAddress2.Trim());
                }

                string s = String.Format("{0} {1} {2}",
                                         contact.City,
                                         contact.State,
                                         contact.Zip).Trim();

                string countryName = null;
                try
                {
                    countryName = HL.Common.ValueObjects.CountryType.Parse(contact.Country).Name;
                }
                catch { }
                if (!string.IsNullOrEmpty(countryName))
                {
                    s = s + "<br/>" + countryName;
                }

                if (!String.IsNullOrEmpty(s))
                {
                    address.AppendFormat("{0}<br/>", s);
                }

                if (!String.IsNullOrEmpty(address.ToString().Trim()))
                {
                    return(String.Format("<div class='address-lines-div'>{0}</div>", address.ToString()));
                }
            }

            return("");
        }
        protected void ContactsRadGrid_ItemDataBound(object source, GridItemEventArgs e)
        {
            switch (e.Item.ItemType)
            {
            case GridItemType.Header:
                CheckBox selectAllCheckBox = (CheckBox)(e.Item.Cells[3].FindControl("SelectAllList"));;
                if (null != selectAllCheckBox)
                {
                    selectAllCheckBox.Checked = IsSelectAllChecked() && selectedSpan.InnerHtml == totalSpan.InnerHtml && selVal.Value == string.Empty ? true : false;
                }
                break;

            case GridItemType.AlternatingItem:
            case GridItemType.Item:
                Contact_V03 contact            = e.Item.DataItem as Contact_V03;
                LinkButton  lnkEmailColumn     = e.Item.FindControl("lnkEmailColumn") as LinkButton;
                Label       lblEmailLinkColumn = e.Item.FindControl("lblEmailLinkColumn") as Label;
                LinkButton  lnkInvite          = e.Item.FindControl("lnkInvite") as LinkButton;
                if (contact.PrimaryEmailInfo.OptoutDate != null && contact.PrimaryEmailInfo.OptoutDate <= DateTime.Now.ToUniversalTime())
                {
                    lnkEmailColumn.Visible     = false;
                    lblEmailLinkColumn.Visible = true;
                    // if last invite date is greater than 6 months
                    lnkInvite.Visible = contact.PrimaryEmailInfo.LastInviteDate == null || Convert.ToDateTime(contact.PrimaryEmailInfo.LastInviteDate).AddDays(60) <= DateTime.Now.ToUniversalTime() ? true : false;
                }
                else
                {
                    lnkInvite.Visible          = false;
                    lnkEmailColumn.Visible     = true;
                    lblEmailLinkColumn.Visible = false;
                }
                break;

            case GridItemType.Pager:

                break;
            }
        }
        protected int GetID(object dataItem)
        {
            Contact_V03 contact = dataItem as Contact_V03;

            return(contact.ContactID);
        }