Ejemplo n.º 1
0
        /// <summary>
        /// 获取点赞数量和判断是否点赞
        /// </summary>
        /// <param name="caseEntities"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        protected List <CaseEntity> CaseListEndorseCountByList(List <CaseEntity> caseEntities, int userId)
        {
            if (caseEntities.Count() > 0)
            {
                int[] idInts = caseEntities.Select(it => it.caseId).ToArray();

                EndorseBLL           endorseBLL      = new EndorseBLL();
                List <EndorseEntity> endorseEntities = endorseBLL.ListByTypeAndObjIdInts((int)Entity.TypeEnumEntity.TypeEnum.案例, idInts);

                if (endorseEntities.Count() > 0)
                {
                    if (userId > 10000)
                    {
                        var userEndorseList = endorseEntities.Where(it => it.userId == userId).ToList();

                        userEndorseList.ToList().ForEach(it =>
                        {
                            caseEntities.First(itt => itt.caseId == it.objId).isEndorse = true;
                        });
                    }

                    Dictionary <int, int> keyValuePairs = endorseEntities
                                                          .GroupBy(it => it.objId)
                                                          .Select(it => new
                    {
                        id    = it.Key,
                        count = it.Count()
                    })
                                                          .ToDictionary(it => it.id, it => it.count);

                    caseEntities = (from c in caseEntities
                                    join e in keyValuePairs on c.caseId equals e.Key into se
                                    from ses in se.DefaultIfEmpty()
                                    select new CaseEntity
                    {
                        caseId = c.caseId,
                        coverImage = c.coverImage,
                        createDate = c.createDate,
                        describe = c.describe,
                        integral = c.integral,
                        isDel = c.isDel,
                        modifyDate = c.modifyDate,
                        name = c.name,
                        portrait = c.portrait,
                        state = c.state,
                        tips = c.tips,
                        title = c.title,
                        userId = c.userId,
                        commentCount = c.commentCount,
                        endorseCount = ses.Value,
                        isEndorse = c.isEndorse,
                        readCount = c.readCount
                    })
                                   .ToList();
                }
            }

            return(caseEntities);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取点赞和判断是否已点赞
        /// </summary>
        /// <param name="shareEntities"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        protected List <ShareEntity> ShareListEndorseCountByList(List <ShareEntity> shareEntities, int userId = -1)
        {
            if (shareEntities.Count() > 0)
            {
                int[] shareIdInts = shareEntities.Select(it => it.shareId).ToArray();

                EndorseBLL           endorseBLL      = new EndorseBLL();
                List <EndorseEntity> endorseEntities = endorseBLL.ListByTypeAndObjIdInts((int)Entity.TypeEnumEntity.TypeEnum.说说, shareIdInts);

                if (endorseEntities.Count() > 0)
                {
                    if (userId > 10000)
                    {
                        var userEndorseList = endorseEntities.Where(it => it.userId == userId).ToList();

                        userEndorseList.ToList().ForEach(it =>
                        {
                            shareEntities.First(itt => itt.shareId == it.objId).isEndorse = true;
                        });
                    }

                    Dictionary <int, int> keyValuePairs = endorseEntities
                                                          .GroupBy(it => it.objId)
                                                          .Select(it => new
                    {
                        id    = it.Key,
                        count = it.Count()
                    })
                                                          .ToDictionary(it => it.id, it => it.count);

                    shareEntities = (from s in shareEntities
                                     join e in keyValuePairs on s.shareId equals e.Key into se
                                     from ses in se.DefaultIfEmpty()
                                     select new ShareEntity
                    {
                        contents = s.contents,
                        createDate = s.createDate,
                        endorseCount = ses.Value,
                        img = s.img,
                        integral = s.integral,
                        modifyDate = s.modifyDate,
                        shareId = s.shareId,
                        shareTopicId = s.shareTopicId,
                        shareTypeId = s.shareTypeId,
                        userId = s.userId,
                        isDel = s.isDel,
                        name = s.name,
                        portrait = s.portrait,
                        isEndorse = s.isEndorse,
                        commentCount = s.commentCount,
                        readCount = s.readCount
                    })
                                    .ToList();
                }
            }

            return(shareEntities);
        }
Ejemplo n.º 3
0
        public JsonResult Delete([FromForm] string token, [FromForm] int objId, [FromForm] int type)
        {
            DataResult dr = new DataResult();

            try
            {
                if (objId < 10000 || type < 1)
                {
                    dr.code = "201";
                    dr.msg  = "参数错误";
                    return(Json(dr));
                }

                UserEntity userEntity = this.GetUserByToken(token);


                EndorseBLL    endorseBLL    = new EndorseBLL();
                EndorseEntity endorseEntity = endorseBLL.GetUserIdAndTypeAndObjId(userEntity.userId, type, objId);

                endorseEntity.isDel      = true;
                endorseEntity.modifyDate = DateTime.Now;

                int rows = endorseBLL.ActionDal.ActionDBAccess.Updateable(endorseEntity).ExecuteCommand();
                //增加阅读记录
                ReadBLL readBLL = new ReadBLL();
                readBLL.Create(userEntity.userId, type, objId);
                if (rows > 0)
                {
                    dr.code = "200";
                    dr.msg  = "成功";
                }
                else
                {
                    dr.code = "201";
                    dr.msg  = "失败";
                }
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }
            return(Json(dr));
        }
Ejemplo n.º 4
0
        public JsonResult GetById([FromForm] string token, [FromForm] int caseId)
        {
            DataResult dr = new DataResult();

            try
            {
                CaseBLL    caseBLL    = new CaseBLL();
                CaseEntity caseEntity = caseBLL.GetById(caseId);

                CommentBLL commentBLL = new CommentBLL();
                caseEntity.commentCount = commentBLL.ListByTypeAndObjId((int)Entity.TypeEnumEntity.TypeEnum.案例, caseEntity.caseId).Count();

                EndorseBLL           endorseBLL      = new EndorseBLL();
                List <EndorseEntity> endorseEntities = endorseBLL.ListByTypeAndObjId((int)Entity.TypeEnumEntity.TypeEnum.案例, caseEntity.caseId);

                caseEntity.endorseCount = endorseEntities.Count();
                UserEntity userEntity = new UserEntity();
                if (!string.IsNullOrWhiteSpace(token))
                {
                    userEntity = this.GetUserByToken(token);
                    if (endorseEntities.ToList().Exists(it => it.userId == userEntity.userId))
                    {
                        caseEntity.isEndorse = true;
                    }
                }

                CaseStepBLL caseStepBLL = new CaseStepBLL();
                caseEntity.caseStepEntities = caseStepBLL.ListByCaseId(caseEntity.caseId);

                CaseTagCorrelationBLL caseTagCorrelationBLL = new CaseTagCorrelationBLL();
                caseEntity.caseTagEntities = caseTagCorrelationBLL.CaseTagListByCaseId(caseEntity.caseId);

                dr.code = "200";
                dr.data = caseEntity;
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }

            return(Json(dr));
        }
Ejemplo n.º 5
0
        public JsonResult Create([FromForm] string token, [FromForm] int objId, [FromForm] int type)
        {
            DataResult dr = new DataResult();

            try
            {
                if (objId < 10000 || type < 1)
                {
                    dr.code = "201";
                    dr.msg  = "参数错误";
                    return(Json(dr));
                }

                UserEntity userEntity = this.GetUserByToken(token);

                EndorseBLL endorseBLL = new EndorseBLL();
                int        rows       = endorseBLL.Create(userEntity.userId, type, objId);
                //增加阅读记录
                ReadBLL readBLL = new ReadBLL();
                readBLL.Create(userEntity.userId, type, objId);
                if (rows > 0)
                {
                    dr.code = "200";
                    dr.msg  = "成功";
                }
                else
                {
                    dr.code = "201";
                    dr.msg  = "失败";
                }
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }
            return(Json(dr));
        }
Ejemplo n.º 6
0
        public JsonResult GetById([FromForm] string token, [FromForm] int shareId)
        {
            DataResult dr = new DataResult();

            try
            {
                ShareEntity shareEntity = shareBLL.GetById(shareId);
                UserEntity  userEntity  = new UserEntity();

                CommentBLL commentBLL = new CommentBLL();
                shareEntity.commentCount = commentBLL.ListByTypeAndObjId((int)Entity.TypeEnumEntity.TypeEnum.说说, shareEntity.shareId).Count();

                EndorseBLL           endorseBLL      = new EndorseBLL();
                List <EndorseEntity> endorseEntities = endorseBLL.ListByTypeAndObjId((int)Entity.TypeEnumEntity.TypeEnum.说说, shareEntity.shareId);

                shareEntity.endorseCount = endorseEntities.Count();
                if (!string.IsNullOrWhiteSpace(token))
                {
                    userEntity = this.GetUserByToken(token);
                    if (endorseEntities.ToList().Exists(it => it.userId == userEntity.userId))
                    {
                        shareEntity.isEndorse = true;
                    }
                }

                dr.code = "200";
                dr.data = shareEntity;
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }

            return(Json(dr));
        }