コード例 #1
0
        public IActionResult PostUser(UserQuery userQuery)
        {
            var userToPost = new User(userQuery.Id, userQuery.Email);
            var postedUser = usersService.AddUser(userToPost);

            return(CreatedAtAction(nameof(GetUserById), new { id = postedUser.Id }, postedUser));
        }
コード例 #2
0
        public HttpResponse Register(RegisterInputViewModel model)
        {
            if (model.Username.Length < 4 || model.Username.Length > 10)
            {
                return(this.Error("Username must be between 4 and 10 symbols!"));
            }
            if (model.Password.Length < 4 || model.Password.Length > 20)
            {
                return(this.Error("Password must be between 4 and 20 symbols!"));
            }
            if (model.Email.Length < 0)
            {
                return(this.Error("Invalid email"));
            }
            if (model.Password != model.ConfirmPassword)
            {
                return(this.Error("The passwords you entered do not match!"));
            }
            if (usersService.UsernameExists(model.Username))
            {
                return(this.Error("Username already exists!"));
            }
            if (usersService.EmailExists(model.Email))
            {
                return(this.Error("Email already exists!"));
            }
            usersService.AddUser(model.Username, model.Password, model.Email);

            return(this.Redirect("Login"));
        }
コード例 #3
0
        public async Task <IActionResult> Post(Users model)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(model.Name))
                {
                    return(BadRequest("Please enter user name"));
                }
                else if (string.IsNullOrWhiteSpace(model.Age))
                {
                    return(BadRequest("Please enter age"));
                }
                else if (string.IsNullOrWhiteSpace(model.Password))
                {
                    return(BadRequest("Please enter password"));
                }

                model.CreatedOn = DateTime.UtcNow;
                await _usersService.AddUser(model);

                return(Ok("Your user has been added successfully"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
コード例 #4
0
        public void AddUser()
        {
            // Arrange:
            var newUser = new UserViewModel
            {
                FirstName = "new",
                LastName  = "newlast",
                Address   = "newadr",
                Email     = "newemail",
            };
            var prevCount = _usersService.GetUsers().Count();

            // Act:
            _usersService.AddUser(newUser);

            // Assert:

            // Ensure that a new entity object has been created:
            var currentCount = _usersService.GetUsers().Count();

            Assert.AreEqual(prevCount + 1, currentCount);

            // Get access to the entity object and assert that
            // the properties have been set:
            var newEntity = _usersService.GetUsers().Last();

            Assert.AreEqual("new newlast", newEntity.FullName);
        }
コード例 #5
0
        public async Task <ActionResult <User> > AddUser(User user)
        {
            _repository.AddUser(user);
            await _repository.SaveChangeAsync();

            return(CreatedAtAction("GetUserById", new { id = user.Usersid }, user));
        }
コード例 #6
0
        public async Task <IActionResult> Post(UserDto userDto)
        {
            userDto.UserId = Guid.NewGuid();
            var user = await _usersService.AddUser(userDto);

            _rabbitService.Enqueue(JsonConvert.SerializeObject(userDto));
            return(Ok(user));
        }
コード例 #7
0
        public void a_users_service_can_add_a_new_user()
        {
            var userToAdd   = new User(109143, "*****@*****.**");
            var createdUser = usersService.AddUser(userToAdd);

            Assert.Equal(userToAdd, createdUser);
            Assert.Contains(userToAdd, usersService.Users);
        }
コード例 #8
0
        public IActionResult CreateNewUser([FromBody] User user)
        {
            var serviceUser = _usersService.AddUser(user);

            string baseUrl = @"http://localhost:62487";

            return(Created($"{baseUrl}/api/users/{serviceUser.Username}", serviceUser));
        }
コード例 #9
0
        public async Task <JsonResult> CreateUser([FromBody] CreateUserModel model)
        {
            if (!ModelState.IsValid)
            {
                return(ReturnResponse(EServiceActionStatus.BadRequest));
            }
            var result = await _usersService.AddUser(model);

            return(ReturnResponse(result));
        }
コード例 #10
0
        public IActionResult AddUser([FromBody] UserRequest user)
        {
            var result = _userService.AddUser(user);

            if (String.IsNullOrEmpty(result.Error))
            {
                return(Ok(result.id));
            }
            return(BadRequest(result.Error));
        }
コード例 #11
0
        public async Task <IHttpActionResult> AddUser(UserDto userDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _service.AddUser(userDto.Name, userDto.Surname);

            return(Ok(_mapper.Map <ExistingUserDto>(user)));
        }
コード例 #12
0
 public Users Post([FromBody] Users oUsers)
 {
     if (ModelState.IsValid)
     {
         return(_oUsersService.AddUser(oUsers));
     }
     else
     {
         return(null);
     }
 }
コード例 #13
0
ファイル: UsersController.cs プロジェクト: mokv/Messenger
 public void AddUser([FromBody] User user)
 {
     try
     {
         service.AddUser(user);
     }
     catch (ArgumentException)
     {
         throw new HttpResponseException(HttpStatusCode.NotAcceptable);
     }
 }
コード例 #14
0
 public Task <User> AddUser([FromBody] User user)
 {
     if (String.IsNullOrEmpty(user.FIO))
     {
         throw new Exception("Не введено ФИО");
     }
     if (user.DepId == 0)
     {
         throw new Exception("Не введен DepId");
     }
     return(_usersService.AddUser(user));
 }
コード例 #15
0
 public object AddUser(PostUser user)
 {
     if (user == null)
     {
         return(new ReturnResult <Users>(-4, "传入参数错误!"));
     }
     if (user == null || string.IsNullOrEmpty(user.VerificationCode) ||
         string.IsNullOrEmpty(user.Pwd) || string.IsNullOrEmpty(user.PhoneNumber))
     {
         return(new ReturnResult <Users>(-4, "传入参数错误!"));
     }
     return(_UsersService.AddUser(user.PhoneNumber, user.Pwd, user.VerificationCode));
 }
コード例 #16
0
ファイル: UsersController.cs プロジェクト: allo97/Codenames
        public async Task <IActionResult> AddUser([FromBody] UserDto userDto)
        {
            try
            {
                var createdUser = await _userService.AddUser(_mapper.Map <User>(userDto));

                return(Ok(_mapper.Map <UserDto>(createdUser)));
            }
            catch (Exception ex)
            {
                var errorMessage = "There was an error while trying to add User to MongoDB";
                return(BadRequest(errorMessage + "\n" + ex));
            }
        }
コード例 #17
0
ファイル: UsersController.cs プロジェクト: boleae/InnoCv
 public IHttpActionResult AddUser([FromBody] User user)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _usersService.AddUser(user);
             return(Ok(user));
         }
         else
         {
             return(BadRequest(ModelState));
         }
     }
     catch (Exception ex)
     {
         return(Json(new
         {
             Result = HttpStatusCode.InternalServerError,
             Message = ex.Message
         }));
     }
 }
コード例 #18
0
        public IActionResult Create([FromBody] NewUser login)
        {
            var roles = new List <string>();

            roles.Add("User");
            if (_usersService.Count() == 0)
            {
                roles.Add("Admin");
            }
            (bool result, string message) = _usersService.AddUser(login.Name, login.Email, login.Password, roles);
            if (result)
            {
                return(Ok());
            }
            return(BadRequest(message));
        }
コード例 #19
0
ファイル: UsersController.cs プロジェクト: Lulubul/Netflix
        public async Task <IActionResult> Register(UserRegister user)
        {
            if (user == null)
            {
                return(BadRequest($"Parameter is not defined in query {nameof(UserRegister)}"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newUser = await _usersService.AddUser(user);

            return(Ok(newUser));
        }
コード例 #20
0
        public IActionResult AddUser([FromBody] UserViewModel user)
        {
            if (user == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(StatusCode(412));
            }

            var addedUserId = _usersService.AddUser(user);
            var newUser     = _usersService.GetUserById(addedUserId);

            return(CreatedAtRoute("GetUserById", new { userId = addedUserId }, newUser));
        }
コード例 #21
0
ファイル: UsersController.cs プロジェクト: rummic/EOD
        public async Task <ActionResult <ResponseDto <int> > > AddUser([FromBody] AddUserDto userToAdd)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            ResponseDto <int> result = await _usersService.AddUser(userToAdd);

            if (result.HasErrors)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
コード例 #22
0
 public IActionResult AddUser([FromBody] UserView user)
 {
     if (user == null)
     {
         return(BadRequest());
     }
     if (!ModelState.IsValid)
     {
         return(StatusCode(412, "Modelstate is not valid"));
     }
     try {
         var newUser = _usersService.AddUser(user);
         return(CreatedAtRoute("GetUserById", new { userId = newUser.Id }, newUser));
     } catch (AlreadyExistsException e) {
         return(StatusCode(409, e.Message));
     }
 }
コード例 #23
0
        public ActionResult Register()
        {
            var name     = Request.Form["username"];
            var email    = Request.Form["email"];
            var password = _cyberSecurity.EncryptPassword(Request.Form["password"]);

            try
            {
                _sqlUsersService.AddUser(name, email, password);
            }
            catch (Npgsql.PostgresException)
            {
                return(Json("You already registerd. Email address taken!"));
            }

            return(Json("Success!"));
        }
コード例 #24
0
 public IActionResult Register(RegisterViewModel model)
 {
     if (ModelState.IsValid != true)
     {
         return(View());
     }
     if (usersService.Exists(model.Username))
     {
         Model["Error"] = $"Username '{model.Username}' is already taken";
         return(View());
     }
     if (model.Password != model.ConfirmPassword)
     {
         Model["Error"] = $"Passwords do not match";
         return(View());
     }
     usersService.AddUser(model.Username, model.Password, model.Email, model.FullName);
     return(RedirectToAction(Constants.LoginViewRoute));
 }
コード例 #25
0
        public async Task <IActionResult> AddUser([FromBody] CreateUserRequest request)
        {
            var result = _requestValidator.Validate(request);

            if (!result.IsValid)
            {
                {
                    throw new InvalidValueException(result.Errors.Select(e => e.ErrorMessage).Distinct().ToArray());
                }
            }

            var user = _mapper.Map <User>(request);
            await _usersService.AddUser(user);

            return(Ok(new CreateUserResponse()
            {
                UserId = user.UserId
            }));
        }
コード例 #26
0
 public IActionResult AddUser([FromBody] AddUserCommand user)
 {
     try
     {
         return(Ok(_usersService.AddUser(user)));
     }
     catch (DuplicateEmailException)
     {
         return(StatusCode(409));
     }
     catch (DuplicateNameException)
     {
         return(StatusCode(403));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #27
0
        public async Task <OkResult> BotFramework([FromBody] Activity activity)
        {
            try
            {
                if (!_bfService.ExistProviderClient(activity.Conversation.Id, activity.ChannelId,
                                                    activity.From.Id))
                {
                    _bfService.AddProviderClient(new Uri(activity.ServiceUrl), _appCredentials, activity.From, activity.Recipient, activity.Conversation.Id, activity.ChannelId, activity.From.Id);
                    //Создание id по шаблону
                    var id = _bfService.CreateIdentificator(activity.Conversation.Id, activity.ChannelId,
                                                            activity.From.Id);
                    //Проверка наличия пользовалея
                    if (!_usersService.ExistUser(id))
                    {
                        //Добавление пользователя
                        _usersService.AddUser(id, activity.ChannelId, _bfService.SendMessage);
                    }
                }

                //if message
                if (activity.Type == ActivityTypes.Message)
                {
                    //Генерация id
                    var id = _bfService.CreateIdentificator(activity.Conversation.Id, activity.ChannelId,
                                                            activity.From.Id);

                    //Отправка сообщения на обработку
                    //Можно поставить выполнение в ассинхронном режиме
                    await _usersService.GetUser(id).InPoint(_bfService.ActivityToMessage(activity, id));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                //Console.WriteLine(e);
                throw;
            }
            //Проверка наличия Client Provider

            return(Ok());
        }
コード例 #28
0
 //public HttpResponseMessage AddUser([FromBody]User user)
 public string AddUser([FromBody] User user)
 {
     if (user.Username == null || user.Password == null)
     {
         return("0");
     }
     else
     {
         //return new HttpResponseMessage(HttpStatusCode.BadRequest);
         if (_service.AddUser(user) == null)
         {
             //return new HttpResponseMessage(HttpStatusCode.BadRequest);
             return("2");
         }
         else
         {
             //return new HttpResponseMessage(HttpStatusCode.OK);
             return("1");
         }
     }
 }
コード例 #29
0
        public async Task <IActionResult> AddUser([FromBody]  AppUser appUser)
        {
            if (appUser == null)
            {
                return(new BadRequestObjectResult(ApiResponse <string> .ErrorResult(message: "user is not set.", statusCode: HttpStatusCode.BadRequest)));
            }

            var userExist = await _usersService.FindUserAsync(appUser.Email);

            if (userExist != null)
            {
                return(new BadRequestObjectResult(ApiResponse <string> .ErrorResult(message: "User already exist.", statusCode: HttpStatusCode.BadRequest)));
            }

            User user = await _usersService.AddUser(appUser);

            var(accessToken, refreshToken, claims) = await _tokenStoreService.CreateJwtTokens(user, refreshTokenSource : null);

            //_antiforgery.RegenerateAntiForgeryCookies(claims);

            return(new OkObjectResult(ApiResponse <object> .SuccessResult(new { access_token = accessToken, refresh_token = refreshToken })));
        }
        public async Task <IActionResult> RegisterUser([FromBody] AddUserRequest request)
        {
            try
            {
                var validationResult = new RegistrationRequestValidator().ValidateRequest(request);
                if (validationResult != null)
                {
                    return(ValidationProblem(validationResult));
                }

                var result = await _service.AddUser(request.ToUserMap());

                return(Ok(result));
            }
            catch (UserAlreadyExistsException)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, $"User With Username: '******' Already Exists!"));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }