예제 #1
0
        public async Task <IActionResult> Post([FromBody] sys_user value)
        {
            using (var tran = _context.Database.BeginTransaction())
            {
                try
                {
                    var oldSysUser = _sysUserRpt.FindBy(f => f.UserId == value.UserId);
                    if (oldSysUser.Any())
                    {
                        return(BadRequest(string.Concat(value.UserId, "已经存在。")));
                    }
                    value.CreatedAt = DateTime.Now;
                    value.UpdatedAt = DateTime.Now;
                    value.IsDelete  = false;
                    if (User.Identity is ClaimsIdentity identity)
                    {
                        value.CreatedBy = identity.Name ?? "admin";
                    }
                    _sysUserRpt.Add(value);
                    _sysUserRpt.Commit();

                    if (!string.IsNullOrEmpty(value.RoleIds) && value.RoleIds.Length > 1)
                    {
                        //新增用户角色关系表
                        string[] roles = value.RoleIds.Split(",".ToArray());
                        foreach (var item in roles)
                        {
                            if (!string.IsNullOrEmpty(item))
                            {
                                var userrole = new sys_role_user {
                                    RoleId = int.Parse(item), UserId = value.Id
                                };
                                _sysRoleUserRpt.Add(userrole);
                            }
                        }
                        _sysRoleUserRpt.Commit();
                    }
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    tran.Rollback();
                    return(BadRequest(ex));
                }
            }
            return(new OkObjectResult(value));
        }
 public IActionResult Init([FromServices] IOptions <CodeGenerateOption> options)
 {
     InitSysMenus(options.Value.ControllersNamespace);
     if (!userRepository.Exist(m => m.SysUserName.Equals("admin", StringComparison.OrdinalIgnoreCase) && m.Activable))
     {
         userRepository.Add(new SysUser()
         {
             SysUserName = "******",
             Activable   = true,
             EMail       = "*****@*****.**",
             SysPassword = "******",
             Telephone   = "13888888888"
         });
     }
     return(Ok());
 }
예제 #3
0
        public Task <Unit> Handle(AddUserCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(Task.FromResult(new Unit()));
            }
            // 实例化领域模型,这里才真正的用到了领域模型
            // 注意这里是通过构造函数方法实现
            var sysUserModel = new Sys_User(Guid.NewGuid(), request.UserId, request.UserName, request.Gender, request.PassWord, request.Email, request.Phone, request.TrxTime, null);

            _sysUserRepository.Add(sysUserModel);
            if (Commit())
            {
                //_bus.RaiseEvent(new )
            }


            return(Task.FromResult(new Unit()));
        }
예제 #4
0
 public void InsertAccount(Entities.SysUser account)
 {
     service.Add(account);
 }