Example #1
0
        /// <summary>
        /// 批量获取楼盘推荐
        /// </summary>
        /// <param name="user"></param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public virtual async Task <int> AllCountAsync(BuildingRecommendRequest buildingRecommendRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var building = await _ibuildingStore.GetAsync(x => x.Where(y => !y.IsDeleted && y.ExamineStatus == (int)Models.ExamineStatusEnum.Approved && y.Id == buildingRecommendRequest.BuildingId));

                if (building == null)
                {
                    return(-1);
                }

                var departmentid = (await _iorganizationExpansionStore.ListAsync(a => a.Where(b => (b.SonId == building.OrganizationId && b.Type == "Filiale") || (b.OrganizationId == building.OrganizationId && b.Type == "Filiale")))).FirstOrDefault()?.OrganizationId;
                if (departmentid == null)
                {
                    return(-2);
                }


                var response = _ibuildingRecommendsStore.BuildingRecommendAll().Where(x => !x.IsOutDate && !x.IsDeleted && !x.IsRegion && !x.Buildings.IsDeleted && x.MainAreaId == departmentid);
                return(await response.CountAsync(cancellationToken));
            }
            catch (Exception e)
            {
                return(0);
            }
        }
Example #2
0
        public async Task <ResponseMessage> PutBuildingRecommend(UserInfo user, [FromBody] BuildingRecommendRequest buildingRecommendRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改楼盘收藏信息(PutBuildingRecommend):\r\n请求的参数为:\r\n" + (buildingRecommendRequest != null ? JsonHelper.ToJson(buildingRecommendRequest) : ""));

            var response = new ResponseMessage();

            if (!ModelState.IsValid)
            {
                var error  = "";
                var errors = ModelState.Values.ToList();
                foreach (var item in errors)
                {
                    foreach (var e in item.Errors)
                    {
                        error += e.ErrorMessage + "  ";
                    }
                }
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = error;
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改楼盘收藏信息(PutBuildingRecommend)模型验证失败:\r\n{error},\r\n请求的参数为:\r\n" + (buildingRecommendRequest != null ? JsonHelper.ToJson(buildingRecommendRequest) : ""));

                return(response);
            }
            try
            {
                var dictionaryGroup = await _buildingRecommendManager.FindByIdAsync(buildingRecommendRequest.Id, HttpContext.RequestAborted);

                if (dictionaryGroup == null)
                {
                    await _buildingRecommendManager.CreateAsync(user, buildingRecommendRequest, HttpContext.RequestAborted);
                }
                await _buildingRecommendManager.UpdateAsync(user.Id, buildingRecommendRequest, HttpContext.RequestAborted);

                response.Code    = ResponseCodeDefines.SuccessCode;
                response.Message = "修改成功";
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改楼盘收藏信息(PutBuildingRecommend)报错:\r\n{e.ToString()},\r\n请求的参数为:\r\n" + (buildingRecommendRequest != null ? JsonHelper.ToJson(buildingRecommendRequest) : ""));
            }
            return(response);
        }
Example #3
0
        /// <summary>
        /// 修改单个楼盘收藏信息
        /// </summary>
        /// <param name="userId">请求者Id</param>
        /// <param name="buildingRecommendRequest">请求数据</param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public virtual async Task UpdateAsync(string userId, BuildingRecommendRequest buildingRecommendRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (buildingRecommendRequest == null)
            {
                throw new ArgumentNullException(nameof(buildingRecommendRequest));
            }
            var buildingRecommend = await _ibuildingRecommendsStore.GetAsync(a => a.Where(b => b.Id == buildingRecommendRequest.Id && !b.IsDeleted));

            if (buildingRecommend == null)
            {
                return;
            }
            var newbuildingRecommend = _mapper.Map <BuildingRecommend>(buildingRecommendRequest);

            newbuildingRecommend.IsDeleted       = buildingRecommend.IsDeleted;
            newbuildingRecommend.CreateTime      = buildingRecommend.CreateTime;
            newbuildingRecommend.CreateUser      = buildingRecommend.CreateUser;
            newbuildingRecommend.UpdateTime      = DateTime.Now;
            newbuildingRecommend.UpdateUser      = userId;
            newbuildingRecommend.RecommendUserId = buildingRecommend.RecommendUserId;

            //判断是否改变排序
            if (newbuildingRecommend.Order != buildingRecommend.Order)
            {
                var query = _ibuildingRecommendsStore.BuildingRecommendAll().Where(x => x.Order >= newbuildingRecommend.Order);
                foreach (var item in query)
                {
                    item.Order = item.Order - 1;
                }
                await _ibuildingRecommendsStore.UpdateListAsync(await query.ToListAsync(cancellationToken), cancellationToken);
            }
            try
            {
                await _ibuildingRecommendsStore.UpdateAsync(newbuildingRecommend, cancellationToken);
            }
            catch { }
        }
Example #4
0
        /// <summary>
        /// 新增楼盘收藏信息
        /// </summary>
        /// <param name="user">创建者</param>
        /// <param name="buildingRecommendRequest">请求实体</param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public virtual async Task <BuildingRecommendResponse> CreateAsync(UserInfo user, BuildingRecommendRequest buildingRecommendRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (buildingRecommendRequest == null)
            {
                throw new ArgumentNullException(nameof(buildingRecommendRequest));
            }

            var building = await _ibuildingStore.GetAsync(x => x.Where(y => !y.IsDeleted && y.ExamineStatus == (int)Models.ExamineStatusEnum.Approved && y.Id == buildingRecommendRequest.BuildingId));

            if (building == null)
            {
                return(null);
            }



            var buildingRecommend = _mapper.Map <BuildingRecommend>(buildingRecommendRequest);

            buildingRecommend.Id              = Guid.NewGuid().ToString();
            buildingRecommend.CreateUser      = user.Id;
            buildingRecommend.CreateTime      = DateTime.Now;
            buildingRecommend.RecommendUserId = user.Id;

            if (buildingRecommend.IsRegion)
            {
                var ss = await _permissionExpansionManager.HavePermission(user.Id, "RECOMMEND_REGION");

                if (!ss)
                {
                    return(null);
                }

                var mainareaid = (await _iorganizationExpansionStore.ListAsync(x => x.Where(y => (y.SonId == building.OrganizationId && y.Type == "Region") || (y.OrganizationId == building.OrganizationId && y.Type == "Region")), cancellationToken)).FirstOrDefault()?.OrganizationId;

                if (mainareaid == null)
                {
                    return(null);
                }
                else
                {
                    if (await _ibuildingRecommendsStore.GetAsync(x => x.Where(y => y.BuildingId == buildingRecommend.BuildingId && y.IsRegion && !y.IsDeleted && !y.IsOutDate && y.MainAreaId == mainareaid)) != null)
                    {
                        return(null);
                    }
                    buildingRecommend.MainAreaId = mainareaid;
                }
            }
            else
            {
                var ss = await _permissionExpansionManager.HavePermission(user.Id, "RECOMMEND_FILIALE");

                if (!ss)
                {
                    return(null);
                }
                var mainareaid = (await _iorganizationExpansionStore.ListAsync(x => x.Where(y => (y.SonId == building.OrganizationId && y.Type == "Filiale") || (y.OrganizationId == building.OrganizationId && y.Type == "Filiale")), cancellationToken)).FirstOrDefault()?.OrganizationId;

                if (await _ibuildingRecommendsStore.GetAsync(x => x.Where(y => y.BuildingId == buildingRecommend.BuildingId && y.IsRegion && !y.IsDeleted && !y.IsOutDate && y.MainAreaId == mainareaid)) != null)
                {
                    return(null);
                }
                buildingRecommend.MainAreaId = mainareaid;
            }

            try
            {
                await _ibuildingRecommendsStore.CreateAsync(buildingRecommend, cancellationToken);
            }
            catch
            {
            }
            return(_mapper.Map <BuildingRecommendResponse>(buildingRecommend));
        }
Example #5
0
        public async Task <ResponseMessage <BuildingRecommendResponse> > PostBuildingRecommend(UserInfo user, [FromBody] BuildingRecommendRequest buildingRecommendRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增楼盘收藏信息(PostBuildingRecommend):\r\n请求的参数为:\r\n" + (buildingRecommendRequest != null ? JsonHelper.ToJson(buildingRecommendRequest) : ""));

            var response = new ResponseMessage <BuildingRecommendResponse>();

            if (!ModelState.IsValid)
            {
                var error  = "";
                var errors = ModelState.Values.ToList();
                foreach (var item in errors)
                {
                    foreach (var e in item.Errors)
                    {
                        error += e.ErrorMessage + "  ";
                    }
                }
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = error;
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增楼盘收藏信息(PostBuildingRecommend)模型验证失败:\r\n{error},\r\n请求的参数为:\r\n" + (buildingRecommendRequest != null ? JsonHelper.ToJson(buildingRecommendRequest) : ""));

                return(response);
            }
            if (!buildingRecommendRequest.IsRegion)
            {
                var count = await _buildingRecommendManager.AllCountAsync(buildingRecommendRequest);

                if (count == 5)
                {
                    response.Code    = ResponseCodeDefines.NotAllow;
                    response.Message = "当前公司推荐数量大于5";
                    return(response);
                }
                else if (count == -1)
                {
                    response.Code    = ResponseCodeDefines.NotAllow;
                    response.Message = "暂未找到该楼盘或者该楼盘已推荐";
                    return(response);
                }
                else if (count == -2)
                {
                    response.Code    = ResponseCodeDefines.NotAllow;
                    response.Message = "暂未找到该部门分公司";
                    return(response);
                }
            }
            try
            {
                response.Extension = await _buildingRecommendManager.CreateAsync(user, buildingRecommendRequest, HttpContext.RequestAborted);

                if (response.Extension == null)
                {
                    response.Code    = ResponseCodeDefines.NotFound;
                    response.Message = "新增失败";
                }
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.Message;
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增楼盘收藏信息(PostBuildingRecommend)报错:\r\n{e.ToString()},\r\n请求的参数为:\r\n" + (buildingRecommendRequest != null ? JsonHelper.ToJson(buildingRecommendRequest) : ""));
            }

            return(response);
        }