示例#1
0
        /// <summary>
        /// 新增用户信息
        /// </summary>
        public APIResponseEntity <bool> Add(APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.UserInfo.AddOrUpdateEntity> request)
        {
            var response = new APIResponseEntity <bool>();

            #region 数据校验

            if (null == request.Body.UserInfo)
            {
                response.IsSuccess = false;
                response.Message   = "请指定用户信息!";
                return(response);
            }
            request.Body.UserInfo.UserName = (request.Body.UserInfo.UserName ?? "").Trim();
            if (!string.IsNullOrWhiteSpace(request.Body.UserInfo.Pwd))
            {
                request.Body.UserInfo.Pwd = XCLCMS.Data.CommonHelper.EncryptHelper.EncryptStringMD5(request.Body.UserInfo.Pwd);
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.UserInfo.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //必须指定用户信息
            if (string.IsNullOrEmpty(request.Body.UserInfo.UserName))
            {
                response.IsSuccess = false;
                response.Message   = "请指定用户名!";
                return(response);
            }

            //用户名是否被占用
            if (this.userInfoBLL.IsExistUserName(request.Body.UserInfo.UserName))
            {
                response.IsSuccess = false;
                response.Message   = "用户名被占用,请重新指定用户名!";
                return(response);
            }

            //应用号与商户一致
            if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.UserInfo.FK_MerchantID, request.Body.UserInfo.FK_MerchantAppID))
            {
                response.IsSuccess = false;
                response.Message   = "商户号与应用号不匹配,请核对后再试!";
                return(response);
            }

            //角色是否越界
            var roleList = this.sysRoleBLL.GetModelList(request.Body.RoleIdList);
            if (null != roleList && roleList.Count > 0 && roleList.Exists(k => k.FK_MerchantID != request.Body.UserInfo.FK_MerchantID))
            {
                response.IsSuccess = false;
                response.Message   = "角色与用户所在商户不匹配!";
                return(response);
            }

            #endregion 数据校验

            XCLCMS.Data.BLL.Strategy.UserInfo.UserInfoContext userInfoContext = new Data.BLL.Strategy.UserInfo.UserInfoContext();
            userInfoContext.ContextInfo = this.ContextInfo;
            userInfoContext.UserInfo    = request.Body.UserInfo;
            userInfoContext.UserRoleIDs = request.Body.RoleIdList;
            userInfoContext.HandleType  = Data.BLL.Strategy.StrategyLib.HandleType.ADD;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.UserInfo.UserInfo()
            });
            if (userInfoContext.UserRoleIDs.IsNotNullOrEmpty())
            {
                strategy.StrategyList.Add(new XCLCMS.Data.BLL.Strategy.UserInfo.RoleInfo());
            }
            strategy.Execute <XCLCMS.Data.BLL.Strategy.UserInfo.UserInfoContext>(userInfoContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "添加成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
            }

            return(response);
        }
示例#2
0
        /// <summary>
        /// 修改文章信息
        /// </summary>
        public APIResponseEntity <bool> Update(APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.Article.AddOrUpdateEntity> request)
        {
            List <long> tempIdList;
            var         response = new APIResponseEntity <bool>();

            #region 数据校验

            if (null == request.Body.Article)
            {
                response.IsSuccess = false;
                response.Message   = "请指定文章信息!";
                return(response);
            }
            if (string.IsNullOrWhiteSpace(request.Body.Article.Code))
            {
                request.Body.Article.Code = request.Body.Article.ArticleID.ToString();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.AuthorName))
            {
                request.Body.Article.AuthorName = request.Body.Article.AuthorName.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Code))
            {
                request.Body.Article.Code = request.Body.Article.Code.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Comments))
            {
                request.Body.Article.Comments = request.Body.Article.Comments.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Contents))
            {
                request.Body.Article.Contents = request.Body.Article.Contents.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.FromInfo))
            {
                request.Body.Article.FromInfo = request.Body.Article.FromInfo.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.KeyWords))
            {
                request.Body.Article.KeyWords = request.Body.Article.KeyWords.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.LinkUrl))
            {
                request.Body.Article.LinkUrl = request.Body.Article.LinkUrl.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.SubTitle))
            {
                request.Body.Article.SubTitle = request.Body.Article.SubTitle.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Summary))
            {
                request.Body.Article.Summary = request.Body.Article.Summary.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Tags))
            {
                request.Body.Article.Tags = request.Body.Article.Tags.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Title))
            {
                request.Body.Article.Title = request.Body.Article.Title.Trim();
            }
            if (request.Body.Article.PublishTime == DateTime.MinValue)
            {
                request.Body.Article.PublishTime = DateTime.Now;
            }

            var model = this.articleBLL.GetModel(request.Body.Article.ArticleID);
            if (null == model)
            {
                response.IsSuccess = false;
                response.Message   = "请指定有效的文章信息!";
                return(response);
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.Article.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //必须指定文章信息
            if (string.IsNullOrEmpty(request.Body.Article.Title))
            {
                response.IsSuccess = false;
                response.Message   = "请指定文章标题!";
                return(response);
            }

            //如果内容类型为链接,则必须指定链接地址
            if (string.IsNullOrWhiteSpace(request.Body.Article.LinkUrl) && string.Equals(request.Body.Article.ArticleContentType, XCLCMS.Data.CommonHelper.EnumType.ArticleContentTypeEnum.URL.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                response.IsSuccess = false;
                response.Message   = "请指定跳转链接地址!";
                return(response);
            }

            //code是否被占用
            if (!string.IsNullOrEmpty(request.Body.Article.Code) && !string.Equals(model.Code, request.Body.Article.Code, StringComparison.OrdinalIgnoreCase) && this.articleBLL.IsExistCode(request.Body.Article.Code))
            {
                response.IsSuccess = false;
                response.Message   = "文章标识Code被占用,请重新指定!";
                return(response);
            }

            //应用号与商户一致
            if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.Article.FK_MerchantID, request.Body.Article.FK_MerchantAppID))
            {
                response.IsSuccess = false;
                response.Message   = "商户号与应用号不匹配,请核对后再试!";
                return(response);
            }

            //过滤非法文章分类
            if (request.Body.ArticleTypeIDList.IsNotNullOrEmpty())
            {
                tempIdList = request.Body.ArticleTypeIDList.Where(k =>
                {
                    var typeModel = this.sysDicBLL.GetModel(k);
                    return(null != typeModel && typeModel.FK_MerchantID == request.Body.Article.FK_MerchantID);
                }).ToList();
                if (request.Body.ArticleTypeIDList.Count != tempIdList.Count)
                {
                    response.IsSuccess = false;
                    response.Message   = "不能包含无效的文章分类信息!";
                    return(response);
                }
                request.Body.ArticleTypeIDList = tempIdList;
            }

            //过滤非法附件
            if (request.Body.ArticleAttachmentIDList.IsNotNullOrEmpty())
            {
                tempIdList = request.Body.ArticleAttachmentIDList.Where(k =>
                {
                    var typeModel = this.attachmentBLL.GetModel(k);
                    return(null != typeModel && typeModel.FK_MerchantID == request.Body.Article.FK_MerchantID);
                }).ToList();
                if (request.Body.ArticleAttachmentIDList.Count != tempIdList.Count)
                {
                    response.IsSuccess = false;
                    response.Message   = "不能包含无效的附件信息!";
                    return(response);
                }
                request.Body.ArticleAttachmentIDList = tempIdList;
            }

            //过滤非法产品
            if (request.Body.ArticleProductIDList.IsNotNullOrEmpty())
            {
                tempIdList = request.Body.ArticleProductIDList.Where(k =>
                {
                    var typeModel = this.productBLL.GetModel(k);
                    return(null != typeModel && typeModel.FK_MerchantID == request.Body.Article.FK_MerchantID);
                }).ToList();
                if (request.Body.ArticleProductIDList.Count != tempIdList.Count)
                {
                    response.IsSuccess = false;
                    response.Message   = "不能包含无效的营销产品信息!";
                    return(response);
                }
                request.Body.ArticleProductIDList = tempIdList;
            }

            #endregion 数据校验

            model.RecordState        = request.Body.Article.RecordState;
            model.ArticleContentType = request.Body.Article.ArticleContentType;
            model.ArticleState       = request.Body.Article.ArticleState;
            model.AuthorName         = request.Body.Article.AuthorName;
            model.BadCount           = request.Body.Article.BadCount;
            if (string.IsNullOrWhiteSpace(request.Body.Article.Code))
            {
                model.Code = model.ArticleID.ToString();
            }
            else
            {
                model.Code = request.Body.Article.Code;
            }
            model.CommentCount     = request.Body.Article.CommentCount;
            model.Comments         = request.Body.Article.Comments;
            model.Contents         = request.Body.Article.Contents;
            model.FromInfo         = request.Body.Article.FromInfo;
            model.GoodCount        = request.Body.Article.GoodCount;
            model.HotCount         = request.Body.Article.HotCount;
            model.IsCanComment     = request.Body.Article.IsCanComment;
            model.IsEssence        = request.Body.Article.IsEssence;
            model.IsRecommend      = request.Body.Article.IsRecommend;
            model.IsTop            = request.Body.Article.IsTop;
            model.KeyWords         = request.Body.Article.KeyWords;
            model.LinkUrl          = request.Body.Article.LinkUrl;
            model.MainImage1       = request.Body.Article.MainImage1;
            model.MainImage2       = request.Body.Article.MainImage2;
            model.MainImage3       = request.Body.Article.MainImage3;
            model.MiddleCount      = request.Body.Article.MiddleCount;
            model.PublishTime      = request.Body.Article.PublishTime;
            model.SubTitle         = request.Body.Article.SubTitle;
            model.Summary          = request.Body.Article.Summary;
            model.Tags             = request.Body.Article.Tags;
            model.Title            = request.Body.Article.Title;
            model.TopBeginTime     = request.Body.Article.TopBeginTime;
            model.TopEndTime       = request.Body.Article.TopEndTime;
            model.URLOpenType      = request.Body.Article.URLOpenType;
            model.VerifyState      = request.Body.Article.VerifyState;
            model.ViewCount        = request.Body.Article.ViewCount;
            model.FK_MerchantAppID = request.Body.Article.FK_MerchantAppID;
            model.FK_MerchantID    = request.Body.Article.FK_MerchantID;

            var articleContext = new Data.BLL.Strategy.Article.ArticleContext();
            articleContext.ContextInfo             = this.ContextInfo;
            articleContext.Article                 = model;
            articleContext.HandleType              = Data.BLL.Strategy.StrategyLib.HandleType.UPDATE;
            articleContext.ArticleTypeIDList       = request.Body.ArticleTypeIDList;
            articleContext.ArticleAttachmentIDList = request.Body.ArticleAttachmentIDList;
            articleContext.ArticleProductIDList    = request.Body.ArticleProductIDList;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.Article.Article(),
                new XCLCMS.Data.BLL.Strategy.Article.ObjectAttachment(),
                new XCLCMS.Data.BLL.Strategy.Article.ArticleType(),
                new XCLCMS.Data.BLL.Strategy.Article.Tags(),
                new XCLCMS.Data.BLL.Strategy.Article.ObjectProduct()
            });
            strategy.Execute(articleContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "修改成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
            }

            return(response);
        }
示例#3
0
        /// <summary>
        /// 修改用户信息
        /// </summary>
        public APIResponseEntity <bool> Update(APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.UserInfo.AddOrUpdateEntity> request)
        {
            var response = new APIResponseEntity <bool>();

            #region 数据校验

            if (null == request.Body.UserInfo)
            {
                response.IsSuccess = false;
                response.Message   = "请指定用户信息!";
                return(response);
            }

            var model = this.userInfoBLL.GetModel(request.Body.UserInfo.UserInfoID);
            if (null == model)
            {
                response.IsSuccess = false;
                response.Message   = "请指定有效的用户信息!";
                return(response);
            }

            request.Body.UserInfo.UserName = (request.Body.UserInfo.UserName ?? "").Trim();
            if (!string.IsNullOrWhiteSpace(request.Body.UserInfo.Pwd) && !XCLNetTools.Encrypt.MD5.Is32MD5(request.Body.UserInfo.Pwd))
            {
                request.Body.UserInfo.Pwd = XCLCMS.Data.CommonHelper.EncryptHelper.EncryptStringMD5(request.Body.UserInfo.Pwd);
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.UserInfo.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //应用号与商户一致
            if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.UserInfo.FK_MerchantID, request.Body.UserInfo.FK_MerchantAppID))
            {
                response.IsSuccess = false;
                response.Message   = "商户号与应用号不匹配,请核对后再试!";
                return(response);
            }

            //角色是否越界
            var roleList = this.sysRoleBLL.GetModelList(request.Body.RoleIdList);
            if (null != roleList && roleList.Count > 0 && roleList.Exists(k => k.FK_MerchantID != request.Body.UserInfo.FK_MerchantID))
            {
                response.IsSuccess = false;
                response.Message   = "角色与用户所在商户不匹配!";
                return(response);
            }

            #endregion 数据校验

            model.RecordState      = request.Body.UserInfo.RecordState;
            model.AccessToken      = request.Body.UserInfo.AccessToken;
            model.AccessType       = request.Body.UserInfo.AccessType;
            model.Age              = request.Body.UserInfo.Age;
            model.Birthday         = request.Body.UserInfo.Birthday;
            model.Email            = request.Body.UserInfo.Email;
            model.FK_MerchantID    = request.Body.UserInfo.FK_MerchantID;
            model.FK_MerchantAppID = request.Body.UserInfo.FK_MerchantAppID;
            model.NickName         = request.Body.UserInfo.NickName;
            model.OtherContact     = request.Body.UserInfo.OtherContact;
            if (!string.IsNullOrWhiteSpace(request.Body.UserInfo.Pwd))
            {
                model.Pwd = request.Body.UserInfo.Pwd;
            }
            model.QQ        = request.Body.UserInfo.QQ;
            model.RealName  = request.Body.UserInfo.RealName;
            model.Remark    = request.Body.UserInfo.Remark;
            model.SexType   = request.Body.UserInfo.SexType;
            model.Tel       = request.Body.UserInfo.Tel;
            model.UserState = request.Body.UserInfo.UserState;

            model.UpdaterID   = this.ContextInfo.UserInfoID;
            model.UpdaterName = this.ContextInfo.UserName;
            model.UpdateTime  = DateTime.Now;

            XCLCMS.Data.BLL.Strategy.UserInfo.UserInfoContext userInfoContext = new Data.BLL.Strategy.UserInfo.UserInfoContext();
            userInfoContext.ContextInfo = this.ContextInfo;
            userInfoContext.UserInfo    = model;
            userInfoContext.UserRoleIDs = request.Body.RoleIdList;
            userInfoContext.HandleType  = Data.BLL.Strategy.StrategyLib.HandleType.UPDATE;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.UserInfo.UserInfo()
            });
            if (userInfoContext.UserRoleIDs.IsNotNullOrEmpty())
            {
                strategy.StrategyList.Add(new XCLCMS.Data.BLL.Strategy.UserInfo.RoleInfo());
            }
            strategy.Execute <XCLCMS.Data.BLL.Strategy.UserInfo.UserInfoContext>(userInfoContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "修改成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
            }

            return(response);
        }
示例#4
0
        public APIResponseEntity <bool> Update(JObject obj)
        {
            var request  = obj.ToObject <APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.Article.AddOrUpdateEntity> >();
            var response = new APIResponseEntity <bool>();

            #region 数据校验

            if (null == request.Body.Article)
            {
                response.IsSuccess = false;
                response.Message   = "请指定文章信息!";
                return(response);
            }
            if (string.IsNullOrWhiteSpace(request.Body.Article.Code))
            {
                request.Body.Article.Code = request.Body.Article.ArticleID.ToString();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.AuthorName))
            {
                request.Body.Article.AuthorName = request.Body.Article.AuthorName.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Code))
            {
                request.Body.Article.Code = request.Body.Article.Code.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Comments))
            {
                request.Body.Article.Comments = request.Body.Article.Comments.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Contents))
            {
                request.Body.Article.Contents = request.Body.Article.Contents.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.FromInfo))
            {
                request.Body.Article.FromInfo = request.Body.Article.FromInfo.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.KeyWords))
            {
                request.Body.Article.KeyWords = request.Body.Article.KeyWords.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.LinkUrl))
            {
                request.Body.Article.LinkUrl = request.Body.Article.LinkUrl.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.SubTitle))
            {
                request.Body.Article.SubTitle = request.Body.Article.SubTitle.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Summary))
            {
                request.Body.Article.Summary = request.Body.Article.Summary.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Tags))
            {
                request.Body.Article.Tags = request.Body.Article.Tags.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Title))
            {
                request.Body.Article.Title = request.Body.Article.Title.Trim();
            }

            var model = this.articleBLL.GetModel(request.Body.Article.ArticleID);
            if (null == model)
            {
                response.IsSuccess = false;
                response.Message   = "请指定有效的文章信息!";
                return(response);
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.Article.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //必须指定文章信息
            if (string.IsNullOrEmpty(request.Body.Article.Title))
            {
                response.IsSuccess = false;
                response.Message   = "请指定文章标题!";
                return(response);
            }

            //code是否被占用
            if (!string.IsNullOrEmpty(request.Body.Article.Code) && !string.Equals(model.Code, request.Body.Article.Code, StringComparison.OrdinalIgnoreCase) && this.articleBLL.IsExistCode(request.Body.Article.Code))
            {
                response.IsSuccess = false;
                response.Message   = "文章标识Code被占用,请重新指定!";
                return(response);
            }

            //应用号与商户一致
            if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.Article.FK_MerchantID, request.Body.Article.FK_MerchantAppID))
            {
                response.IsSuccess = false;
                response.Message   = "商户号与应用号不匹配,请核对后再试!";
                return(response);
            }

            //限制商户
            if (base.IsOnlyCurrentMerchant && request.Body.Article.FK_MerchantID != base.CurrentUserModel.FK_MerchantID)
            {
                response.IsSuccess = false;
                response.Message   = "只能在自己所属的商户下面修改文章信息!";
                return(response);
            }

            #endregion 数据校验

            model.ArticleContentType = request.Body.Article.ArticleContentType;
            model.ArticleState       = request.Body.Article.ArticleState;
            model.AuthorName         = request.Body.Article.AuthorName;
            model.BadCount           = request.Body.Article.BadCount;
            if (string.IsNullOrWhiteSpace(request.Body.Article.Code))
            {
                model.Code = model.ArticleID.ToString();
            }
            else
            {
                model.Code = request.Body.Article.Code;
            }
            model.CommentCount     = request.Body.Article.CommentCount;
            model.Comments         = request.Body.Article.Comments;
            model.Contents         = request.Body.Article.Contents;
            model.FromInfo         = request.Body.Article.FromInfo;
            model.GoodCount        = request.Body.Article.GoodCount;
            model.HotCount         = request.Body.Article.HotCount;
            model.IsCanComment     = request.Body.Article.IsCanComment;
            model.IsEssence        = request.Body.Article.IsEssence;
            model.IsRecommend      = request.Body.Article.IsRecommend;
            model.IsTop            = request.Body.Article.IsTop;
            model.KeyWords         = request.Body.Article.KeyWords;
            model.LinkUrl          = request.Body.Article.LinkUrl;
            model.MainImage1       = request.Body.Article.MainImage1;
            model.MainImage2       = request.Body.Article.MainImage2;
            model.MainImage3       = request.Body.Article.MainImage3;
            model.MiddleCount      = request.Body.Article.MiddleCount;
            model.PublishTime      = request.Body.Article.PublishTime;
            model.SubTitle         = request.Body.Article.SubTitle;
            model.Summary          = request.Body.Article.Summary;
            model.Tags             = request.Body.Article.Tags;
            model.Title            = request.Body.Article.Title;
            model.TopBeginTime     = request.Body.Article.TopBeginTime;
            model.TopEndTime       = request.Body.Article.TopEndTime;
            model.UpdaterID        = base.UserID;
            model.UpdaterName      = base.CurrentUserModel.UserName;
            model.UpdateTime       = DateTime.Now;
            model.URLOpenType      = request.Body.Article.URLOpenType;
            model.VerifyState      = request.Body.Article.VerifyState;
            model.ViewCount        = request.Body.Article.ViewCount;
            model.FK_MerchantAppID = request.Body.Article.FK_MerchantAppID;
            model.FK_MerchantID    = request.Body.Article.FK_MerchantID;

            var articleContext = new Data.BLL.Strategy.Article.ArticleContext();
            articleContext.CurrentUserInfo         = base.CurrentUserModel;
            articleContext.Article                 = model;
            articleContext.HandleType              = Data.BLL.Strategy.StrategyLib.HandleType.UPDATE;
            articleContext.ArticleTypeIDList       = request.Body.ArticleTypeIDList;
            articleContext.ArticleAttachmentIDList = request.Body.ArticleAttachmentIDList;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.Article.Article(),
                new XCLCMS.Data.BLL.Strategy.Article.ObjectAttachment(),
                new XCLCMS.Data.BLL.Strategy.Article.ArticleType()
            });
            strategy.Execute(articleContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "修改成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
                XCLNetLogger.Log.WriteLog(XCLNetLogger.Config.LogConfig.LogLevel.ERROR, "修改文章信息失败", strategy.ResultMessage);
            }

            return(response);
        }
示例#5
0
        /// <summary>
        /// 修改信息
        /// </summary>
        public APIResponseEntity <bool> Update(APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.KeyValueInfo.AddOrUpdateEntity> request)
        {
            List <long> tempIdList;
            var         response = new APIResponseEntity <bool>();

            #region 数据校验

            var model = KeyValueInfoBLL.GetModel(request.Body.KeyValueInfo.KeyValueInfoID);
            if (null == model)
            {
                response.IsSuccess = false;
                response.Message   = "请指定有效的数据信息!";
                return(response);
            }

            request.Body.KeyValueInfo.FK_ProductID = request.Body.KeyValueInfo.FK_ProductID > 0 ? request.Body.KeyValueInfo.FK_ProductID : 0;
            request.Body.KeyValueInfo.FK_UserID    = request.Body.KeyValueInfo.FK_UserID > 0 ? request.Body.KeyValueInfo.FK_UserID : 0;
            request.Body.KeyValueInfo.Code         = (request.Body.KeyValueInfo.Code ?? string.Empty).Trim();
            if (string.IsNullOrWhiteSpace(request.Body.KeyValueInfo.Code))
            {
                request.Body.KeyValueInfo.Code = request.Body.KeyValueInfo.KeyValueInfoID.ToString();
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.KeyValueInfo.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //code是否被占用
            if (!string.IsNullOrEmpty(request.Body.KeyValueInfo.Code) && !string.Equals(model.Code, request.Body.KeyValueInfo.Code, StringComparison.OrdinalIgnoreCase) && this.KeyValueInfoBLL.IsExistCode(request.Body.KeyValueInfo.Code))
            {
                response.IsSuccess = false;
                response.Message   = "标识Code被占用,请重新指定!";
                return(response);
            }

            //应用号与商户一致
            if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.KeyValueInfo.FK_MerchantID, request.Body.KeyValueInfo.FK_MerchantAppID))
            {
                response.IsSuccess = false;
                response.Message   = "商户号与应用号不匹配,请核对后再试!";
                return(response);
            }

            //产品检测
            if (request.Body.KeyValueInfo.FK_ProductID > 0)
            {
                var productModel = this.productBLL.GetModel(request.Body.KeyValueInfo.FK_ProductID);
                if (null == productModel)
                {
                    response.IsSuccess = false;
                    response.Message   = "请指定有效的产品信息!";
                    return(response);
                }

                //产品与商户一致
                if (productModel.FK_MerchantID != request.Body.KeyValueInfo.FK_MerchantID)
                {
                    response.IsSuccess = false;
                    response.Message   = "产品信息所属商户应与该数据所属商户一致!";
                    return(response);
                }
            }

            //所属用户校验
            if (request.Body.KeyValueInfo.FK_UserID > 0)
            {
                var uInfo = userInfoBLL.GetModel(request.Body.KeyValueInfo.FK_UserID);
                if (null == uInfo)
                {
                    response.IsSuccess = false;
                    response.Message   = "必须指定有效的所属用户信息!";
                    return(response);
                }
                request.Body.KeyValueInfo.UserName = uInfo.UserName;
            }
            else
            {
                request.Body.KeyValueInfo.FK_UserID = 0;
                request.Body.KeyValueInfo.UserName  = string.Empty;
            }

            //过滤非法分类
            if (request.Body.KeyValueInfoTypeIDList.IsNotNullOrEmpty())
            {
                tempIdList = request.Body.KeyValueInfoTypeIDList.Where(k =>
                {
                    var typeModel = this.sysDicBLL.GetModel(k);
                    return(null != typeModel && typeModel.FK_MerchantID == request.Body.KeyValueInfo.FK_MerchantID);
                }).ToList();
                if (request.Body.KeyValueInfoTypeIDList.Count != tempIdList.Count)
                {
                    response.IsSuccess = false;
                    response.Message   = "不能包含无效的数据分类信息!";
                    return(response);
                }
                request.Body.KeyValueInfoTypeIDList = tempIdList;
            }

            #endregion 数据校验

            model.Code             = request.Body.KeyValueInfo.Code;
            model.Remark           = request.Body.KeyValueInfo.Remark;
            model.FK_MerchantID    = request.Body.KeyValueInfo.FK_MerchantID;
            model.FK_MerchantAppID = request.Body.KeyValueInfo.FK_MerchantAppID;
            model.RecordState      = request.Body.KeyValueInfo.RecordState;
            model.Contents         = request.Body.KeyValueInfo.Contents;

            var context = new Data.BLL.Strategy.KeyValueInfo.KeyValueInfoContext();
            context.ContextInfo            = this.ContextInfo;
            context.KeyValueInfo           = model;
            context.HandleType             = Data.BLL.Strategy.StrategyLib.HandleType.UPDATE;
            context.KeyValueInfoTypeIDList = request.Body.KeyValueInfoTypeIDList;

            var strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.KeyValueInfo.KeyValueInfo(),
                new XCLCMS.Data.BLL.Strategy.KeyValueInfo.KeyValueInfoType()
            });
            strategy.Execute(context);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "数据信息修改成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
            }

            return(response);
        }
示例#6
0
        /// <summary>
        /// 新增文章信息
        /// </summary>
        public APIResponseEntity <bool> Add(APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.Article.AddOrUpdateEntity> request)
        {
            var response = new APIResponseEntity <bool>();

            #region 数据校验

            if (null == request.Body.Article)
            {
                response.IsSuccess = false;
                response.Message   = "请指定文章信息!";
                return(response);
            }
            if (string.IsNullOrWhiteSpace(request.Body.Article.Code))
            {
                request.Body.Article.Code = request.Body.Article.ArticleID.ToString();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.AuthorName))
            {
                request.Body.Article.AuthorName = request.Body.Article.AuthorName.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Code))
            {
                request.Body.Article.Code = request.Body.Article.Code.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Comments))
            {
                request.Body.Article.Comments = request.Body.Article.Comments.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Contents))
            {
                request.Body.Article.Contents = request.Body.Article.Contents.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.FromInfo))
            {
                request.Body.Article.FromInfo = request.Body.Article.FromInfo.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.KeyWords))
            {
                request.Body.Article.KeyWords = request.Body.Article.KeyWords.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.LinkUrl))
            {
                request.Body.Article.LinkUrl = request.Body.Article.LinkUrl.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.SubTitle))
            {
                request.Body.Article.SubTitle = request.Body.Article.SubTitle.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Summary))
            {
                request.Body.Article.Summary = request.Body.Article.Summary.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Tags))
            {
                request.Body.Article.Tags = request.Body.Article.Tags.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Title))
            {
                request.Body.Article.Title = request.Body.Article.Title.Trim();
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.Article.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //必须指定文章信息
            if (string.IsNullOrEmpty(request.Body.Article.Title))
            {
                response.IsSuccess = false;
                response.Message   = "请指定文章标题!";
                return(response);
            }

            //如果内容类型为链接,则必须指定链接地址
            if (string.IsNullOrWhiteSpace(request.Body.Article.LinkUrl) && string.Equals(request.Body.Article.ArticleContentType, XCLCMS.Data.CommonHelper.EnumType.ArticleContentTypeEnum.URL.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                response.IsSuccess = false;
                response.Message   = "请指定跳转链接地址!";
                return(response);
            }

            //code是否被占用
            if (!string.IsNullOrEmpty(request.Body.Article.Code) && this.articleBLL.IsExistCode(request.Body.Article.Code))
            {
                response.IsSuccess = false;
                response.Message   = "文章标识Code被占用,请重新指定!";
                return(response);
            }

            //应用号与商户一致
            if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.Article.FK_MerchantID, request.Body.Article.FK_MerchantAppID))
            {
                response.IsSuccess = false;
                response.Message   = "商户号与应用号不匹配,请核对后再试!";
                return(response);
            }

            #endregion 数据校验

            var articleContext = new Data.BLL.Strategy.Article.ArticleContext();
            articleContext.ContextInfo             = this.ContextInfo;
            articleContext.Article                 = request.Body.Article;
            articleContext.HandleType              = Data.BLL.Strategy.StrategyLib.HandleType.ADD;
            articleContext.ArticleTypeIDList       = request.Body.ArticleTypeIDList;
            articleContext.ArticleAttachmentIDList = request.Body.ArticleAttachmentIDList;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.Article.Article(),
                new XCLCMS.Data.BLL.Strategy.Article.ObjectAttachment(),
                new XCLCMS.Data.BLL.Strategy.Article.ArticleType(),
                new XCLCMS.Data.BLL.Strategy.Article.Tags()
            });
            strategy.Execute(articleContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "添加成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
            }

            return(response);
        }
示例#7
0
        public APIResponseEntity <bool> Add(JObject obj)
        {
            var request  = obj.ToObject <APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.Article.AddOrUpdateEntity> >();
            var response = new APIResponseEntity <bool>();

            #region 数据校验

            if (null == request.Body.Article)
            {
                response.IsSuccess = false;
                response.Message   = "请指定文章信息!";
                return(response);
            }
            if (string.IsNullOrWhiteSpace(request.Body.Article.Code))
            {
                request.Body.Article.Code = request.Body.Article.ArticleID.ToString();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.AuthorName))
            {
                request.Body.Article.AuthorName = request.Body.Article.AuthorName.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Code))
            {
                request.Body.Article.Code = request.Body.Article.Code.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Comments))
            {
                request.Body.Article.Comments = request.Body.Article.Comments.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Contents))
            {
                request.Body.Article.Contents = request.Body.Article.Contents.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.FromInfo))
            {
                request.Body.Article.FromInfo = request.Body.Article.FromInfo.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.KeyWords))
            {
                request.Body.Article.KeyWords = request.Body.Article.KeyWords.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.LinkUrl))
            {
                request.Body.Article.LinkUrl = request.Body.Article.LinkUrl.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.SubTitle))
            {
                request.Body.Article.SubTitle = request.Body.Article.SubTitle.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Summary))
            {
                request.Body.Article.Summary = request.Body.Article.Summary.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Tags))
            {
                request.Body.Article.Tags = request.Body.Article.Tags.Trim();
            }
            if (!string.IsNullOrEmpty(request.Body.Article.Title))
            {
                request.Body.Article.Title = request.Body.Article.Title.Trim();
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.Article.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //必须指定文章信息
            if (string.IsNullOrEmpty(request.Body.Article.Title))
            {
                response.IsSuccess = false;
                response.Message   = "请指定文章标题!";
                return(response);
            }

            //code是否被占用
            if (!string.IsNullOrEmpty(request.Body.Article.Code) && this.articleBLL.IsExistCode(request.Body.Article.Code))
            {
                response.IsSuccess = false;
                response.Message   = "文章标识Code被占用,请重新指定!";
                return(response);
            }

            //应用号与商户一致
            if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.Article.FK_MerchantID, request.Body.Article.FK_MerchantAppID))
            {
                response.IsSuccess = false;
                response.Message   = "商户号与应用号不匹配,请核对后再试!";
                return(response);
            }

            //限制商户
            if (base.IsOnlyCurrentMerchant && request.Body.Article.FK_MerchantID != base.CurrentUserModel.FK_MerchantID)
            {
                response.IsSuccess = false;
                response.Message   = "只能在自己所属的商户下面添加文章信息!";
                return(response);
            }

            #endregion 数据校验

            var articleContext = new Data.BLL.Strategy.Article.ArticleContext();
            articleContext.CurrentUserInfo         = base.CurrentUserModel;
            articleContext.Article                 = request.Body.Article;
            articleContext.HandleType              = Data.BLL.Strategy.StrategyLib.HandleType.ADD;
            articleContext.ArticleTypeIDList       = request.Body.ArticleTypeIDList;
            articleContext.ArticleAttachmentIDList = request.Body.ArticleAttachmentIDList;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.Article.Article(),
                new XCLCMS.Data.BLL.Strategy.Article.ObjectAttachment(),
                new XCLCMS.Data.BLL.Strategy.Article.ArticleType()
            });
            strategy.Execute(articleContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "添加成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
                XCLNetLogger.Log.WriteLog(XCLNetLogger.Config.LogConfig.LogLevel.ERROR, "添加文章信息失败", strategy.ResultMessage);
            }

            return(response);
        }
示例#8
0
        public async Task <APIResponseEntity <bool> > Update([FromBody] APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.UserInfo.AddOrUpdateEntity> request)
        {
            return(await Task.Run(() =>
            {
                var response = new APIResponseEntity <bool>();

                #region 数据校验

                if (null == request.Body.UserInfo)
                {
                    response.IsSuccess = false;
                    response.Message = "请指定用户信息!";
                    return response;
                }

                var model = this.userInfoBLL.GetModel(request.Body.UserInfo.UserInfoID);
                if (null == model)
                {
                    response.IsSuccess = false;
                    response.Message = "请指定有效的用户信息!";
                    return response;
                }

                request.Body.UserInfo.UserName = (request.Body.UserInfo.UserName ?? "").Trim();
                if (!string.IsNullOrWhiteSpace(request.Body.UserInfo.Pwd))
                {
                    request.Body.UserInfo.Pwd = XCLCMS.WebAPI.Library.EncryptHelper.EncryptStringMD5(request.Body.UserInfo.Pwd);
                }

                //商户必须存在
                var merchant = this.merchantBLL.GetModel(request.Body.UserInfo.FK_MerchantID);
                if (null == merchant)
                {
                    response.IsSuccess = false;
                    response.Message = "无效的商户号!";
                    return response;
                }

                //应用号与商户一致
                if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.UserInfo.FK_MerchantID, request.Body.UserInfo.FK_MerchantAppID))
                {
                    response.IsSuccess = false;
                    response.Message = "商户号与应用号不匹配,请核对后再试!";
                    return response;
                }

                //限制商户
                if (base.IsOnlyCurrentMerchant && request.Body.UserInfo.FK_MerchantID != base.CurrentUserModel.FK_MerchantID)
                {
                    response.IsSuccess = false;
                    response.Message = "只能在自己所属的商户下面修改用户信息!";
                    return response;
                }

                //角色是否越界
                var roleList = this.sysRoleBLL.GetModelList(request.Body.RoleIdList);
                if (null != roleList && roleList.Count > 0 && roleList.Exists(k => k.FK_MerchantID != request.Body.UserInfo.FK_MerchantID))
                {
                    response.IsSuccess = false;
                    response.Message = "角色与用户所在商户不匹配!";
                    return response;
                }

                #endregion 数据校验

                model.RecordState = request.Body.UserInfo.RecordState;
                model.AccessToken = request.Body.UserInfo.AccessToken;
                model.AccessType = request.Body.UserInfo.AccessType;
                model.Age = request.Body.UserInfo.Age;
                model.Birthday = request.Body.UserInfo.Birthday;
                model.Email = request.Body.UserInfo.Email;
                model.FK_MerchantID = request.Body.UserInfo.FK_MerchantID;
                model.FK_MerchantAppID = request.Body.UserInfo.FK_MerchantAppID;
                model.NickName = request.Body.UserInfo.NickName;
                model.OtherContact = request.Body.UserInfo.OtherContact;
                if (!string.IsNullOrWhiteSpace(request.Body.UserInfo.Pwd))
                {
                    model.Pwd = request.Body.UserInfo.Pwd;
                }
                model.QQ = request.Body.UserInfo.QQ;
                model.RealName = request.Body.UserInfo.RealName;
                model.Remark = request.Body.UserInfo.Remark;
                model.SexType = request.Body.UserInfo.SexType;
                model.Tel = request.Body.UserInfo.Tel;
                model.UserState = request.Body.UserInfo.UserState;

                model.UpdaterID = base.CurrentUserModel.UserInfoID;
                model.UpdaterName = base.CurrentUserModel.UserName;
                model.UpdateTime = DateTime.Now;

                XCLCMS.Data.BLL.Strategy.UserInfo.UserInfoContext userInfoContext = new Data.BLL.Strategy.UserInfo.UserInfoContext();
                userInfoContext.CurrentUserInfo = base.CurrentUserModel;
                userInfoContext.UserInfo = model;
                userInfoContext.UserRoleIDs = request.Body.RoleIdList;
                userInfoContext.HandleType = Data.BLL.Strategy.StrategyLib.HandleType.UPDATE;

                XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
                {
                    new XCLCMS.Data.BLL.Strategy.UserInfo.UserInfo()
                });
                if (XCLCMS.Lib.Permission.PerHelper.HasPermission(base.CurrentUserModel.UserInfoID, Lib.Permission.Function.FunctionEnum.SysFun_SetUserRole))
                {
                    strategy.StrategyList.Add(new XCLCMS.Data.BLL.Strategy.UserInfo.RoleInfo());
                }
                strategy.Execute <XCLCMS.Data.BLL.Strategy.UserInfo.UserInfoContext>(userInfoContext);

                if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
                {
                    response.Message = "修改成功!";
                    response.IsSuccess = true;
                }
                else
                {
                    response.Message = strategy.ResultMessage;
                    response.IsSuccess = false;
                    XCLNetLogger.Log.WriteLog(XCLNetLogger.Config.LogConfig.LogLevel.ERROR, "修改用户信息失败", strategy.ResultMessage);
                }

                return response;
            }));
        }
示例#9
0
        public async Task <APIResponseEntity <bool> > Add([FromBody] APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.UserInfo.AddOrUpdateEntity> request)
        {
            return(await Task.Run(() =>
            {
                var response = new APIResponseEntity <bool>();

                #region 数据校验

                if (null == request.Body.UserInfo)
                {
                    response.IsSuccess = false;
                    response.Message = "请指定用户信息!";
                    return response;
                }
                request.Body.UserInfo.UserName = (request.Body.UserInfo.UserName ?? "").Trim();
                if (!string.IsNullOrWhiteSpace(request.Body.UserInfo.Pwd))
                {
                    request.Body.UserInfo.Pwd = XCLCMS.WebAPI.Library.EncryptHelper.EncryptStringMD5(request.Body.UserInfo.Pwd);
                }

                //商户必须存在
                var merchant = this.merchantBLL.GetModel(request.Body.UserInfo.FK_MerchantID);
                if (null == merchant)
                {
                    response.IsSuccess = false;
                    response.Message = "无效的商户号!";
                    return response;
                }

                //必须指定用户信息
                if (string.IsNullOrEmpty(request.Body.UserInfo.UserName))
                {
                    response.IsSuccess = false;
                    response.Message = "请指定用户名!";
                    return response;
                }

                //用户名是否被占用
                if (this.userInfoBLL.IsExistUserName(request.Body.UserInfo.UserName))
                {
                    response.IsSuccess = false;
                    response.Message = "用户名被占用,请重新指定用户名!";
                    return response;
                }

                //应用号与商户一致
                if (!this.merchantAppBLL.IsTheSameMerchantInfoID(request.Body.UserInfo.FK_MerchantID, request.Body.UserInfo.FK_MerchantAppID))
                {
                    response.IsSuccess = false;
                    response.Message = "商户号与应用号不匹配,请核对后再试!";
                    return response;
                }

                //限制商户
                if (base.IsOnlyCurrentMerchant && request.Body.UserInfo.FK_MerchantID != base.CurrentUserModel.FK_MerchantID)
                {
                    response.IsSuccess = false;
                    response.Message = "只能在自己所属的商户下面添加用户信息!";
                    return response;
                }

                //角色是否越界
                var roleList = this.sysRoleBLL.GetModelList(request.Body.RoleIdList);
                if (null != roleList && roleList.Count > 0 && roleList.Exists(k => k.FK_MerchantID != request.Body.UserInfo.FK_MerchantID))
                {
                    response.IsSuccess = false;
                    response.Message = "角色与用户所在商户不匹配!";
                    return response;
                }

                #endregion 数据校验

                XCLCMS.Data.BLL.Strategy.UserInfo.UserInfoContext userInfoContext = new Data.BLL.Strategy.UserInfo.UserInfoContext();
                userInfoContext.CurrentUserInfo = base.CurrentUserModel;
                userInfoContext.UserInfo = request.Body.UserInfo;
                userInfoContext.UserRoleIDs = request.Body.RoleIdList;
                userInfoContext.HandleType = Data.BLL.Strategy.StrategyLib.HandleType.ADD;

                XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
                {
                    new XCLCMS.Data.BLL.Strategy.UserInfo.UserInfo()
                });
                if (XCLCMS.Lib.Permission.PerHelper.HasPermission(base.CurrentUserModel.UserInfoID, Lib.Permission.Function.FunctionEnum.SysFun_SetUserRole))
                {
                    strategy.StrategyList.Add(new XCLCMS.Data.BLL.Strategy.UserInfo.RoleInfo());
                }
                strategy.Execute <XCLCMS.Data.BLL.Strategy.UserInfo.UserInfoContext>(userInfoContext);

                if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
                {
                    response.Message = "添加成功!";
                    response.IsSuccess = true;
                }
                else
                {
                    response.Message = strategy.ResultMessage;
                    response.IsSuccess = false;
                    XCLNetLogger.Log.WriteLog(XCLNetLogger.Config.LogConfig.LogLevel.ERROR, "添加用户信息失败", strategy.ResultMessage);
                }

                return response;
            }));
        }
示例#10
0
        /// <summary>
        /// 修改角色
        /// </summary>
        public APIResponseEntity <bool> Update(APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.SysRole.AddOrUpdateEntity> request)
        {
            var response           = new APIResponseEntity <bool>();
            var allLeafFunctionIds = this.vSysFunctionBLL.GetModelList("").Where(k => k.IsLeaf == 1).Select(k => (long)k.SysFunctionID).ToList();

            #region 数据校验

            if (null == request.Body.SysRole)
            {
                response.IsSuccess = false;
                response.Message   = "请指定角色信息!";
                return(response);
            }

            var model = this.sysRoleBLL.GetModel(request.Body.SysRole.SysRoleID);
            if (null == model)
            {
                response.IsSuccess = false;
                response.Message   = "请指定有效的角色信息!";
                return(response);
            }

            request.Body.SysRole.RoleName = (request.Body.SysRole.RoleName ?? "").Trim();
            request.Body.SysRole.Code     = (request.Body.SysRole.Code ?? "").Trim();
            if (null == request.Body.FunctionIdList)
            {
                request.Body.FunctionIdList = new List <long>();
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.SysRole.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //只能修改商户主角色节点下面的角色信息(层级为3的节点)
            var vSysRoleModel = this.vSysRoleBLL.GetModel(request.Body.SysRole.SysRoleID);
            if (vSysRoleModel.NodeLevel != 3)
            {
                response.IsSuccess = false;
                response.Message   = "只能修改商户主角色节点下面的角色信息(层级为3的节点)!";
                return(response);
            }

            //追加默认的功能权限
            if (string.Equals(request.Body.SysRole.Code, XCLCMS.Data.CommonHelper.SysRoleConst.SysRoleCodeEnum.MerchantMainRole.ToString(), StringComparison.OrdinalIgnoreCase) || merchant.MerchantSystemType == XCLCMS.Data.CommonHelper.EnumType.MerchantSystemTypeEnum.NOR.ToString())
            {
                request.Body.FunctionIdList.AddRange(XCLCMS.Data.CommonHelper.Function.NormalMerchantFixedFunctionIDList);
            }
            request.Body.FunctionIdList = request.Body.FunctionIdList.Intersect(allLeafFunctionIds).ToList();

            //必须指定角色信息
            if (string.IsNullOrEmpty(request.Body.SysRole.RoleName))
            {
                response.IsSuccess = false;
                response.Message   = "请指定角色名!";
                return(response);
            }

            //角色code是否存在
            if (!string.IsNullOrEmpty(request.Body.SysRole.Code))
            {
                if (!string.Equals(model.Code, request.Body.SysRole.Code, StringComparison.OrdinalIgnoreCase) && this.sysRoleBLL.IsExistCode(request.Body.SysRole.Code))
                {
                    response.IsSuccess = false;
                    response.Message   = string.Format("角色标识【{0}】已存在!", request.Body.SysRole.Code);
                    return(response);
                }
            }

            //普通商户的权限是否已越界
            if (merchant.MerchantSystemType == XCLCMS.Data.CommonHelper.EnumType.MerchantSystemTypeEnum.NOR.ToString())
            {
                var normalFunIds = this.sysFunctionWebAPIBLL.GetNormalMerchantFunctionIDList(new APIRequestEntity <object>()).Body;
                if (request.Body.FunctionIdList.IsNotNullOrEmpty())
                {
                    if (request.Body.FunctionIdList.Exists(k => !normalFunIds.Contains(k)))
                    {
                        response.IsSuccess = false;
                        response.Message   = "该角色的权限已越界!";
                        return(response);
                    }
                }
            }

            #endregion 数据校验

            model.Code     = request.Body.SysRole.Code;
            model.Remark   = request.Body.SysRole.Remark;
            model.RoleName = request.Body.SysRole.RoleName;
            model.Sort     = request.Body.SysRole.Sort;
            model.Weight   = request.Body.SysRole.Weight;

            XCLCMS.Data.BLL.Strategy.SysRole.SysRoleContext sysRoleContext = new Data.BLL.Strategy.SysRole.SysRoleContext();
            sysRoleContext.ContextInfo    = this.ContextInfo;
            sysRoleContext.SysRole        = model;
            sysRoleContext.FunctionIdList = request.Body.FunctionIdList;
            sysRoleContext.HandleType     = Data.BLL.Strategy.StrategyLib.HandleType.UPDATE;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.SysRole.SysRole(),
                new XCLCMS.Data.BLL.Strategy.SysRole.SysRoleFunction()
            });
            strategy.Execute <XCLCMS.Data.BLL.Strategy.SysRole.SysRoleContext>(sysRoleContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "修改成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
            }

            return(response);
        }
示例#11
0
        /// <summary>
        /// 添加角色
        /// </summary>
        public APIResponseEntity <bool> Add(APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.SysRole.AddOrUpdateEntity> request)
        {
            var response           = new APIResponseEntity <bool>();
            var allLeafFunctionIds = this.vSysFunctionBLL.GetModelList("").Where(k => k.IsLeaf == 1).Select(k => (long)k.SysFunctionID).ToList();

            #region 数据校验

            if (null == request.Body.SysRole)
            {
                response.IsSuccess = false;
                response.Message   = "请指定角色信息!";
                return(response);
            }
            request.Body.SysRole.RoleName = (request.Body.SysRole.RoleName ?? "").Trim();
            request.Body.SysRole.Code     = (request.Body.SysRole.Code ?? "").Trim();
            if (null == request.Body.FunctionIdList)
            {
                request.Body.FunctionIdList = new List <long>();
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.SysRole.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //追加默认的功能权限
            if (string.Equals(request.Body.SysRole.Code, XCLCMS.Data.CommonHelper.SysRoleConst.SysRoleCodeEnum.MerchantMainRole.ToString(), StringComparison.OrdinalIgnoreCase) || merchant.MerchantSystemType == XCLCMS.Data.CommonHelper.EnumType.MerchantSystemTypeEnum.NOR.ToString())
            {
                request.Body.FunctionIdList.AddRange(XCLCMS.Data.CommonHelper.Function.NormalMerchantFixedFunctionIDList);
            }
            request.Body.FunctionIdList = request.Body.FunctionIdList.Intersect(allLeafFunctionIds).Distinct().ToList();

            //必须指定角色信息
            if (string.IsNullOrEmpty(request.Body.SysRole.RoleName))
            {
                response.IsSuccess = false;
                response.Message   = "请指定角色名!";
                return(response);
            }

            //角色code是否存在
            if (!string.IsNullOrEmpty(request.Body.SysRole.Code))
            {
                if (this.sysRoleBLL.IsExistCode(request.Body.SysRole.Code))
                {
                    response.IsSuccess = false;
                    response.Message   = string.Format("角色标识【{0}】已存在!", request.Body.SysRole.Code);
                    return(response);
                }
            }

            //父角色是否存在
            var parentNodeModel = this.vSysRoleBLL.GetModel(request.Body.SysRole.ParentID);
            if (null == parentNodeModel)
            {
                response.IsSuccess = false;
                response.Message   = "父角色不存在!";
                return(response);
            }

            //父节点必须为第2层级
            if (parentNodeModel.NodeLevel != 2)
            {
                response.IsSuccess = false;
                response.Message   = "父节点必须为第2层级节点!";
                return(response);
            }
            //子角色与父角色必须在同一商户中
            if (!this.vSysRoleBLL.IsRoot(parentNodeModel.SysRoleID.Value))
            {
                if (parentNodeModel.FK_MerchantID != request.Body.SysRole.FK_MerchantID)
                {
                    response.IsSuccess = false;
                    response.Message   = "您添加的角色必须与父角色在同一个商户中!";
                    return(response);
                }
            }

            //普通商户的权限是否已越界
            if (merchant.MerchantSystemType == XCLCMS.Data.CommonHelper.EnumType.MerchantSystemTypeEnum.NOR.ToString())
            {
                var normalFunIds = this.sysFunctionWebAPIBLL.GetNormalMerchantFunctionIDList(new APIRequestEntity <object>()).Body;
                if (request.Body.FunctionIdList.IsNotNullOrEmpty())
                {
                    if (request.Body.FunctionIdList.Exists(k => !normalFunIds.Contains(k)))
                    {
                        response.IsSuccess = false;
                        response.Message   = "该角色的权限已越界!";
                        return(response);
                    }
                }
            }

            #endregion 数据校验

            XCLCMS.Data.BLL.Strategy.SysRole.SysRoleContext sysRoleContext = new Data.BLL.Strategy.SysRole.SysRoleContext();
            sysRoleContext.ContextInfo    = this.ContextInfo;
            sysRoleContext.SysRole        = request.Body.SysRole;
            sysRoleContext.FunctionIdList = request.Body.FunctionIdList;
            sysRoleContext.HandleType     = Data.BLL.Strategy.StrategyLib.HandleType.ADD;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.SysRole.SysRole(),
                new XCLCMS.Data.BLL.Strategy.SysRole.SysRoleFunction()
            });
            strategy.Execute <XCLCMS.Data.BLL.Strategy.SysRole.SysRoleContext>(sysRoleContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "添加成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
            }

            return(response);
        }
示例#12
0
        public APIResponseEntity <bool> Update(JObject obj)
        {
            var request            = obj.ToObject <APIRequestEntity <XCLCMS.Data.WebAPIEntity.RequestEntity.SysRole.AddOrUpdateEntity> >();
            var response           = new APIResponseEntity <bool>();
            var allLeafFunctionIds = XCLCMS.Lib.Permission.PerHelper.GetFunctionList().Where(k => k.IsLeaf == 1).Select(k => (long)k.SysFunctionID).ToList();

            #region 数据校验

            if (null == request.Body.SysRole)
            {
                response.IsSuccess = false;
                response.Message   = "请指定角色信息!";
                return(response);
            }

            var model = this.sysRoleBLL.GetModel(request.Body.SysRole.SysRoleID);
            if (null == model)
            {
                response.IsSuccess = false;
                response.Message   = "请指定有效的角色信息!";
                return(response);
            }

            request.Body.SysRole.RoleName = (request.Body.SysRole.RoleName ?? "").Trim();
            request.Body.SysRole.Code     = (request.Body.SysRole.Code ?? "").Trim();
            if (null == request.Body.FunctionIdList)
            {
                request.Body.FunctionIdList = new List <long>();
            }

            //商户必须存在
            var merchant = this.merchantBLL.GetModel(request.Body.SysRole.FK_MerchantID);
            if (null == merchant)
            {
                response.IsSuccess = false;
                response.Message   = "无效的商户号!";
                return(response);
            }

            //追加默认的功能权限
            if (string.Equals(request.Body.SysRole.Code, XCLCMS.Data.CommonHelper.SysRoleConst.SysRoleCodeEnum.MerchantMainRole.ToString(), StringComparison.OrdinalIgnoreCase) || merchant.MerchantSystemType == XCLCMS.Data.CommonHelper.EnumType.MerchantSystemTypeEnum.NOR.ToString())
            {
                request.Body.FunctionIdList.AddRange(XCLCMS.Lib.Permission.PerHelper.NormalMerchantFixedFunctionIDList);
            }
            request.Body.FunctionIdList = request.Body.FunctionIdList.Intersect(allLeafFunctionIds).ToList();

            //必须指定角色信息
            if (string.IsNullOrEmpty(request.Body.SysRole.RoleName))
            {
                response.IsSuccess = false;
                response.Message   = "请指定角色名!";
                return(response);
            }

            //角色code是否存在
            if (!string.IsNullOrEmpty(request.Body.SysRole.Code))
            {
                if (!string.Equals(model.Code, request.Body.SysRole.Code, StringComparison.OrdinalIgnoreCase) && this.sysRoleBLL.IsExistCode(request.Body.SysRole.Code))
                {
                    response.IsSuccess = false;
                    response.Message   = string.Format("角色标识【{0}】已存在!", request.Body.SysRole.Code);
                    return(response);
                }
            }

            //限制商户
            if (base.IsOnlyCurrentMerchant && request.Body.SysRole.FK_MerchantID != base.CurrentUserModel.FK_MerchantID)
            {
                response.IsSuccess = false;
                response.Message   = "只能在自己所属的商户下面修改角色信息!";
                return(response);
            }

            //普通商户的权限是否已越界
            if (merchant.MerchantSystemType == XCLCMS.Data.CommonHelper.EnumType.MerchantSystemTypeEnum.NOR.ToString())
            {
                var normalFunIds = XCLCMS.Lib.Permission.PerHelper.GetNormalMerchantFunctionIDList();
                if (request.Body.FunctionIdList.IsNotNullOrEmpty())
                {
                    if (request.Body.FunctionIdList.Exists(k => !normalFunIds.Contains(k)))
                    {
                        response.IsSuccess = false;
                        response.Message   = "该角色的权限已越界!";
                        return(response);
                    }
                }
            }

            #endregion 数据校验

            model.Code        = request.Body.SysRole.Code;
            model.Remark      = request.Body.SysRole.Remark;
            model.RoleName    = request.Body.SysRole.RoleName;
            model.Sort        = request.Body.SysRole.Sort;
            model.UpdaterID   = base.CurrentUserModel.UserInfoID;
            model.UpdaterName = base.CurrentUserModel.UserName;
            model.UpdateTime  = DateTime.Now;
            model.Weight      = request.Body.SysRole.Weight;

            XCLCMS.Data.BLL.Strategy.SysRole.SysRoleContext sysRoleContext = new Data.BLL.Strategy.SysRole.SysRoleContext();
            sysRoleContext.CurrentUserInfo = base.CurrentUserModel;
            sysRoleContext.SysRole         = model;
            sysRoleContext.FunctionIdList  = request.Body.FunctionIdList;
            sysRoleContext.HandleType      = Data.BLL.Strategy.StrategyLib.HandleType.UPDATE;

            XCLCMS.Data.BLL.Strategy.ExecuteStrategy strategy = new Data.BLL.Strategy.ExecuteStrategy(new List <Data.BLL.Strategy.BaseStrategy>()
            {
                new XCLCMS.Data.BLL.Strategy.SysRole.SysRole(),
                new XCLCMS.Data.BLL.Strategy.SysRole.SysRoleFunction()
            });
            strategy.Execute <XCLCMS.Data.BLL.Strategy.SysRole.SysRoleContext>(sysRoleContext);

            if (strategy.Result != Data.BLL.Strategy.StrategyLib.ResultEnum.FAIL)
            {
                response.Message   = "修改成功!";
                response.IsSuccess = true;
            }
            else
            {
                response.Message   = strategy.ResultMessage;
                response.IsSuccess = false;
                XCLNetLogger.Log.WriteLog(XCLNetLogger.Config.LogConfig.LogLevel.ERROR, "修改角色信息失败", strategy.ResultMessage);
            }

            return(response);
        }