示例#1
0
        protected void CustomerContactsList_Sorting(object sender, GridViewSortEventArgs e)
        {
            SortDirection = e.SortExpression == SortExpression ? (SortDirection == "ASC" ? "DESC" : "ASC") : "ASC";

            SortExpression = e.SortExpression;

            _contacts.DefaultView.Sort = string.Format("{0} {1}", SortExpression, SortDirection);

            CustomerContactsList.DataSource = _contacts;
            CustomerContactsList.DataBind();
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RedirectToLoginIfAnonymous();

            var channelPermission               = ServiceContext.GetChannelAccessByContact(Contact);
            var channelCreateAccess             = (channelPermission != null && channelPermission.GetAttributeValue <bool?>("adx_create").GetValueOrDefault(false));
            var channelWriteAccess              = (channelPermission != null && channelPermission.GetAttributeValue <bool?>("adx_write").GetValueOrDefault(false));
            var channelReadAccess               = (channelPermission != null && channelPermission.GetAttributeValue <bool?>("adx_read").GetValueOrDefault(false));
            var parentCustomerAccount           = Contact.GetAttributeValue <EntityReference>("parentcustomerid") == null ? null : ServiceContext.CreateQuery("account").FirstOrDefault(a => a.GetAttributeValue <Guid>("accountid") == Contact.GetAttributeValue <EntityReference>("parentcustomerid").Id);
            var validAcccountClassificationCode = parentCustomerAccount != null && parentCustomerAccount.GetAttributeValue <OptionSetValue>("accountclassificationcode") != null && parentCustomerAccount.GetAttributeValue <OptionSetValue>("accountclassificationcode").Value == (int)Enums.AccountClassificationCode.Partner;

            if (channelPermission == null)
            {
                NoChannelPermissionsRecordError.Visible = true;

                ContactsList.Visible = false;

                return;
            }

            if (!channelReadAccess && !channelWriteAccess)
            {
                ChannelPermissionsError.Visible = true;
            }
            else
            {
                if (parentCustomerAccount == null)
                {
                    NoParentAccountError.Visible = true;
                }
                else
                {
                    ParentAccountClassificationCodeError.Visible = !validAcccountClassificationCode;
                }
            }

            if ((!channelReadAccess && !channelWriteAccess) || parentCustomerAccount == null || !validAcccountClassificationCode)
            {
                ContactsList.Visible = false;

                return;
            }

            CreateButton.Visible = channelCreateAccess;

            if (!IsPostBack)
            {
                PopulateCustomerFilter();
            }

            var contacts = new List <Entity>();

            if (string.Equals(CustomerFilter.Text, "All", StringComparison.InvariantCulture))
            {
                var myContacts = ServiceContext.CreateQuery("contact").Where(c => c.GetAttributeValue <EntityReference>("msa_managingpartnerid") == parentCustomerAccount.ToEntityReference());

                contacts.AddRange(myContacts);

                var accounts = ServiceContext.CreateQuery("account").Where(a => a.GetAttributeValue <EntityReference>("msa_managingpartnerid") == parentCustomerAccount.ToEntityReference()).ToList();

                if (accounts.Any())
                {
                    foreach (var account in accounts)
                    {
                        var currentContacts =
                            ServiceContext.CreateQuery("contact")
                            .Where(
                                c =>
                                (c.GetAttributeValue <EntityReference>("msa_managingpartnerid") == null ||
                                 (c.GetAttributeValue <EntityReference>("msa_managingpartnerid") != null &&
                                  !c.GetAttributeValue <EntityReference>("msa_managingpartnerid").Equals(parentCustomerAccount.ToEntityReference()))) &&
                                c.GetAttributeValue <EntityReference>("parentcustomerid") != null &&
                                c.GetAttributeValue <EntityReference>("parentcustomerid").Equals(account.ToEntityReference()));

                        contacts.AddRange(currentContacts);
                    }
                }
            }
            else if (string.Equals(CustomerFilter.Text, "My", StringComparison.InvariantCulture))
            {
                var currentContacts =
                    ServiceContext.CreateQuery("contact")
                    .Where(
                        c =>
                        c.GetAttributeValue <EntityReference>("parentcustomerid") == null &&
                        (c.GetAttributeValue <EntityReference>("msa_managingpartnerid") != null &&
                         c.GetAttributeValue <EntityReference>("msa_managingpartnerid").Equals(parentCustomerAccount.ToEntityReference())));

                contacts.AddRange(currentContacts);
            }
            else
            {
                Guid accountid;

                if (Guid.TryParse(CustomerFilter.SelectedValue, out accountid))
                {
                    var currentContacts =
                        ServiceContext.CreateQuery("contact")
                        .Where(
                            c =>
                            c.GetAttributeValue <EntityReference>("parentcustomerid") != null &&
                            c.GetAttributeValue <EntityReference>("parentcustomerid").Equals(new EntityReference("account", accountid)));

                    contacts.AddRange(currentContacts);
                }
            }

            _contacts = EnumerableExtensions.CopyToDataTable(contacts.Select(c => new
            {
                contactid   = c.GetAttributeValue <Guid>("contactid"),
                ID          = c.GetAttributeValue <string>("fullname"),
                CompanyName = c.GetRelatedEntity(ServiceContext, new Relationship("contact_customer_accounts")) == null ? string.Empty : c.GetRelatedEntity(ServiceContext, new Relationship("contact_customer_accounts")).GetAttributeValue <string>("name"),
                City        = c.GetAttributeValue <string>("address1_city"),
                State       = c.GetAttributeValue <string>("address1_stateorprovince"),
                Phone       = c.GetAttributeValue <string>("address1_telephone1"),
                Email       = c.GetAttributeValue <string>("emailaddress1"),
            }));

            _contacts.Columns["City"].ColumnName  = "City";
            _contacts.Columns["State"].ColumnName = "State";
            _contacts.Columns["Phone"].ColumnName = "Phone";
            _contacts.Columns["Email"].ColumnName = "E-mail Address";

            CustomerContactsList.DataKeyNames = new[] { "contactid" };
            CustomerContactsList.DataSource   = _contacts;
            CustomerContactsList.DataBind();

            Guid id;

            if (CustomerFilter.SelectedItem != null && Guid.TryParse(CustomerFilter.SelectedItem.Value, out id))
            {
                CreateButton.QueryStringCollection = new QueryStringCollection("");

                CreateButton.QueryStringCollection.Set("AccountID", id.ToString());
            }
        }