Ejemplo n.º 1
0
        protected void AddNote_Click(object sender, EventArgs e)
        {
            var regardingContact = ServiceRequest.GetAttributeValue <EntityReference>(RegardingContactFieldName);

            if (regardingContact == null || Contact == null || regardingContact.Id != Contact.Id)
            {
                throw new InvalidOperationException("Unable to retrieve order.");
            }

            var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(
                requestContext: Request.RequestContext, portalName: PortalName);
            var serviceContext = dataAdapterDependencies.GetServiceContext();

            var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies);

            if (NewNotePublic.Checked)
            {
                if (!string.IsNullOrEmpty(NewNoteText.Text) || (NewNoteAttachment.PostedFile != null && NewNoteAttachment.PostedFile.ContentLength > 0))
                {
                    var annotation = new Annotation
                    {
                        NoteText  = string.Format("{0}{1}", AnnotationHelper.PublicAnnotationPrefix, NewNoteText.Text),
                        Subject   = AnnotationHelper.BuildNoteSubject(dataAdapterDependencies),
                        Regarding = ServiceRequest.ToEntityReference()
                    };
                    if (NewNoteAttachment.PostedFile != null && NewNoteAttachment.PostedFile.ContentLength > 0)
                    {
                        annotation.FileAttachment = AnnotationDataAdapter.CreateFileAttachment(new HttpPostedFileWrapper(NewNoteAttachment.PostedFile));
                    }
                    dataAdapter.CreateAnnotation(annotation);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(NewNoteText.Text) ||
                    (NewNoteAttachment.PostedFile != null && NewNoteAttachment.PostedFile.ContentLength > 0))
                {
                    var annotation = new Annotation
                    {
                        NoteText  = string.Format("{0}{1}", AnnotationHelper.WebAnnotationPrefix, NewNoteText.Text),
                        Subject   = AnnotationHelper.BuildNoteSubject(dataAdapterDependencies),
                        Regarding = ServiceRequest.ToEntityReference()
                    };
                    if (NewNoteAttachment.PostedFile != null && NewNoteAttachment.PostedFile.ContentLength > 0)
                    {
                        annotation.FileAttachment = AnnotationDataAdapter.CreateFileAttachment(new HttpPostedFileWrapper(NewNoteAttachment.PostedFile));
                    }
                    dataAdapter.CreateAnnotation(annotation);
                }
            }

            Response.Redirect(Request.Url.PathAndQuery);
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ServiceRequestRollupRecord != null)
            {
                var serviceRequestTypeReference =
                    ServiceRequestRollupRecord.GetAttributeValue <EntityReference>("adx_servicerequesttype");

                var serviceRequestType =
                    XrmContext.CreateQuery("adx_servicerequesttype").FirstOrDefault(
                        srt => srt.GetAttributeValue <Guid>("adx_servicerequesttypeid") == serviceRequestTypeReference.Id);

                var entityName = serviceRequestType.GetAttributeValue <string>("adx_entityname");

                RegardingContactFieldName = serviceRequestType.GetAttributeValue <string>("adx_regardingcontactfieldname");

                var trueMetadataRequest = new RetrieveEntityRequest
                {
                    LogicalName   = entityName,
                    EntityFilters = EntityFilters.Attributes
                };

                var trueMetadataResponse = (RetrieveEntityResponse)XrmContext.Execute(trueMetadataRequest);

                var primaryFieldName = trueMetadataResponse.EntityMetadata.PrimaryIdAttribute;

                var entityId = ServiceRequestRollupRecord.GetAttributeValue <string>("adx_entityid");

                var trueRecordId = Guid.Parse(entityId);

                var trueRecord =
                    XrmContext.CreateQuery(entityName).FirstOrDefault(r => r.GetAttributeValue <Guid>(primaryFieldName) == trueRecordId);

                ServiceRequest = trueRecord;



                var regardingContact = ServiceRequest.GetAttributeValue <EntityReference>(RegardingContactFieldName);

                if (regardingContact == null || Contact == null || regardingContact.Id != Contact.Id)
                {
                    AddANote.Enabled      = false;
                    AddANote.Visible      = false;
                    AddNoteInline.Visible = false;
                    AddNoteInline.Enabled = false;

                    RenderCrmEntityFormView(entityName, primaryFieldName, trueRecordId, FormViewMode.ReadOnly);

                    var dataAdapterDependencies =
                        new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: PortalName);
                    var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies);
                    var annotations = dataAdapter.GetAnnotations(ServiceRequest.ToEntityReference(),
                                                                 new List <Order> {
                        new Order("createdon")
                    });

                    if (!annotations.Any())
                    {
                        NotesLabel.Visible = false;
                        NotesList.Visible  = false;
                    }

                    NotesList.DataSource = annotations;
                    NotesList.DataBind();
                }
                else
                {
                    RenderCrmEntityFormView(entityName, primaryFieldName, trueRecordId, FormViewMode.Edit);

                    var dataAdapterDependencies =
                        new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: PortalName);
                    var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies);
                    var annotations = dataAdapter.GetAnnotations(ServiceRequest.ToEntityReference(),
                                                                 new List <Order> {
                        new Order("createdon")
                    },
                                                                 privacy: AnnotationPrivacy.Web | AnnotationPrivacy.Private | AnnotationPrivacy.Public);

                    NotesList.DataSource = annotations;
                    NotesList.DataBind();
                }

                if (Request.IsAuthenticated && Contact != null)
                {
                    var dataAdapter = CreateAlertDataAdapter();

                    var hasAlert = dataAdapter.HasAlert(Contact.ToEntityReference());

                    AddAlert.Visible    = !hasAlert;
                    RemoveAlert.Visible = hasAlert;
                }
                else
                {
                    AddAlertLoginLink.Visible = true;
                }

                DisplaySlaDetails(serviceRequestType);
            }
        }
Ejemplo n.º 3
0
 private IAlertSubscriptionDataAdapter CreateAlertDataAdapter()
 {
     return(new ActivityEnabledEntityDataAdapter(ServiceRequest.ToEntityReference(), new Adxstudio.Xrm.Cms.PortalContextDataAdapterDependencies(Portal, requestContext: Request.RequestContext)));
 }