Example #1
0
        public async Task <ResultModel> AddUserAsync(AddUserRequestModel requestModel)
        {
            var model = _mapper.Map <AddUserModel>(requestModel);
            await _userService.AddUserAsync(model);

            return(ResultModel.Success("添加成功"));
        }
        public void PostTest()
        {
            User user = GetUser();
            ValidationResponse <User> validationResponse = GetOkValidationResponse();
            AddUserRequestModel       userRequest        = GetAddUserRequestModel();
            UserResponseModel         userResponse       = GetUserResponseModel();

            _mockMapper
            .Setup(mapper => mapper.Map <AddUserRequestModel, User>(userRequest))
            .Returns(user);

            _mockService
            .Setup(serv => serv.Add(user))
            .Returns(validationResponse);

            _mockMapper
            .Setup(mapper => mapper.Map <User, UserResponseModel>(validationResponse.ResponseData))
            .Returns(userResponse);

            IActionResult actionResult = _controller.Post(userRequest);

            CreatedAtActionResult actual = (CreatedAtActionResult)actionResult;
            string actualName            = ((UserResponseModel)actual.Value).FullName;

            Assert.Equal(user.FullName, actualName);
            Assert.Equal(StatusCodes.Status201Created, actual.StatusCode);
        }
Example #3
0
        private async Task <IActionResult> AddUserToForm(AddUserRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var user = await _tenantRepository.GetUserByEmailAsync(model.Email, TenantId);

            if (user == null)
            {
                return(BadRequest("user does not exist on team"));
            }
            var form = await _tenantRepository.GetFormById(model.Id, TenantId);

            if (form == null)
            {
                return(BadRequest("no forms with this Id exists!"));
            }
            var projects = await _tenantRepository.GetUserProjects(model.Email, tenantId : TenantId);

            if (!projects.Any(p => p.Forms.Contains(form)))
            {
                return(BadRequest("user does not have access to this project!"));
            }
            await _tenantRepository.AddUserToForm(user.Id, model.Id, TenantId, model.Role);

            return(Ok());
        }
Example #4
0
        public Task <string> UpdateUser(AddUserRequestModel user)
        {
            var url    = _addressConfig.UpdateUserUrl;
            var result = _client.UploadModel(url, user);

            return(result);
        }
Example #5
0
        public async Task <IActionResult> AddUserToMeeting(string meetingId, AddUserRequestModel reqBody)
        {
            // TODO: parse body and validate request

            var response = await connect.AddUserToMeeting(meetingId, reqBody);

            return(Ok(response));
        }
        public async Task <string> CreateUser()
        {
            var newUser = new AddUserRequestModel();

            newUser.Name       = "test" + GetRandomNum();
            newUser.Mobile     = GetRandomMobile();
            newUser.Department = new[] { 1 };
            var result = await dtManager.CreateUser(newUser);

            return(result);
        }
Example #7
0
        public IActionResult Post([FromBody] AddUserRequestModel userRequest)
        {
            User user = _mapper.Map <AddUserRequestModel, User>(userRequest);
            ValidationResponse <User> validationResponse = _userService.Add(user);

            if (validationResponse.Status == ValidationStatus.Failed)
            {
                return(BadRequest(validationResponse.Message));
            }

            UserResponseModel userResponse = _mapper.Map <User, UserResponseModel>(validationResponse.ResponseData);

            return(CreatedAtAction("GetById", new { id = userResponse.Id }, userResponse));
        }
Example #8
0
        public async Task <ResultModel> AddUser(AddUserRequestModel requestModel)
        {
            try
            {
                var model = _mapper.Map <AddUserModel>(requestModel);
                await _userService.AddUserAsync(model);

                return(ResultModel.Success("添加成功"));
            }
            catch (InvalidOperationException ex)
            {
                return(ResultModel.Fail(ex.Message));
            }
        }
        public async Task <string> UpdateUser()
        {
            string dptId = "1";
            var    departmentUserListStr = await dtManager.GetDepartmentUserList(dptId);

            var departmentUserList = JsonConvert.DeserializeObject <DepartmentUserResponseModel>(departmentUserListStr);
            var newUser            = new AddUserRequestModel();

            newUser.Name   = "testUpdate" + GetRandomNum();
            newUser.Userid = departmentUserList.UserList.Last().UserId;
            var result = await dtManager.UpdateUser(newUser);

            return(result);
        }
Example #10
0
        public async Task AddAsync(AddUserRequestModel requestModel)
        {
            var user = await userRepository.GetByCPFAsync(requestModel.CPF);

            switch (user == null)
            {
            case true:
            {
                await userRepository.AddAsync(mapper.Map <UserModel>(requestModel));

                break;
            }

            case false: throw new Exception("The CPF already exists.");
            }
        }
Example #11
0
        public async Task <IActionResult> AddUserToTeam(AddUserRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            //check if user has account on system
            var password        = string.Empty;
            var applicationUser = await _userManager.FindByEmailAsync(model.Email);

            if (applicationUser == null)
            {
                applicationUser = new ApplicationUser {
                    Email = model.Email, UserName = model.Email
                };
                password = PasswordHelper.CreatePassword(7);

                var result = await _userManager.CreateAsync(applicationUser, password);

                if (!result.Succeeded)
                {
                    return(BadRequest(new ErrorResponse
                    {
                        ErrorDescription = "Your Email or Password is Incorrect"
                    }));
                }

                //email password to user
            }
            //we have an applicationUser
            var teamUser = await _tenantRepository.GetUserByEmailAsync(model.Email, TenantId);

            if (teamUser != null)
            {
                return(new BadRequestObjectResult(new { error = "a user with that email already exists in this team" }));
            }
            teamUser = new User
            {
                ApplicationUserId = applicationUser.Id, Email = model.Email, UserRole = model.Role
            };
            await _tenantRepository.AddUserToTeam(teamUser, TenantId);

            return(Ok(new { Message = $"advice user to check email for confirmation", password }));
        }
        public async Task <ResultModel> AddUser(AddUserRequestModel requestModel)
        {
            try
            {
                var model = _mapper.Map <AddUserModel>(requestModel);
                await _userService.AddUserAsync(model);

                return(ResultModel.Success("添加成功"));
            }
            catch (AspectInvocationException ex)
            {
                return(ResultModel.Fail(ex.InnerException?.Message));
            }
            catch (MateralConfigCenterException ex)
            {
                return(ResultModel.Fail(ex.Message));
            }
        }
        public void PostUserAlreadyExistTest()
        {
            User user = GetUser();
            ValidationResponse <User> validationResponse = GetFailedValidationResponse();
            AddUserRequestModel       userRequest        = GetAddUserRequestModel();

            _mockMapper
            .Setup(mapper => mapper.Map <AddUserRequestModel, User>(userRequest))
            .Returns(user);

            _mockService
            .Setup(serv => serv.Add(user))
            .Returns(validationResponse);

            IActionResult actionResult = _controller.Post(userRequest);

            BadRequestObjectResult actual = (BadRequestObjectResult)actionResult;

            Assert.Equal(StatusCodes.Status400BadRequest, actual.StatusCode);
        }
Example #14
0
        public async Task <IActionResult> AddUserToProject(AddUserRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var projects = await _tenantRepository.GetUserProjects(model.Email, TenantId);

            if (projects != null && projects.Any())
            {
                return(BadRequest($"user {model.Email} already in project"));
            }
            var user = await _tenantRepository.GetUserByEmailAsync(model.Email, tenantId : TenantId);

            if (user == null)
            {
                return(BadRequest("this user does not exist on team"));
            }
            await _tenantRepository.AddProjectUser(user.Id, model.Id, TenantId, model.Role);

            return(new OkObjectResult(new { Message = $"User {model.Email} added to project {model.Id}" }));
        }
        public IActionResult AddUser([FromBody] AddUserRequestModel requestModel)
        {
            try
            {
                var userResponse = this.userServiceClient.AddUser(new AddUserRequest
                {
                    Username   = requestModel.Username,
                    Firstname  = requestModel.Firstname,
                    Lastname   = requestModel.Lastname,
                    CustomerId = new UUID {
                        Value = requestModel.CustomerId.ToString()
                    },
                    StatusId = requestModel.StatusId
                });

                return(Ok(userResponse.Id));
            }
            catch
            {
                return(StatusCode(
                           (int)HttpStatusCode.InternalServerError,
                           "Could not create user"));
            }
        }
        public async Task <IActionResult> Post([FromBody] AddUserRequestModel request)
        {
            await mediator.Send(request);

            return(Accepted());
        }
Example #17
0
        public async Task <IActionResult> Post([FromBody] AddUserRequestModel requestModel)
        {
            await userService.AddAsync(requestModel);

            return(Ok("User created successfully."));
        }
Example #18
0
 public ApiResultModel <int> Add(AddUserRequestModel requestModel)
 {
     throw new System.NotImplementedException();
 }
Example #19
0
        public async Task <ResultModel> AddUserAsync(AddUserRequestModel requestModel)
        {
            var resultModel = await SendPutAsync <ResultModel>($"{_controllerUrl}AddUser", requestModel);

            return(resultModel);
        }