Пример #1
0
 public ResponseUserAdd UserAdd([FromBody] RequestUserAdd request)
 {
     try
     {
         PermissionBLL bll = new PermissionBLL();
         return(bll.UserAdd(request));
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(
                   Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Пример #2
0
        public ResponseUserAdd UserAdd(RequestUserAdd request)
        {
            ResponseUserAdd response = new ResponseUserAdd();

            using (cnn = GetConnection())
            {
                var ts = cnn.BeginTransaction();
                try
                {
                    var    user = UserInfoGetButAccount(request.Token, ts);
                    string pass = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(request.Data.Password, "MD5");

                    request.Data.Password = pass;

                    var data = cnn.Query("select * from tks_fas_User where userName=@UserName",
                                         new { UserName = request.Data.UserName }, ts);
                    if (data.Count() > 0)
                    {
                        throw new NormalException("用户名已经存在");
                    }
                    request.Data.Id         = Guid.NewGuid().ToString("N");
                    request.Data.CreateUser = user.User.UserName;
                    request.Data.CreateDate = DateTime.Now;
                    cnn.Insert <TKS_FAS_User>(request.Data, ts);

                    //org
                    cnn.Execute("delete from tks_fas_user2Node where userid=@UserId",
                                new { UserId = request.Data.Id }, ts);
                    cnn.Insert <TKS_FAS_User2Node>(new TKS_FAS_User2Node
                    {
                        Id     = Guid.NewGuid().ToString("N"),
                        NodeId = user.Node.Id,
                        UserId = request.Data.Id
                    }, 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 ResponseUserAdd);
                }
            }
        }