Пример #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 ResponseRoleAdd RoleAdd([FromBody] RequestRoleAdd request)
 {
     try
     {
         RoleBLL bll = new RoleBLL();
         return(bll.RoleAdd(request));
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(
                   Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }