Example #1
0
        public JsonResult List([FromForm] string token, [FromForm] TypeEnumEntity.TypeEnum typeId)
        {
            DataResult dr = new DataResult();

            try
            {
                EnshrineBLL           enshrineBLL      = new EnshrineBLL();
                List <EnshrineEntity> enshrineEntities = new List <EnshrineEntity>();

                UserEntity userEntity = this.GetUserByToken(token);

                enshrineEntities = enshrineBLL.ListByUserId(userEntity.userId, (int)typeId);
                CaseBLL caseBLL    = new CaseBLL();
                int[]   caseIdInts = enshrineEntities.Where(it => it.typeId == (int)TypeEnumEntity.TypeEnum.案例).Select(it => it.objId).ToArray();
                if (caseIdInts.Count() > 0)
                {
                    List <CaseEntity> caseEntities = caseBLL.ListByCaseIdInts(caseIdInts);

                    if (caseEntities.Count > 0)
                    {
                        caseEntities = CaseListEndorseCountByList(caseEntities, userEntity.userId);
                        caseEntities = CaseListCommentCountByList(caseEntities);

                        caseEntities.ForEach(it =>
                        {
                            enshrineEntities.Find(itt => itt.typeId == (int)TypeEnumEntity.TypeEnum.案例 && itt.objId == it.caseId).caseEntity = it;
                        });
                    }
                }

                int[] caseOfficialIdInts = enshrineEntities.Where(it => it.typeId == (int)TypeEnumEntity.TypeEnum.官方案例).Select(it => it.objId).ToArray();
                if (caseOfficialIdInts.Count() > 0)
                {
                    List <CaseOfficialEntity> caseOfficialEntities = caseBLL.ListByCaseOfficialIdInts(caseOfficialIdInts);

                    if (caseOfficialEntities.Count > 0)
                    {
                        caseOfficialEntities = CaseOfficialEndorseCountByList(caseOfficialEntities, userEntity.userId);
                        caseOfficialEntities = CaseOfficialCommentCountByList(caseOfficialEntities);

                        caseOfficialEntities.ForEach(it =>
                        {
                            enshrineEntities.Find(itt => itt.typeId == (int)TypeEnumEntity.TypeEnum.官方案例 && itt.objId == it.caseOfficialId).caseOfficialEntity = it;
                        });
                    }
                }



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

            return(Json(dr));
        }
Example #2
0
        public JsonResult Create([FromForm] string token, [FromForm] int objId, [FromForm] TypeEnumEntity.TypeEnum typeId)
        {
            DataResult dr = new DataResult();

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

                UserEntity userEntity = this.GetUserByToken(token);

                EnshrineBLL    enshrineBLL    = new EnshrineBLL();
                EnshrineEntity enshrineEntity = enshrineBLL.GetByIdAndTypeIdAndUserId(objId, (int)typeId, userEntity.userId);

                if (enshrineEntity != null)
                {
                    dr.code = "200";
                    dr.msg  = "成功";
                    return(Json(dr));
                }

                EnshrineEntity enshrine = new EnshrineEntity()
                {
                    createDate = DateTime.Now,
                    objId      = objId,
                    typeId     = (int)typeId,
                    userId     = userEntity.userId
                };

                int rows = enshrineBLL.ActionDal.ActionDBAccess.Insertable(enshrine).ExecuteCommand();

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