Example #1
0
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (!IsValid)
        {
            return;
        }

        msFile fi = new msFile();

        fi.Description = tbDescription.Text;
        fi.FileCabinet = targetFolder.FileCabinet;
        fi.FileFolder  = targetFolder.ID;

        switch (fuFile.State)
        {
        case FileUploadCoordinator.FileUploadState.NoFileSpecified:
            return;

        case FileUploadCoordinator.FileUploadState.NewFileSpecified:
            var f = new MemberSuiteFile();
            f.FileContents = fuFile.FileUpload.FileBytes;
            f.FileName     = fuFile.FileUpload.FileName;
            f.FileType     = fuFile.FileUpload.PostedFile.ContentType;
            fi["FileContents_Contents"] = f;
            break;
        }

        SaveObject(fi);

        GoTo("BrowseFileFolder.aspx?contextID=" + targetFolder.ID, string.Format("File '{0}' has been updated successfully.", fi.Name));
    }
Example #2
0
    protected void unbindResume()
    {
        //If there's no resume create a new one and default IsApproved to true
        if (targetResume == null)
        {
            targetResume = new msResume {
                IsApproved = true
            }
        }
        ;

        targetResume.Owner    = ConciergeAPI.CurrentEntity.ID;
        targetResume.Name     = tbName.Text;
        targetResume.IsActive = cbIsActive.Checked;

        if (fuUploadResume.HasFile)
        {
            targetResume.File = null;

            var file = new MemberSuiteFile
            {
                FileContents = fuUploadResume.FileBytes,
                FileName     = fuUploadResume.FileName,
                FileType     = fuUploadResume.FileName.EndsWith(".doc", StringComparison.CurrentCultureIgnoreCase) && fuUploadResume.PostedFile.ContentType == "application/octet-stream" ? "application/msword" : fuUploadResume.PostedFile.ContentType
            };

            targetResume["File_Contents"] = file;
        }
    }
    private MemberSuiteFile getImageFile()
    {
        if (!imageUpload.HasFile)
        {
            return(null);
        }

        MemoryStream stream = new MemoryStream(imageUpload.FileBytes);

        System.Drawing.Image image = Image.FromStream(stream);

        //Resize the image if required - perserve scale
        if (image.Width > 120 || image.Height > 120)
        {
            int     largerDimension = image.Width > image.Height ? image.Width : image.Height;
            decimal ratio           = largerDimension / 120m;            //Target size is 120x120 so this works for either dimension

            int thumbnailWidth  = Convert.ToInt32(image.Width / ratio);  //Explicit convert will round
            int thumbnailHeight = Convert.ToInt32(image.Height / ratio); //Explicit convert will round

            //Create a thumbnail to resize the image.  The delegate is not used and IntPtr.Zero is always required.
            //For more information see http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx
            Image resizedImage = image.GetThumbnailImage(thumbnailWidth, thumbnailHeight, () => false, IntPtr.Zero);

            //Replace the stream containing the original image with the resized image
            stream = new MemoryStream();
            resizedImage.Save(stream, image.RawFormat);
        }

        var result = new MemberSuiteFile
        {
            FileContents = stream.ToArray(),
            FileName     = imageUpload.FileName,
            FileType     = imageUpload.PostedFile.ContentType
        };

        return(result);
    }
Example #4
0
    protected void btnPlaceOrder_Click(object sender, EventArgs e)
    {
        const string ContentSuffix = "_Contents";

        if (!IsValid)
        {
            return;
        }

        lock (threadLock)
        {
            if (targetOrder == null)
            {
                Refresh();
                return;
            }

            targetOrder.Notes = tbNotesComments.Text;

            // add cross sell
            var csi = MultiStepWizards.PlaceAnOrder.CrossSellItems;
            if (csi != null && csi.Count > 0)
            {
                targetOrder.LineItems.AddRange(csi.FindAll(x => x.Quantity != 0)); // add any cross sell items
            }
            using (var api = GetServiceAPIProxy())
            {
                var msPayload = new List <MemberSuiteObject>();
                // Go over line items and generate payoads for all attachments realted fields.
                foreach (var lineItem in targetOrder.LineItems)
                {
                    // We're looking for _Content only. _Content has to be of MemberSuiteFile type.
                    var attachments = lineItem.Fields.Where(f => f.Key.EndsWith(ContentSuffix) && IsNonEmptyMemberSuiteFile(f.Value))
                                      .Select(c =>
                    {
                        var msf = (MemberSuiteFile)c.Value;
                        // Generate ID
                        var fileId = api.GenerateIdentifer("File").ResultValue;
                        // Create ms object...
                        var mso                     = new MemberSuiteObject();
                        mso.ClassType               = "File";
                        mso.Fields["ID"]            = fileId;
                        mso.Fields["FileContents"]  = msf.FileContents;
                        mso.Fields["Name"]          = msf.FileName;
                        mso.Fields["ContentLength"] = msf.FileContents.Length;

                        return(new { Key = c.Key.Replace(ContentSuffix, string.Empty), FileId = fileId, File = mso });
                    });

                    if (attachments.Count() > 0)
                    {
                        foreach (var a in attachments)
                        {
                            // JES product fullfillment logic expects an xml file to save.. Copy relevant values into MemberSuiteFile & serializer it to send to JES (MS-6424)
                            //
                            var ms = new MemberSuiteFile();
                            ms.FileName     = a.File.SafeGetValue <string>("Name");
                            ms.FileContents = a.File.SafeGetValue <byte[]>("FileContents");
                            ms.FileType     = a.File.SafeGetValue <string>("FileType"); //we don't currently have this


                            var xml = MemberSuite.SDK.Utilities.Xml.Serialize(ms);


                            lineItem.Options.Add(new NameValueStringPair {
                                Name = a.Key, Value = xml
                            });
                            // Add according ms file to payload.
                            msPayload.Add(a.File);
                        }
                    }
                }

                OrderPayload payload = MultiStepWizards.PlaceAnOrder.Payload;

                if (msPayload.Count() > 0)
                {
                    if (payload == null)
                    {
                        payload = new OrderPayload();
                    }

                    if (payload.ObjectsToSave == null)
                    {
                        payload.ObjectsToSave = new List <MemberSuiteObject>();
                    }

                    payload.ObjectsToSave.AddRange(msPayload);
                }

                if (targetOrder.Date == DateTime.MinValue)
                {
                    targetOrder.Date = DateTime.Now;
                }

                var processedOrderPacket = api.PreProcessOrder(targetOrder).ResultValue;
                cleanOrder       = processedOrderPacket.FinalizedOrder.ConvertTo <msOrder>();
                cleanOrder.Total = processedOrderPacket.Total;

                //if (string.IsNullOrWhiteSpace(cleanOrder.BillingEmailAddress))
                //    cleanOrder.BillingEmailAddress = CurrentUser.EmailAddress;

                if (MultiStepWizards.RegisterForEvent.IsSessionSwap)
                {
                    var swapResult = api.SwapSessions(
                        MultiStepWizards.RegisterForEvent.SwapRegistrationID,
                        MultiStepWizards.RegisterForEvent.SessionsToCancel,
                        cleanOrder);

                    if (!swapResult.Success)
                    {
                        QueueBannerError(swapResult.FirstErrorMessage);
                    }
                    else
                    {
                        QueueBannerMessage("Session updates complete.");
                    }

                    MultiStepWizards.RegisterForEvent.Clear();
                    GoTo(MultiStepWizards.PlaceAnOrder.OrderCompleteUrl ?? "OrderComplete.aspx");
                }

                var processInfo = api.ProcessOrder(cleanOrder, payload).ResultValue;


                // let's wait for the order
                var processStatus = OrderUtilities.WaitForOrderToComplete(api, processInfo);

                if (processStatus.Status == LongRunningTaskStatus.Failed)
                {
                    throw new ConciergeClientException(
                              MemberSuite.SDK.Concierge.ConciergeErrorCode.IllegalOperation,
                              processStatus.AdditionalInfo);
                }

                string url = MultiStepWizards.PlaceAnOrder.OrderCompleteUrl ?? "OrderComplete.aspx";
                if (url.Contains("?"))
                {
                    url += "&";
                }
                else
                {
                    url += "?";
                }


                targetOrder = null;

                // clear the cart
                if (isTransient)
                {
                    // clear out the items
                    if (MultiStepWizards.PlaceAnOrder.TransientShoppingCart != null)
                    {
                        MultiStepWizards.PlaceAnOrder.TransientShoppingCart.LineItems.Clear();
                    }

                    MultiStepWizards.PlaceAnOrder.TransientShoppingCart = null;
                }
                else
                {
                    MultiStepWizards.PlaceAnOrder.ShoppingCart       = null;
                    MultiStepWizards.PlaceAnOrder.RecentlyAddedItems = null;
                }

                MultiStepWizards.PlaceAnOrder.CrossSellItems = null;



                MultiStepWizards.PlaceAnOrder.EditOrderLineItem                    = null; // clear this out
                MultiStepWizards.PlaceAnOrder.EditOrderLineItemProductName         = null; // clear this out
                MultiStepWizards.PlaceAnOrder.EditOrderLineItemProductDemographics = null; // clear this out
                MultiStepWizards.PlaceAnOrder.OrderConfirmationPacket              = null;

                if (processStatus.Status == LongRunningTaskStatus.Running)
                {
                    // MS-5204. Don't create job posting here. If JES is down then, job posting will be created
                    // during order processing. Otherwise we'll endup with duplicate job postings.
                    // hack - let's save the job posting
                    //if (MultiStepWizards.PostAJob.JobPosting != null)
                    //    SaveObject(MultiStepWizards.PostAJob.JobPosting);

                    MultiStepWizards.PostAJob.JobPosting = null;

                    GoTo("OrderQueued.aspx");
                }

                var order = LoadObjectFromAPI <msOrder>(processStatus.WorkflowID);
                QueueBannerMessage(string.Format("Order #{0} was processed successfully.",
                                                 order.SafeGetValue <long>(
                                                     msLocallyIdentifiableAssociationDomainObject.FIELDS.LocalID)));

                url += "orderID=" + order.ID;

                if (!url.Contains("contextID="))
                {
                    url += "&contextID=" + order.ID;
                }

                GoTo(url);
            }
        }
    }