Example #1
0
        public ActionResult OrderUser()
        {
            //获取参数
            var type    = this.Request["type"].SafeConvert().ToStr();
            var userIds = this.Request["userIds"].StringHelper().SplitToList(",", StringSplitOptions.RemoveEmptyEntries);

            if (type.Length == 0)
            {
                throw new QWF.Framework.GlobalException.UIValidateException("type参数类型不正确");
            }

            if (userIds == null)
            {
                throw new QWF.Framework.GlobalException.UIValidateException("请选择一条记录");
            }

            //
            Web.ResultWebData result = new Web.ResultWebData();
            result.Success = true;
            result.Message = "success";

            var userServices = MainServices.CreateWebAppServices.GetUserServices();

            IOC.IUserIoc ioc = Iocs.GetInstance().Resolve <IOC.IUserIoc>();
            if (ioc != null)
            {
                ioc.OrderUserBegin(type, userIds);
            }

            try
            {
                userServices.OrderUser(type, userIds);

                if (ioc != null)
                {
                    ioc.OrderUserSuccess(type, userIds);
                }
            }

            catch (Exception ex)
            {
                ioc.OrderUserFail(type, userIds);
                throw ex;
            }

            //输出JSON
            return(this.Content(Newtonsoft.Json.JsonConvert.SerializeObject(result)));
        }
Example #2
0
        public ActionResult SaveUser()
        {
            //获取参数
            var svrUser = new Services.SvrModels.SvrUserInfo();

            svrUser.OrgId       = this.Request["orgId"].SafeConvert().ToInt32(0);
            svrUser.UserName    = this.Request["userName"].SafeConvert().ToStr();
            svrUser.PassWord    = this.Request["password"].SafeConvert().ToStr();
            svrUser.UserId      = this.Request["userId"].SafeConvert().ToInt32(0);
            svrUser.Realname    = this.Request["realname"].SafeConvert().ToStr();
            svrUser.Fax         = this.Request["fax"].SafeConvert().ToStr();
            svrUser.Tel         = this.Request["tel"].SafeConvert().ToStr();
            svrUser.Phone       = this.Request["phone"].SafeConvert().ToStr();
            svrUser.Email       = this.Request["email"].SafeConvert().ToStr();
            svrUser.QQ          = this.Request["qq"].SafeConvert().ToStr();
            svrUser.Weixin      = this.Request["weixin"].SafeConvert().ToStr();
            svrUser.Position    = this.Request["position"].SafeConvert().ToStr();
            svrUser.Leader      = this.Request["leader"] == null ? false:true;
            svrUser.UserRemarks = this.Request["userRemarks"].SafeConvert().ToStr();

            if (svrUser.UserId == 0)
            {
                if (svrUser.PassWord.StrValidatorHelper().StrIsNullOrEmpty())
                {
                    throw new QWF.Framework.GlobalException.UIValidateException("请填写密码");
                }
            }

            //密码处理
            if (!svrUser.PassWord.StrValidatorHelper().StrIsNullOrEmpty())
            {
                svrUser.PassWord = svrUser.PassWord.StringHelper().EncodeMD5();
            }
            //
            Web.ResultWebData result = new Web.ResultWebData();
            result.Success = true;
            result.Message = "success";

            int userId = 0;

            //控制反转
            IOC.IUserIoc userIoc = Iocs.GetInstance().Resolve <IOC.IUserIoc>();
            try
            {
                if (svrUser.UserId == 0)
                {
                    //新增前
                    if (userIoc != null)
                    {
                        svrUser = userIoc.CreateBegin(svrUser);
                    }

                    //新增
                    userId = MainServices.CreateWebAppServices.GetUserServices().CreateUser(svrUser);

                    //创建成功
                    if (userIoc != null)
                    {
                        userIoc.CreateSuccess(userId);
                    }
                }
                else
                {
                    //编辑

                    if (userIoc != null)
                    {
                        svrUser = userIoc.UpdateBegin(svrUser);
                    }

                    userId = MainServices.CreateWebAppServices.GetUserServices().UpdateUser(svrUser);

                    if (userIoc != null)
                    {
                        userIoc.UpdateSuccess(userId);
                    }
                }
            }
            catch (Exception ex)
            {
                if (userIoc != null)
                {
                    userIoc.CreateFail(svrUser, ex);
                }

                throw ex;
            }
            //输出用户ID
            result.Data = new { userId = userId };
            //输出JSON
            return(this.Content(Newtonsoft.Json.JsonConvert.SerializeObject(result)));
        }