コード例 #1
0
        public async Task <IResponseDTO> RegisterAdmin([FromBody] UserRegisterationRequest request)
        {
            var authResponse = await _identityService.RegisterAdminAsync(request.FullName, request.UserName, request.Email, request.Password, request.Roles, request.PhoneNumber);

            authResponse.Data = null;
            return(authResponse);
        }
コード例 #2
0
        public async Task <IResponseDTO> GetAllUsersAsync(int pageNumber = 0, int pageSize = 0)
        {
            var appUsers      = new List <ApplicationUser>();
            var appUserstotal = new List <ApplicationUser>();
            var total         = 0;

            try
            {
                List <ApplicationRole> role = new List <ApplicationRole>();

                role = _unitOfWork.ApplicationRole.Get(x => x.UserType == UserType.Admin).ToList();
                //   total = _userManager.Users.Include(u => u.UserRoles).ThenInclude(ur => ur.Role).Where(x=>x.confirmed==true).Count();
                foreach (var Role in role)
                {
                    var usersInRole = await _userManager.GetUsersInRoleAsync(Role.Name);

                    var usersInRoleIds = usersInRole.Select(x => x.Id);
                    var users          = _unitOfWork.ApplicationUser.Get(x => x.confirmed == true, page: pageNumber, Take: pageSize).Where(u => usersInRoleIds.Contains(u.Id)).ToList();
                    appUsers.AddRange(users);
                }
                foreach (var Role in role)
                {
                    var usersInRole = await _userManager.GetUsersInRoleAsync(Role.Name);

                    var usersInRoleIds = usersInRole.Select(x => x.Id);
                    var users          = _unitOfWork.ApplicationUser.Get(x => x.confirmed == true).Where(u => usersInRoleIds.Contains(u.Id)).ToList();
                    appUserstotal.AddRange(users);
                }


                var ApplicationRoleDto = new List <UserRegisterationRequest>();
                foreach (var Model in appUsers)
                {
                    var Roleid      = _dataContext.UserRoles.FirstOrDefault(x => x.UserId == Model.Id);
                    var Application = new UserRegisterationRequest();
                    Application.Id          = Model.Id;
                    Application.FullName    = Model.FullName;
                    Application.UserName    = Model.UserName;
                    Application.Email       = Model.Email;
                    Application.Roles       = Roleid.RoleId;
                    Application.RoleName    = !string.IsNullOrEmpty(Roleid.RoleId)? _unitOfWork.ApplicationRole.GetByID(Roleid.RoleId).Name:"";
                    Application.PhoneNumber = Model.PhoneNumber;

                    ApplicationRoleDto.Add(Application);
                }

                _response.Data          = ApplicationRoleDto;
                _response.Code          = 200;
                _response.Message       = "OK";
                _response.totalRowCount = appUserstotal.Count;
            }
            catch (Exception ex)
            {
                _response.Data    = null;
                _response.Code    = 400;
                _response.Message = ex.Message;
            }
            return(_response);
        }
コード例 #3
0
        public async Task <IActionResult> Register([FromBody] UserRegisterationRequest request)
        {
            var authResponse = await _identityService.RegisterAsync(request.Email, request.Password);

            if (!authResponse.Success)
            {
                return(BadRequest(new AuthFailedResponse {
                    Errors = authResponse.Errors
                }));
            }

            return(Ok(new AuthSuccessResponse {
                Token = authResponse.Token
            }));
        }
コード例 #4
0
        public async Task <IActionResult> Register([FromBody] UserRegisterationRequest request)
        {
            _log.LogInfo("This is for Registeration service");
            var authResponse = await _identityService.RegisterAsync(request.Email, request.Password).ConfigureAwait(false);



            if (!authResponse.Success)
            {
                return(BadRequest(new AuthFailResponse {
                    Errors = authResponse.Errors
                }));
            }

            return(Ok(new AuthSuccessResponse {
                JwtToken = authResponse.JwtToken, RefreshToken = authResponse.RefreshToken
            }));
        }
コード例 #5
0
        public IActionResult Register([FromBody] UserRegisterationRequest request)
        {
            if (request == null)
            {
                return(BadRequest("Log is null."));
            }
            if (this._userRepository.IsEmailExists(request.Email))
            {
                return(BadRequest("Email exists already"));
            }
            if (this._userRepository.IsUserNameExists(request.UserName))
            {
                return(BadRequest("User Name exists already"));
            }
            User user = request.toUserEntity();

            this._userRepository.Add(user);
            return(Ok(user));
        }
コード例 #6
0
        public async Task <IActionResult> Register([FromBody] UserRegisterationRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new AuthFailResponse {
                    Errors = ModelState.Values.SelectMany(x => x.Errors.Select(x => x.ErrorMessage))
                }));
            }
            var authResponse = await _identityService.RegisterAsync(request.Email, request.Password);

            if (!authResponse.Success)
            {
                return(BadRequest(new AuthFailResponse
                {
                    Errors = authResponse.Errors
                }));
            }
            return(Ok(new AuthSuccessResponse
            {
                Token = authResponse.Token,
                RefreshToken = authResponse.RefreshToken
            }));
        }