public ActionResult UserStarPage(int type, int pageSize, int pageNum = 1) { int totalCount; ViewBag.UserStars = UserStarDataSvc.GetPagedEntitys(ref pageNum, pageSize, b => b.OwnerID == CurrentUser.ID && b.ObjType == type, b => b.InsertDate, true, out totalCount).ToList(); ViewBag.TotalCount = totalCount; ViewBag.CurrentPage = pageNum; ViewBag.Type = type; return(View()); }
public ActionResult StarNewBee(Guid id) { NewBee newBee = NewBeeDataSvc.GetByID(id); string starKey = MyRedisKeys.Pre_UserStarCache + CurrentUser.ID; IEnumerable <UserStarCache> userStarCaches = MyRedisDB.GetSet <UserStarCache>(starKey); bool add = false; if (userStarCaches.Count() == 0) { IEnumerable <UserStar> userStars = UserStarDataSvc.GetByCondition(s => s.OwnerID == CurrentUser.ID); if (userStars.Count() > 0) { //添加收藏缓存 foreach (UserStar star in userStars) { MyRedisDB.SetAdd(starKey, new UserStarCache() { ObjID = newBee.ID, ObjType = star.ObjType }); } MyRedisDB.RedisDB.KeyExpire(starKey, DateTime.Now.AddHours(3)); //添加收藏 if (userStars.Where(s => s.ObjID == newBee.ID).Count() == 0) { add = true; } } else { add = true; } } else if (userStarCaches.Where(s => s.ObjID == newBee.ID).Count() == 0) { add = true; } if (add) { //添加收藏 UserStar star = new UserStar(); star.OwnerID = CurrentUser.ID; star.ObjID = newBee.ID; star.Title = newBee.Title; star.ObjType = (int)EnumObjectType.NewBee; UserStarDataSvc.Add(star); MyRedisDB.SetAdd(starKey, new UserStarCache() { ObjID = newBee.ID, ObjType = star.ObjType }); MyRedisDB.RedisDB.KeyExpire(starKey, DateTime.Now.AddHours(3)); } return(Json(new { msg = "done" })); }
public ActionResult StarDelete(Guid id) { UserStar star = UserStarDataSvc.GetByID(id); if (star.OwnerID != CurrentUser.ID) { return(Json(new { msg = "小伙子你想干嘛" })); } UserStarDataSvc.DeleteByID(id); string starKey = MyRedisKeys.Pre_UserStarCache + CurrentUser.ID; IEnumerable <UserStarCache> userStarCaches = MyRedisDB.GetSet <UserStarCache>(starKey); if (userStarCaches.Count() > 0) { UserStarCache starCache = userStarCaches.Where(s => s.ObjID == star.ObjID).FirstOrDefault(); if (starCache != null) { MyRedisDB.SetRemove(starKey, starCache); } } return(Json(new { msg = "done" })); }
//NewBee详情 public ActionResult NewBeeView(Guid id, int co = 0, int ro = 0) { NewBee newBee = NewBeeDataSvc.GetByID(id); ViewBag.NewBee = newBee; ViewBag.Login = CurrentUser != null; ViewBag.Owner = CurrentUser != null ? CurrentUser.ID == newBee.OwnerID : false; ViewBag.COrder = co; ViewBag.ROrder = ro; newBee.ViewCount += 1; NewBeeDataSvc.Update(newBee); if (CurrentUser != null) { //查看次数 暂时不用户统计 //string key = MyRedisKeys.Pre_UserRecord + CurrentUser.ID; //IEnumerable<UserRecord> userRecords = MyRedisDB.GetSet<UserRecord>(key); //if (userRecords.Count() == 0) //{ // MyRedisDB.SetAdd(key, new UserRecord() { ObjID = newBee.ID, type = (int)EnumRecordType.查看 }); // MyRedisDB.RedisDB.KeyExpire(key, DateTime.Now.AddDays(1)); // newBee.ViewCount += 1; // NewBeeDataSvc.Update(newBee); //} //else if (userRecords.Where(r => r.ObjID == newBee.ID && r.type == (int)EnumRecordType.查看).Count() == 0) //{ // MyRedisDB.SetAdd(key, new UserRecord() { ObjID = newBee.ID, type = (int)EnumRecordType.查看 }); // newBee.ViewCount += 1; // NewBeeDataSvc.Update(newBee); //} //收藏 ViewBag.ShowStar = true; string starKey = MyRedisKeys.Pre_UserStarCache + CurrentUser.ID; IEnumerable <UserStarCache> userStarCaches = MyRedisDB.GetSet <UserStarCache>(starKey); if (userStarCaches.Count() == 0) { IEnumerable <UserStar> userStars = UserStarDataSvc.GetByCondition(s => s.OwnerID == CurrentUser.ID); if (userStars.Count() > 0) { if (userStars.Where(s => s.ObjID == newBee.ID).Count() > 0) { ViewBag.ShowStar = false; } //添加收藏缓存 foreach (UserStar star in userStars) { MyRedisDB.SetAdd(starKey, new UserStarCache() { ObjID = newBee.ID, ObjType = star.ObjType }); } MyRedisDB.RedisDB.KeyExpire(starKey, DateTime.Now.AddHours(3)); } } else if (userStarCaches.Where(s => s.ObjID == newBee.ID).Count() > 0) { ViewBag.ShowStar = false; } DisabledUser user = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == CurrentUser.ID && d.ObjectType == (int)EnumObjectType.NewBee && d.AbleDate > DateTime.Now).FirstOrDefault(); if (user != null) { ViewBag.DisableMsg = "你被封禁至" + user.AbleDate.ToString("yyyy-MM-dd HH:ss"); } } return(View()); }