Exemplo n.º 1
0
        protected void AddNote_Click(object sender, EventArgs e)
        {
            if (QuoteToEdit == null || (QuoteToEdit.Entity.GetAttributeValue <EntityReference>("customerid") != null && !QuoteToEdit.Entity.GetAttributeValue <EntityReference>("customerid").Equals(Contact.ToEntityReference())))
            {
                throw new InvalidOperationException("Unable to retrieve quote.");
            }

            if (!string.IsNullOrEmpty(NewNoteText.Text) || (NewNoteAttachment.PostedFile != null && NewNoteAttachment.PostedFile.ContentLength > 0))
            {
                var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(
                    requestContext: Request.RequestContext, portalName: PortalName);

                var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies);

                var annotation = new Annotation
                {
                    NoteText  = string.Format("{0}{1}", AnnotationHelper.WebAnnotationPrefix, NewNoteText.Text),
                    Subject   = AnnotationHelper.BuildNoteSubject(dataAdapterDependencies),
                    Regarding = QuoteToEdit.Entity.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);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RedirectToLoginIfAnonymous();

            var quoteToEditEntity = QuoteToEdit != null ? QuoteToEdit.Entity : null;

            if (quoteToEditEntity == null || (quoteToEditEntity.GetAttributeValue <EntityReference>("customerid") != null && !quoteToEditEntity.GetAttributeValue <EntityReference>("customerid").Equals(Contact.ToEntityReference())))
            {
                PageBreadcrumbs.Visible  = true;
                GenericError.Visible     = true;
                QuoteHeader.Visible      = false;
                QuoteDetails.Visible     = false;
                QuoteInfo.Visible        = false;
                QuoteBreadcrumbs.Visible = false;
                QuoteHeader.Visible      = false;

                return;
            }

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

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

            var quoteState = quoteToEditEntity.GetAttributeValue <OptionSetValue>("statecode");

            ConvertToOrder.Visible = quoteState != null &&
                                     (quoteState.Value == (int)Enums.QuoteState.Active || quoteState.Value == (int)Enums.QuoteState.Won);

            var formViewDataSource = new CrmDataSource {
                ID = "WebFormDataSource", CrmDataContextName = FormView.ContextName
            };

            var fetchXml = string.Format("<fetch mapping='logical'><entity name='{0}'><all-attributes /><filter type='and'><condition attribute = '{1}' operator='eq' value='{{{2}}}'/></filter></entity></fetch>", "quote", "quoteid", QuoteToEdit.Id);

            formViewDataSource.FetchXml = fetchXml;

            QuoteForm.Controls.Add(formViewDataSource);

            FormView.DataSourceID = "WebFormDataSource";

            var baseCartReference = quoteToEditEntity.GetAttributeValue <EntityReference>("adx_shoppingcartid");

            var baseCart = (baseCartReference != null) ? ServiceContext.CreateQuery("adx_shoppingcart").FirstOrDefault(sc => sc.GetAttributeValue <Guid>("adx_shoppingcartid") == baseCartReference.Id)
                                : null;

            var cartRecord = baseCart == null ? null : new ShoppingCart(baseCart, XrmContext);

            if (cartRecord == null)
            {
                ShoppingCartSummary.Visible = false;

                return;
            }

            var cartItems = cartRecord.GetCartItems().Select(sci => sci.Entity);

            if (!cartItems.Any())
            {
                ShoppingCartSummary.Visible = false;

                return;
            }

            CartRepeater.DataSource = cartItems;
            CartRepeater.DataBind();

            Total.Text = cartRecord.GetCartTotal().ToString("C2");
        }