示例#1
0
        public ActionResult Settings(ViewSettings settings)
        {
            ActionResult result = new EmptyResult();

            try
            {
                this.EntityContext.TryAttach(this.ActiveUser);
                UserEngage engage = this.GetUserEngage(this.ActiveUser);

                this.ActiveUser.Email = settings.Email;
                engage.Unsubscribe    = settings.Engage.Unsubscribe;
                engage.Comment        = settings.Engage.Comment;
                engage.ComicCreate    = settings.Engage.ComicCreate;
                engage.ComicRemix     = settings.Engage.ComicRemix;

                this.EntityContext.SaveChanges();

                ViewSettings model = new ViewSettings(new ClientUserEngage(engage), this.ActiveUser.Email);
                model.Feedback = "Your changes have been saved.";

                result = this.View(model);
            }
            finally
            {
                this.EntityContext.TryDetach(this.ActiveUser);
            }
            return(result);
        }
示例#2
0
 public ClientUserEngage(UserEngage engage)
 {
     this.Uid         = engage.Uid;
     this.Comment     = engage.Comment;
     this.ComicCreate = engage.ComicCreate;
     this.ComicRemix  = engage.ComicRemix;
     this.Unsubscribe = engage.Unsubscribe;
 }
示例#3
0
        public EmptyResult ReaderComment(long id)
        {
            try
            {
                this.EntityContext.TryAttach(this.ActiveUser);
                Data.Comic comic = this.EntityContext.TryGetComic(id, this.ActiveUser);
                if (comic != null)
                {
                    comic.AuthorReference.Load();
                    UserEngage engage = this.GetUserEngage(comic.Author);

                    comic.Author.UserEngageReference.Load();

                    UserEngageHistory history = comic.Author.UserEngageHistory
                                                .OrderByDescending(h => h.EngageTime)
                                                .FirstOrDefault(h => h.Engagement == UserEngageHistory.EngagementType.Comment);

                    if (!engage.Unsubscribe && engage.Comment && (history == null || history.EngageTime <= DateTime.Now.AddDays(-1)))
                    {
                        ClientComic c = new ClientComic(comic);

                        // create & save history
                        history            = new UserEngageHistory();
                        history.Engagement = UserEngageHistory.EngagementType.Comment;
                        history.EngageTime = DateTime.Now;
                        history.User       = comic.Author;
                        this.EntityContext.AddToUserEngageHistory(history);
                        this.EntityContext.SaveChanges();

                        // Generate email message
                        EmailManager email = new EmailManager(this.Server);
                        Dictionary <string, string> data = new Dictionary <string, string>();
                        data.Add("id", history.EngageHistoryId.ToString());
                        data.Add("title", String.Format("New Comment - {0}", comic.Title));
                        data.Add("reader.name", this.ActiveUser.Nickname);
                        data.Add("comic.title", comic.Title);
                        data.Add("comic.readUrl", c.ReadUrl);

                        // Send email
                        email.SendEmail(comic.Author, "Comment.html", data);
                    }
                }
            }
            finally
            {
                this.EntityContext.TryDetach(this.ActiveUser);
            }

            return(new EmptyResult());
        }
        protected UserEngage GetUserEngage(User user)
        {
            UserEngage engage = this.EntityContext.TryGetUserEngage(user);

            if (engage == null)
            {
                engage             = new UserEngage();
                engage.User        = user;
                engage.Comment     = true;
                engage.ComicCreate = true;
                engage.ComicRemix  = true;
                engage.Unsubscribe = false;
                this.EntityContext.AddToUserEngage(engage);
                this.EntityContext.SaveChanges();
            }
            return(engage);
        }
示例#5
0
        public ActionResult Settings()
        {
            ActionResult result = new EmptyResult();

            try
            {
                this.EntityContext.TryAttach(this.ActiveUser);
                UserEngage engage = this.GetUserEngage(this.ActiveUser);
                result = this.View(new ViewSettings(new ClientUserEngage(engage), this.ActiveUser.Email));
            }
            finally
            {
                this.EntityContext.TryDetach(this.ActiveUser);
            }

            return(result);
        }
示例#6
0
        public JsonResult Publish(long comicId, string title, string description, bool isPrivate)
        {
            Data.Comic  comic = null;
            ClientComic c     = null;

            try
            {
                this.EntityContext.TryAttach(this.ActiveUser);

                comic = this.EntityContext.TryGetUnpublishedComic(comicId, this.ActiveUser);
                if (comic == null || comic.Uid != this.ActiveUser.Uid)
                {
                    throw new Exception("Could not find the requested comic.");
                }

                comic.Title       = title;
                comic.Description = description;
                comic.IsPrivate   = isPrivate;

                // Get bytecode from storage
                CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.RenderContainer);
                CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.ComicDirectory);
                CloudBlob          blob      = directory.GetBlobReference(comic.StorageKey);

                ClientComic clientComic = new ClientComic(comic);

                // Publish to facebook album for better visibility
                MemoryStream photoStream = new MemoryStream();
                try
                {
                    blob.DownloadToStream(photoStream);

                    FacebookMediaObject fbMedia = new FacebookMediaObject
                    {
                        ContentType = "image/jpeg",
                        FileName    = String.Format("{0}.jpg", comic.StorageKey)
                    };
                    fbMedia.SetValue(photoStream.ToArray());

                    Dictionary <string, object> photoParams = new Dictionary <string, object>();
                    photoParams.Add("message", String.Format("{0} - Remix this comic at {1}", comic.Description, clientComic.RemixUrl));
                    photoParams.Add("source", fbMedia);
                    this.Facebook.Post("/me/photos", photoParams);
                }
                catch (Exception x)
                {
                    this.Log.Error("Unable to publish comic to facebook album.", x);
                }
                finally
                {
                    photoStream.Dispose();
                }

                this.EntityContext.PublishComic(comic, this.ActiveUser);
                c = new ClientComic(comic);
                this.EntityContext.SaveChanges();


                // Email notifications
                UserEngage engage = this.GetUserEngage(this.ActiveUser);

                if (!engage.Unsubscribe && engage.ComicCreate)
                {
                    // create & save history
                    UserEngageHistory history = new UserEngageHistory();
                    history.Engagement = UserEngageHistory.EngagementType.ComicCreate;
                    history.EngageTime = DateTime.Now;
                    history.User       = this.ActiveUser;
                    this.EntityContext.AddToUserEngageHistory(history);
                    this.EntityContext.SaveChanges();

                    // Generate email message
                    EmailManager email = new EmailManager(this.Server);
                    Dictionary <string, string> data = new Dictionary <string, string>();
                    data.Add("id", history.EngageHistoryId.ToString());
                    data.Add("title", String.Format("New Comic - {0}", comic.Title));
                    data.Add("comic.title", c.Title);
                    data.Add("comic.readUrl", c.ReadUrl);

                    // Send email
                    email.SendEmail(this.ActiveUser, "ComicCreate.html", data);
                }

                // Check for notifications of a remixed comic
                if (comic.RemixedComic != null)
                {
                    engage = this.EntityContext.TryGetUserEngage(comic.RemixedComic.Author);
                    ClientComic remixed = new ClientComic(comic.RemixedComic);

                    if (!engage.Unsubscribe && engage.ComicRemix)
                    {
                        UserEngageHistory history = new UserEngageHistory();
                        history.Engagement = UserEngageHistory.EngagementType.ComicRemix;
                        history.EngageTime = DateTime.Now;
                        history.User       = comic.RemixedComic.Author;
                        this.EntityContext.AddToUserEngageHistory(history);
                        this.EntityContext.SaveChanges();

                        // Generate email message
                        EmailManager email = new EmailManager(this.Server);
                        Dictionary <string, string> data = new Dictionary <string, string>();
                        data.Add("id", history.EngageHistoryId.ToString());
                        data.Add("title", String.Format("Remixed Comic - {0}", comic.Title));
                        data.Add("comic.title", c.Title);
                        data.Add("comic.readUrl", c.ReadUrl);
                        data.Add("remix.title", remixed.Title);
                        data.Add("remix.readUrl", remixed.ReadUrl);

                        // Send email
                        email.SendEmail(comic.RemixedComic.Author, "ComicRemix.html", data);
                    }
                }
            }
            finally
            {
                this.EntityContext.TryDetach(this.ActiveUser);
            }

            return(this.Json(c, JsonRequestBehavior.DenyGet));
        }