示例#1
0
        public ResponseRoleAdd RoleAdd(RequestRoleAdd request)
        {
            ResponseRoleAdd response = new ResponseRoleAdd();

            using (cnn = GetConnection())
            {
                var ts = cnn.BeginTransaction();
                try
                {
                    var user = UserInfoGetButAccount(request.Token, ts);

                    var data = cnn.Query("select * from tks_fas_role where name=@Name",
                                         new { Name = request.Data.Name }, ts);
                    if (data.Count() > 0)
                    {
                        throw new NormalException("角色已经存在");
                    }

                    request.Data.Id         = Guid.NewGuid().ToString("N");
                    request.Data.CreateDate = DateTime.Now;
                    request.Data.CreateUser = user.User.UserName;
                    cnn.Insert <TKS_FAS_Role>(request.Data, ts);
                    if (request.Permission.Length > 0)
                    {
                        foreach (var item in request.Permission)
                        {
                            TKS_FAS_Role2Permission Role2Permission = new TKS_FAS_Role2Permission();
                            Role2Permission.Id         = Guid.NewGuid().ToString("N");
                            Role2Permission.RoleId     = request.Data.Id;
                            Role2Permission.Permission = item;

                            if (item == "平台管理员")
                            {
                                Role2Permission.PLevel = 1;
                            }
                            else if (item == "组织机构管理员")
                            {
                                Role2Permission.PLevel = 10;
                            }
                            else if (item == "组织机构会计")
                            {
                                Role2Permission.PLevel = 20;
                            }
                            cnn.Insert <TKS_FAS_Role2Permission>(Role2Permission, ts);
                        }
                    }
                    ts.Commit();
                    response.Id        = request.Data.Id;
                    response.IsSuccess = true;
                    response.Message   = "新增成功";
                    return(response);
                }
                catch (Exception ex)
                {
                    ts.Rollback();
                    return(this.DealException(response, ex) as ResponseRoleAdd);
                }
            }
        }
示例#2
0
        public ResponseRoleUpdate RoleUpdate(RequestRoleUpdate request)
        {
            ResponseRoleUpdate response = new ResponseRoleUpdate();

            using (cnn = GetConnection())
            {
                var ts = cnn.BeginTransaction();

                try
                {
                    var user = UserInfoGetButAccount(request.Token, ts);
                    var role = cnn.Query <TKS_FAS_Role>("select * from tks_fas_role where name=@Name and id<>@Id",
                                                        new
                    {
                        Name = request.Data.Name
                        ,
                        Id = request.Data.Id
                    }, ts);
                    if (role.Count() > 0)
                    {
                        throw new NormalException("角色名已经存在");
                    }

                    request.Data.UpdateUser = user.User.UserName;
                    request.Data.UpdateDate = DateTime.Now;

                    string sql = @"update tks_fas_role set 
                        name=@Name,
                        memo=@Memo,
                        type=@Type,
                        updateUser=@UpdateUser,
                        updateDate=@UpdateDate 
                        where id=@Id";
                    cnn.Execute(sql, request.Data, ts);
                    cnn.Execute("delete from TKS_FAS_Role2Permission where RoleId=@RoleId",
                                new { RoleId = request.Data.Id }, ts);
                    foreach (var item in request.Permission)
                    {
                        TKS_FAS_Role2Permission _row = new TKS_FAS_Role2Permission();
                        _row.Id         = Guid.NewGuid().ToString("N");
                        _row.RoleId     = request.Data.Id;
                        _row.Permission = item;
                        if (item == "平台管理员")
                        {
                            _row.PLevel = 1;
                        }
                        else if (item == "组织机构管理员")
                        {
                            _row.PLevel = 10;
                        }
                        else if (item == "组织机构会计")
                        {
                            _row.PLevel = 20;
                        }
                        cnn.Insert <TKS_FAS_Role2Permission>(_row, ts);
                    }
                    ts.Commit();
                    response.IsSuccess = true;
                    response.Message   = "更新成功";
                    return(response);
                }
                catch (Exception ex)
                {
                    ts.Rollback();
                    return(this.DealException(response, ex) as ResponseRoleUpdate);
                }
            }
        }