Example #1
0
        public async Task <IActionResult> AddAsync(AddUserVO vo)
        {
            var currentUserId   = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var currentUserName = User.FindFirstValue(ClaimTypes.Name);
            var result          = await userService.AddUserAsync(vo, new Guid(currentUserId), currentUserName);

            return(Json(result));
        }
Example #2
0
        public async Task <BizServiceResponse> AddUserAsync(AddUserVO vo, Guid currentUserId, string currentUserLoginName)
        {
            if (vo.Type == UserType.SuperAdmin)
            {
                return(new BizServiceResponse(BizServiceResponseCode.Failed, "添加用户失败:不允许添加超级管理员"));
            }
            var user = await userRepository.ListAsync(new FindUserSpecification(vo.LoginName));

            if (user != null && user.Count > 0)
            {
                return(new BizServiceResponse(BizServiceResponseCode.Failed, "添加用户失败:用户已存在"));
            }
            // TODO
            var now    = DateTime.UtcNow;
            var entity = new User
            {
                Guid               = Guid.NewGuid(),
                Avatar             = "",
                CreateTime         = now,
                CreateUserId       = currentUserId,
                CreateUserName     = currentUserLoginName,
                LastModifyTime     = now,
                LastModifyUserId   = currentUserId,
                LastModifyUserName = currentUserLoginName,
                Description        = null,
                Status             = Status.Normal,
                DOB          = vo.DOB,
                IsDeleted    = IsDeleted.No,
                LoginName    = vo.LoginName,
                NickName     = vo.NickName,
                PasswordHash = vo.Password.MD5Hash(),
                Type         = vo.Type
            };
            var addResult = await userRepository.AddAsync(entity);

            if (addResult.IsNull())
            {
                return(new BizServiceResponse(BizServiceResponseCode.Failed, "添加用户失败"));
            }
            else
            {
                return(new BizServiceResponse(BizServiceResponseCode.Success, "添加用户成功"));
            }
        }