示例#1
0
        public ActionResult SetOrg(SetOrgRequest request)
        {
            var flag = false;
            var msg  = string.Empty;

            if (request.OrgIds.IsNullOrEmpty())
            {
                msg = "请选择机构!";
                return(Json(new { success = flag, msg = msg }, JsonRequestBehavior.AllowGet));
            }

            var rs = _userService.SetOrg(request);

            if (rs.ReturnCode == ReturnCodeType.Success && rs.Content == true)
            {
                flag = true;
                msg  = "设置机构成功!";
            }
            else
            {
                msg = rs.Message.IsNullOrEmpty() ? "设置机构失败!" : rs.Message;
            }

            return(Json(new { success = flag, msg = msg }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public ActionResult SetOrg(SetOrgRequest request)
        {
            var flag = false;
            var msg  = string.Empty;

            if (request.OrgIds.IsNullOrEmpty())
            {
                msg = "请选择机构!";
                return(Json(new { success = flag, msg = msg }, JsonRequestBehavior.AllowGet));
            }

            using (var factory = new ChannelFactory <IRightsUserService>("*"))
            {
                var client = factory.CreateChannel();
                var rs     = client.SetOrg(request);
                if (rs.ReturnCode == ReturnCodeType.Success && rs.Content == true)
                {
                    flag = true;
                    msg  = "设置机构成功!";
                }
                else
                {
                    msg = rs.Message.IsNullOrEmpty() ? "设置机构失败!" : rs.Message;
                }
            }

            return(Json(new { success = flag, msg = msg }, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        /// <summary>
        /// 为所选用户设置机构
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool SetOrg(SetOrgRequest request)
        {
            //先删除所选用户原来的所属机构
            //再新增所选用户选择的所属机构
            //一定要先删除再添加,而且要使用事务
            var result      = false;
            var userIds     = request.UserIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.ToInt()).OrderBy(p => p).ToList();
            var orgIds      = request.OrgIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.ToInt()).OrderBy(p => p).ToList();
            var addUserOrgs = new List <TRightsUserOrganization>();//待添加的用户机构

            foreach (var userId in userIds)
            {
                foreach (var orgId in orgIds)
                {
                    var addUserOrg = new TRightsUserOrganization()
                    {
                        UserId         = userId,
                        OrganizationId = orgId
                    };
                    addUserOrgs.Add(addUserOrg);
                }
            }

            using (var conn = DapperHelper.CreateConnection())
            {
                var trans = conn.BeginTransaction();

                try
                {
                    //先删除
                    conn.Execute(@"DELETE FROM dbo.t_rights_user_organization WHERE user_id IN @UserIds;", new { @UserIds = userIds }, trans);

                    //后添加
                    conn.Execute(@"INSERT INTO dbo.t_rights_user_organization VALUES  (@UserId,@OrganizationId);", addUserOrgs, trans);

                    trans.Commit();
                    result = true;
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                }
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// 为所选用户设置机构
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ServiceResult <bool> SetOrg(SetOrgRequest request)
        {
            //先删除所选用户原来的所属机构
            //再新增所选用户选择的所属机构
            var result = new ServiceResult <bool>
            {
                ReturnCode = ReturnCodeType.Error
            };

            var rs = userDao.SetOrg(request);

            if (rs == true)
            {
                result.ReturnCode = ReturnCodeType.Success;
                result.Content    = true;
            }

            return(result);
        }