protected void CopyAllToCartLinkButton_Click(object sender, EventArgs e)
        {
            // Get the lightbox
            Lightbox lb = ContextInfo.LightboxManager.GetLightboxById(SelectedLightboxId);

            // Get the assets and add them to the cart
            foreach (Asset asset in lb.GetAssetList())
            {
                ContextInfo.CartManager.AddAssetToCart(asset.AssetId.GetValueOrDefault());
            }

            // Change offset to last page to show new assets
            PersistentLightboxCartInfo.CartOffSet = Int32.MaxValue;

            // Switch to cart view
            OpenPanel("cart", "open");

            if (LightboxAssetsCopiedToCart != null)
            {
                LightboxAssetsCopiedToCart(this, EventArgs.Empty);
            }
        }
Example #2
0
        /// <summary>
        /// Sends a lightbox to a user
        /// </summary>
        /// <param name="lightboxId">The ID of the lightbox to send</param>
        /// <param name="subject">The subject of the email</param>
        /// <param name="message">The message to include in the email</param>
        /// <param name="recipient">The email address of the recipient</param>
        /// <param name="cc">The email address of the CC recipient (optional)</param>
        /// <param name="expiryDate">The date which the lightbox should expire (if sent to a non-registered user)</param>
        /// <param name="downloadLinks"></param>
        public void SendLightbox(int lightboxId, string subject, string message, string recipient, string cc, DateTime?expiryDate, bool?downloadLinks, bool?linked, bool?editable)
        {
            ErrorList errors   = new ErrorList();
            Lightbox  lightbox = GetLightboxById(lightboxId);

            User recipientUser = User.Empty;


            if (lightbox.IsLinked && !lightbox.IsEditable)
            {
                errors.Add("you are not allowed to send this linked lightbox");
            }

            if (StringUtils.IsBlank(subject))
            {
                errors.Add("no subject entered");
            }

            if (subject.Length > 150)
            {
                errors.Add("subject length cannot exceed 150 characters");
            }

            if (!StringUtils.IsEmail(recipient))
            {
                errors.Add("no recipient email address entered");
            }
            else if (recipient.Length > 150)
            {
                errors.Add("recipient email address cannot exceed 150 characters");
            }
            else
            {
                recipientUser = User.GetByEmail(recipient);

                if (!recipientUser.IsNull)
                {
                    string errorMsg;
                    if (!ValidateLightboxSendForUser(recipientUser, lightbox, linked, out errorMsg))
                    {
                        errors.Add(errorMsg);
                    }
                }
            }

            //get collection of cc emails and associated user objects
            Dictionary <string, User> ccUsers = new Dictionary <string, User>();

            if (!StringUtils.IsBlank(cc))
            {
                //get valid email addresses from cc string (all lower case)
                string[] ccEmails;

                //SplitEmails returns false if there are any invalid
                //addresses contained in the cc string - currently no action
                //is taken
                StringUtils.SplitEmails(cc, out ccEmails);

                foreach (string address in ccEmails)
                {
                    //check that address has not been added already
                    //and that cc user is not the same as the main recipient
                    if (!ccUsers.ContainsKey(address))
                    {
                        //validate address
                        if (address == recipient.ToLower())
                        {
                            errors.Add("recipient and cc email cannot be the same");
                            break;
                        }
                        else if (cc.Length > 150)
                        {
                            errors.Add("cc email address cannot exceed 150 characters");
                            break;
                        }
                        else
                        {
                            //find if a registered user associated with the address
                            User user = User.GetByEmail(address);

                            if (!user.IsNull)
                            {
                                //registered user - make sure lightbox is valid to send to them
                                string errorMsg;
                                if (ValidateLightboxSendForUser(user, lightbox, linked, out errorMsg))
                                {
                                    ccUsers.Add(address, user);
                                }
                                else
                                {
                                    errors.Add(errorMsg);
                                }
                            }
                            else
                            {
                                //unregistered user
                                ccUsers.Add(address, User.Empty);
                            }
                        }
                    }
                }
            }


            if (ccUsers.Count > MaxNumberCCEmails)
            {
                errors.Add("exceeded maximum number of CC email addresses");
            }

            if (message.Length > 400)
            {
                errors.Add("message cannot be more than 400 characters");
            }

            if (expiryDate.HasValue && expiryDate.Value <= DateTime.Now.Date)
            {
                errors.Add("expiry date must be after today");
            }

            if (lightbox.GetAssetList().Count == 0)
            {
                errors.Add("cannot send empty lightbox");
            }

            if (lightbox.IsPublic && lightbox.UserId != User.UserId.GetValueOrDefault())
            {
                errors.Add("cannot send public lightbox");
            }

            // Drop out with error if any validation errors occured
            if (errors.Count > 0)
            {
                throw new InvalidLightboxException(errors);
            }

            // First send the lightbox to the recipient
            SendLightboxToUser(lightbox, recipientUser, recipient, subject, message, expiryDate, downloadLinks, linked, editable);

            // Then send it to the CC user, if one is specified
            foreach (KeyValuePair <string, User> user in ccUsers)
            {
                SendLightboxToUser(lightbox, user.Value, user.Key, subject, message, expiryDate, downloadLinks, linked, editable);
            }
        }