예제 #1
0
        protected ComicRead GetReader(long comicId)
        {
            ComicRead read = null;

            try
            {
                this.EntityContext.TryAttach(this.ActiveUser);
                Data.Comic comic = this.EntityContext.TryGetComic(comicId, this.ActiveUser, this.Friends);
                if (comic == null || !comic.IsPublished)
                {
                    throw new Exception("Unable to find the requested comic.");
                }

                read = this.EntityContext.TryGetComicRead(comic, this.ActiveUser);

                if (read == null)
                {
                    read          = new ComicRead();
                    read.Comic    = comic;
                    read.Reader   = this.ActiveUser;
                    read.ReadTime = DateTime.Now;
                    this.EntityContext.AddToComicRead(read);
                }
            }
            finally
            {
                this.EntityContext.TryDetach(this.ActiveUser);
            }

            return(read);
        }
예제 #2
0
        public JsonResult ReaderRandom(long comicId)
        {
            ComicRead read = this.GetReader(comicId);

            read.IsRandom = !read.IsRandom;
            this.EntityContext.SaveChanges();

            return(this.Json(new { result = "ok" }));
        }
예제 #3
0
 public ClientComicRead(ComicRead source)
 {
     this.Uid      = source.Uid;
     this.ComicId  = source.ComicId;
     this.ReadTime = source.ReadTime;
     this.IsFunny  = source.IsFunny;
     this.IsSmart  = source.IsSmart;
     this.IsRandom = source.IsRandom;
 }
예제 #4
0
        public ComicRead TryGetComicRead(Comic comic, User reader)
        {
            ComicRead read = null;

            if (reader != null)
            {
                read = this.ComicRead.FirstOrDefault(r => r.ComicId == comic.ComicId && r.Uid == reader.Uid);
            }
            return(read);
        }
예제 #5
0
        public ActionResult Read(long comicId, string title)
        {
            ActionResult result;

            try
            {
                Data.Comic comic = null;

                //// Facebook shared comics
                //if (this.ActiveUser == null && this.HttpContext.Request.UrlReferrer != null && this.HttpContext.Request.UrlReferrer.Host.Contains("facebook.com"))
                //{
                //    comic = this.EntityContext.TryGetComic(comicId, null, true);
                //    if (comic != null)
                //    {
                //        this.LoginGuestUser(comic.Author);
                //    }
                //}
                //// Guest user logged in
                //else if (this.GuestUser != null)
                //{
                //    comic = this.EntityContext.TryGetComic(comicId, this.GuestUser);
                //}
                //else
                //{
                //    // All other entry points
                //    this.EntityContext.TryAttach(this.ActiveUser);
                //    comic = this.EntityContext.TryGetComic(comicId, this.ActiveUser, this.Friends);
                //}

                // Asume that if the user found the comic, they are allowed to read it (hard to track shares and whatnot)
                comic = this.EntityContext.TryGetComic(comicId);

                if (comic == null)
                {
                    result = this.View("ReadNotFound");
                }
                else
                {
                    // Track read
                    this.EntityContext.TryAttach(this.ActiveUser);
                    ComicRead read = this.EntityContext.TryGetComicRead(comic, this.ActiveUser);
                    try                     // Having an entity issue.. trying to track it down with this.
                    {
                        if (read == null)
                        {
                            read          = new ComicRead();
                            read.Comic    = comic;
                            read.Reader   = this.ActiveUser;
                            read.ReadTime = DateTime.Now;

                            if (this.ActiveUser != null)
                            {
                                this.EntityContext.AddToComicRead(read);
                                this.EntityContext.SaveChanges();
                            }
                        }
                    }
                    catch (Exception x)
                    {
                        this.Log.Error("Reader error", x);
                    }
                    finally
                    {
                        this.EntityContext.TryDetach(this.ActiveUser);
                    }

                    // Load tags
                    comic.ComicTags.Load();
                    List <ClientComicTag> tags = comic.ComicTags.Select(t => new ClientComicTag(t)).ToList();

                    result = (ActionResult)this.View(new ViewRead(new ClientComic(comic), new ClientComicRead(read), tags));
                }
            }
            finally
            {
                this.EntityContext.TryDetach(this.ActiveUser);
            }

            return(result);
        }