示例#1
0
        protected void OnItemUpdated(object sender, CrmEntityFormViewUpdatedEventArgs e)
        {
            if (e.Entity != null)
            {
                ParatureSyncContactCustomer(e.Entity.Id);
            }

            ConfirmationMessage.Visible = true;
        }
示例#2
0
 protected void OnItemUpdated(object sender, CrmEntityFormViewUpdatedEventArgs e)
 {
     SuccessMessage.Visible = true;
 }
        protected void OpportunityUpdated(object sender, CrmEntityFormViewUpdatedEventArgs e)
        {
            var context = PortalCrmConfigurationManager.CreateServiceContext();

            var opportunity = context.CreateQuery("opportunity").First(o => o.GetAttributeValue <Guid>("opportunityid") == e.Entity.Id);

            var partnerReference = opportunity.GetAttributeValue <EntityReference>("msa_partnerid");

            if (partnerReference == null)
            {
                return;
            }

            var partner = context.CreateQuery("account").First(p => p.GetAttributeValue <Guid>("accountid") == partnerReference.Id);

            if (partner.GetAttributeValue <int?>("adx_numberofopportunitiesaccepted").GetValueOrDefault(0) == 0)
            {
                partner.SetAttributeValue("adx_numberofopportunitiesaccepted", 1);
            }

            var oppnote      = new Entity("adx_opportunitynote");
            var oppnote2     = new Entity("adx_opportunitynote");
            var feedbackrate = (double)(partner.GetAttributeValue <int?>("adx_numberofopportunitieswithfeedback").GetValueOrDefault(0)) / (partner.GetAttributeValue <int?>("adx_numberofopportunitiesaccepted").GetValueOrDefault(1));

            if (UpdatePipelinePhase.Checked)
            {
                context.SetOpportunityStatusAndSave(opportunity, "Open", 0);
                opportunity.SetAttributeValue("statuscode", new OptionSetValue((int)Adxstudio.Xrm.Partner.Enums.OpportunityStatusReason.InProgress));
                if (!opportunity.GetAttributeValue <bool?>("adx_feedbackyet").GetValueOrDefault(false))
                {
                    if (!(opportunity.GetAttributeValue <bool?>("adx_partnercreated").GetValueOrDefault(false)))
                    {
                        partner.SetAttributeValue("adx_numberofopportunitieswithfeedback", partner.GetAttributeValue <int?>("adx_numberofopportunitieswithfeedback").GetValueOrDefault(0) + 1);
                        partner.SetAttributeValue("adx_feedbackrate", feedbackrate);
                        opportunity.SetAttributeValue("adx_feedbackyet", true);
                    }
                }

                oppnote.SetAttributeValue("adx_name", PipelinePhase.SelectedItem.Text);
                oppnote.SetAttributeValue("adx_date", DateTime.UtcNow);
                oppnote.SetAttributeValue("adx_description", PipelineUpdateDetails.Text);
            }
            else if (WinOpportunity.Checked)
            {
                context.SetOpportunityStatusAndSave(opportunity, "Won", 0);
                opportunity.SetAttributeValue("statuscode", new OptionSetValue((int)Adxstudio.Xrm.Partner.Enums.OpportunityStatusReason.Purchased));
                if (!opportunity.GetAttributeValue <bool?>("adx_feedbackyet").GetValueOrDefault(false))
                {
                    if (!(opportunity.GetAttributeValue <bool?>("adx_partnercreated").GetValueOrDefault(false)))
                    {
                        partner.SetAttributeValue("adx_numberofopportunitieswithfeedback", partner.GetAttributeValue <int?>("adx_numberofopportunitieswithfeedback").GetValueOrDefault(0) + 1);
                        partner.SetAttributeValue("adx_feedbackrate", feedbackrate);
                        opportunity.SetAttributeValue("adx_feedbackyet", true);
                    }
                }

                opportunity.SetAttributeValue("adx_wondate", DateTime.UtcNow);
                var wonSetting = XrmContext.CreateQuery("adx_sitesetting").FirstOrDefault(ss => ss.GetAttributeValue <string>("adx_name") == "Won Opportunity Note");
                var wonNote    = "Won";
                wonNote = (wonSetting != null) ? wonSetting.GetAttributeValue <string>("adx_value") : wonNote;

                oppnote.SetAttributeValue("adx_name", wonNote);
                oppnote.SetAttributeValue("adx_date", DateTime.UtcNow);
                oppnote.SetAttributeValue("adx_description", WonDetails.Text);
            }
            else if (CancelOpportunity.Checked)
            {
                context.SetOpportunityStatusAndSave(opportunity, "Lost", 0);
                opportunity.SetAttributeValue("statuscode", new OptionSetValue((int)Adxstudio.Xrm.Partner.Enums.OpportunityStatusReason.Canceled));
                if (!opportunity.GetAttributeValue <bool?>("adx_feedbackyet").GetValueOrDefault(false))
                {
                    if (!(opportunity.GetAttributeValue <bool?>("adx_partnercreated").GetValueOrDefault(false)))
                    {
                        partner.SetAttributeValue("adx_numberofopportunitieswithfeedback", partner.GetAttributeValue <int?>("adx_numberofopportunitieswithfeedback").GetValueOrDefault(0) + 1);
                        partner.SetAttributeValue("adx_feedbackrate", feedbackrate);
                        opportunity.SetAttributeValue("adx_feedbackyet", true);
                    }
                }

                var cancelSetting = XrmContext.CreateQuery("adx_sitesetting").FirstOrDefault(ss => ss.GetAttributeValue <string>("adx_name") == "Cancel Opportunity Note");
                var cancelNote    = "Canceled";
                cancelNote = (cancelSetting != null) ? cancelSetting.GetAttributeValue <string>("adx_value") : cancelNote;

                oppnote.SetAttributeValue("adx_name", cancelNote);
                oppnote.SetAttributeValue("adx_date", DateTime.UtcNow);
                oppnote.SetAttributeValue("adx_description", CancelDetails.Text);
            }
            else if (AddContactCheckBox.Checked)
            {
                var selectedGuid = new Guid(AddContactList.SelectedItem.Value);

                var contact = context.CreateQuery("contact").FirstOrDefault(c => c.GetAttributeValue <Guid>("contactid") == selectedGuid);

                var contactCrossover = opportunity.GetRelatedEntities(context, new Relationship("adx_opportunity_contact")).FirstOrDefault(c => c.GetAttributeValue <Guid>("contactid") == contact.GetAttributeValue <Guid>("contactid"));

                if (contactCrossover == null)
                {
                    context.AddLink(opportunity, new Relationship("adx_opportunity_contact"), contact);

                    oppnote2.SetAttributeValue("adx_name", "Contact Added: " + contact.GetAttributeValue <string>("fullname"));
                    oppnote2.SetAttributeValue("adx_date", DateTime.UtcNow);
                    oppnote2.SetAttributeValue("adx_description", "Contact Added: " + contact.GetAttributeValue <string>("fullname"));

                    context.UpdateObject(contact);
                }

                //var opportunity = OpenOpportunity;
            }
            else if (ReturnToNetwork.Checked)
            {
                context.SetOpportunityStatusAndSave(opportunity, "Lost", 0);
                opportunity.SetAttributeValue("statuscode", new OptionSetValue((int)Adxstudio.Xrm.Partner.Enums.OpportunityStatusReason.Returned));

                if (!(opportunity.GetAttributeValue <bool?>("adx_partnercreated").GetValueOrDefault(false)))
                {
                    partner.SetAttributeValue("adx_numberofreturnedopportunities", partner.GetAttributeValue <int?>("adx_numberofreturnedopportunities").GetValueOrDefault(0) + 1);
                    partner.SetAttributeValue("adx_returnrate", (double)partner.GetAttributeValue <int?>("adx_numberofreturnedopportunities").GetValueOrDefault(0) / (partner.GetAttributeValue <int?>("adx_numberofopportunitiesaccepted").GetValueOrDefault(1)));
                }

                var returnSetting = XrmContext.CreateQuery("adx_sitesetting").FirstOrDefault(ss => ss.GetAttributeValue <string>("adx_name") == "Return Opportunity Note");
                var returnNote    = "Returned to Network";
                returnNote = (returnSetting != null) ? returnSetting.GetAttributeValue <string>("adx_value") : returnNote;

                oppnote.SetAttributeValue("adx_name", returnNote);
                oppnote.SetAttributeValue("adx_date", DateTime.UtcNow);
                oppnote.SetAttributeValue("adx_description", ReasonForReturn.SelectedItem.Text);

                //add the OpportunityNote entity
            }

            var calculatePartnerDetailsAction = new Entity("adx_calculatepartnercapacityworkflowaction");

            calculatePartnerDetailsAction.SetAttributeValue("adx_accountid", partner.ToEntityReference());
            var assignedto = opportunity.GetRelatedEntity(context, new Relationship("msa_contact_opportunity"));

            if (!String.IsNullOrEmpty(oppnote.GetAttributeValue <string>("adx_name")))
            {
                oppnote.SetAttributeValue("adx_opportunityid", opportunity.ToEntityReference());
                oppnote.SetAttributeValue("adx_assignedto", assignedto != null ? assignedto.GetAttributeValue <string>("fullname") : string.Empty);
                context.AddObject(oppnote);
            }
            if (!String.IsNullOrEmpty(oppnote2.GetAttributeValue <string>("adx_name")))
            {
                oppnote2.SetAttributeValue("adx_opportunityid", opportunity.ToEntityReference());
                oppnote2.SetAttributeValue("adx_assignedto", assignedto != null ? assignedto.GetAttributeValue <string>("fullname") : string.Empty);
                context.AddObject(oppnote2);
            }
            var oppID = opportunity.Id;

            context.UpdateObject(partner);
            context.UpdateObject(opportunity);
            context.SaveChanges();

            if (!(opportunity.GetAttributeValue <bool?>("adx_partnercreated").GetValueOrDefault(false)))
            {
                context.AddObject(calculatePartnerDetailsAction);
            }

            context.SaveChanges();

            var opp = context.CreateQuery("opportunity").FirstOrDefault(o => o.GetAttributeValue <Guid>("opportunityid") == oppID);

            if (opp != null)
            {
                CurrentlyAssignedToLabel.Text = assignedto != null?assignedto.GetAttributeValue <string>("fullname") : string.Empty;

                PipelinePhaseText.Text = HttpUtility.HtmlEncode(opp.GetAttributeValue <string>("stepname"));
            }

            DisableControlsBasedOnPipelinePhaseAndAccessPermissions();

            BindPipelinePhaseDetails();

            GetLeadHistory();

            GetContactList();

            ConfirmationMessage.Visible = true;
        }
示例#4
0
 protected void ChannelPermissionsUpdated(object sender, CrmEntityFormViewUpdatedEventArgs e)
 {
     UpdateSuccessMessage.Visible = true;
 }
 protected void OnItemUpdated(object sender, CrmEntityFormViewUpdatedEventArgs e)
 {
     ConfirmationMessage.Visible = true;
 }