Esempio n. 1
0
        private void SendLightboxToUser(Lightbox lightbox, User user, string recipient, string subject, string message, DateTime?expiryDate, bool?downloadLinks, bool?linked, bool?editable)
        {
            m_Logger.Debug("SendLightboxToUser - start");

            int?createdLightboxId = null;
            int?linkedLightboxId  = null;

            if (!user.IsNull)
            {
                //check to see if should link the lightbox or
                //make a new copy of it
                if (linked.GetValueOrDefault(false))
                {
                    // create new linked lightbox
                    LightboxLinked linkedLightbox = LightboxLinked.New();
                    linkedLightbox.UserId     = user.UserId.GetValueOrDefault();
                    linkedLightbox.LightboxId = lightbox.LightboxId.GetValueOrDefault();
                    linkedLightbox.IsEditable = editable;
                    linkedLightbox.ExpiryDate = expiryDate;
                    LightboxLinked.Update(linkedLightbox);

                    linkedLightboxId = linkedLightbox.LightboxLinkedId;
                }
                else
                {
                    // copying lightbox
                    string lightboxName    = lightbox.Name;
                    string newLightboxName = GetLightboxNameForSending(lightboxName);

                    Lightbox createdLightbox = DuplicateLightbox(lightbox.LightboxId.GetValueOrDefault(), newLightboxName, user.UserId.GetValueOrDefault());
                    createdLightboxId = createdLightbox.LightboxId.GetValueOrDefault();
                }
            }

            LightboxSent lbs = LightboxSent.New();

            lbs.LightboxId        = lightbox.LightboxId.GetValueOrDefault();
            lbs.CreatedLightboxId = createdLightboxId;
            lbs.SenderId          = User.UserId.GetValueOrDefault();
            lbs.RecipientEmail    = recipient;
            lbs.Subject           = subject;
            lbs.Message           = message;
            lbs.DateSent          = DateTime.Now;
            lbs.ExpiryDate        = expiryDate;
            lbs.DownloadLinks     = downloadLinks;
            lbs.LightboxLinkedId  = linkedLightboxId;


            if (lbs.RecipientEmail.Length > 150)
            {
                throw new SystemException("Recipient email cannot exceed 150 characters");
            }

            if (lbs.Subject.Length > 150)
            {
                throw new SystemException("Subject cannot exceed 150 characters");
            }

            if (lbs.Message.Length > 500)
            {
                throw new SystemException("Message cannot exceed 500 characters");
            }
            LightboxSent.Update(lbs);

            if (LightboxSentToUser != null)
            {
                LightboxSentToUser(this, new LightboxSentEventArgs(lbs));
            }

            AuditLogManager.LogUserAction(User, AuditUserAction.SendLightbox, string.Format("Sent LightboxId: {0} to: {1}", lightbox.LightboxId, recipient));

            m_Logger.Debug("SendLightboxToUser - end");
        }