public ActionResult AddNewBeeFloor(Guid NewBeeID, string mdTxt, string mdValue)
        {
            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)
            {
                return(Json(new { msg = "你被封禁至" + user.AbleDate.ToString("yyyy-MM-dd HH:ss") }));
            }
            if (string.IsNullOrEmpty(mdTxt) || string.IsNullOrEmpty(mdValue))
            {
                return(Json(new { msg = "参数错误" }));
            }
            if (mdTxt.GetByteCount() > 2500 || mdValue.GetByteCount() > 5000)
            {
                return(Json(new { msg = "参数太长" }));
            }

            NewBee newBee = NewBeeDataSvc.GetByID(NewBeeID);

            newBee.FloorCount   += 1;
            newBee.LastFloorDate = DateTime.Now;

            NewBeeFloor floor = new NewBeeFloor();

            floor.NewBeeID = NewBeeID;
            floor.MDText   = mdTxt;
            floor.MDValue  = HtmlST.Sanitize(mdValue);
            floor.OwnerID  = CurrentUser.ID;
            floor.Order    = newBee.FloorCount;
            NewBeeFloorDataSvc.Add(floor);

            NewBeeDataSvc.Update(newBee);

            if (newBee.OwnerID != CurrentUser.ID)
            {
                string key   = MyRedisKeys.Pre_CMsg + newBee.OwnerID;
                CMsg   bcmsg = MyRedisDB.GetSet <CMsg>(key).Where(m => m.ObjID == NewBeeID).FirstOrDefault();
                if (bcmsg != null)
                {
                    MyRedisDB.SetRemove(key, bcmsg);
                    bcmsg.Count += 1;
                    MyRedisDB.SetAdd(key, bcmsg);
                }
                else
                {
                    bcmsg         = new CMsg();
                    bcmsg.ObjType = (int)EnumObjectType.NewBee;
                    bcmsg.ObjID   = NewBeeID;
                    bcmsg.Count   = 1;
                    bcmsg.Date    = DateTime.Now;
                    bcmsg.Order   = floor.Order;
                    bcmsg.Title   = newBee.Title.MaxByteLength(32);
                    MyRedisDB.SetAdd(key, bcmsg);
                }
            }

            return(Json(new { msg = "done", count = newBee.FloorCount }));
        }
        public ActionResult UserNewBeePage(Guid uid, int pageSize, int pageNum = 1)
        {
            ViewBag.Owner = CurrentUser == null ? false : uid == CurrentUser.ID;
            int totalCount;

            ViewBag.UserNewBees = NewBeeDataSvc.GetPagedEntitys(ref pageNum, pageSize, b => b.OwnerID == uid, b => b.InsertDate, true, out totalCount).ToList();
            ViewBag.TotalCount  = totalCount;
            ViewBag.CurrentPage = pageNum;
            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 NewBeeDelete(Guid id)
        {
            NewBee newBee = NewBeeDataSvc.GetByID(id);

            if (newBee.OwnerID != CurrentUser.ID)
            {
                return(Json(new { msg = "小伙子你想干嘛" }));
            }
            NewBeeDataSvc.DeleteByID(id);
            return(Json(new { msg = "done" }));
        }
        public ActionResult NewBeePage(int pageSize, int pageNum = 1)
        {
            int           totalCount = 0;
            List <NewBee> newBeeList = NewBeeDataSvc.GetPagedEntitys(ref pageNum, pageSize, it => !it.Top, it => it.LastFloorDate, true, out totalCount).ToList();

            if (pageNum == 1)
            {
                List <NewBee> topNewBee = NewBeeDataSvc.GetByCondition(n => n.Top).ToList();
                newBeeList = topNewBee.Concat(newBeeList).OrderByDescending(n => n.Top).ThenByDescending(n => n.LastFloorDate).ToList();
            }
            ViewBag.NewBeeList  = newBeeList;
            ViewBag.TotalCount  = totalCount;
            ViewBag.CurrentPage = pageNum;
            ViewBag.ShowPager   = totalCount > pageSize;

            IEnumerable <Guid> NewBeeIDs = newBeeList.Select(n => n.ID);

            ViewBag.FirstFloors = NewBeeFloorDataSvc.GetByCondition(f => NewBeeIDs.Contains(f.NewBeeID) && f.Order == 1).ToList();
            return(View());
        }
        public ActionResult NewNewBee(string title, string mdTxt, string mdValue)
        {
            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)
            {
                return(Json(new { msg = "你被封禁至" + user.AbleDate.ToString("yyyy-MM-dd HH:ss") }));
            }
            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(mdTxt) || string.IsNullOrEmpty(mdValue))
            {
                return(Json(new { msg = "参数错误" }));
            }

            if (title.GetByteCount() > 100 || mdTxt.GetByteCount() > 2500 || mdValue.GetByteCount() > 5000)
            {
                return(Json(new { msg = "参数太长" }));
            }

            NewBee nb = new NewBee();

            nb.OwnerID       = CurrentUser.ID;
            nb.Title         = title;
            nb.FloorCount    = 1;
            nb.LastFloorDate = DateTime.Now;
            nb.Top           = false;
            NewBeeDataSvc.Add(nb);

            NewBeeFloor nbf = new NewBeeFloor();

            nbf.MDText   = mdTxt;
            nbf.MDValue  = HtmlST.Sanitize(mdValue);
            nbf.NewBeeID = nb.ID;
            nbf.Order    = 1;
            nbf.OwnerID  = CurrentUser.ID;
            NewBeeFloorDataSvc.Add(nbf);

            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());
        }