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); }
public JsonResult ReaderRandom(long comicId) { ComicRead read = this.GetReader(comicId); read.IsRandom = !read.IsRandom; this.EntityContext.SaveChanges(); return(this.Json(new { result = "ok" })); }
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; }
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); }
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); }