Example #1
0
        public ActionResult RegisterUser(UserInputDTO user)
        {
            User u = new User {
                UserName = user.UserName, Password = user.Password, Address = user.Address
            };
            string msgOut = _repository.RegisterUser(u);

            return(Ok(msgOut));
        }
Example #2
0
 public void RegisterUser(UserInputDTO user)
 {
     userService.CreateUser(new User
     {
         Name     = user.Name,
         Email    = user.Email,
         Password = user.Password
     });
 }
        public ActionResult <string> Login(UserInputDTO credentials)
        {
            string token = authenticationService.LoginUser(credentials.Username, credentials.Password);

            if (token == null)
            {
                return(BadRequest("Invalid credentials!"));
            }

            return(Ok(token));
        }
Example #4
0
        public IActionResult Post(UserInputDTO urlInputDTO)
        {
            User u = _usersService.CreateUser(urlInputDTO.ID);

            if (u == null)
            {
                return(Conflict());
            }

            return(Created("api/users/" + u.ID + "/stats", u));
        }
Example #5
0
        public async Task <UserDTO> CreateUser(UserInputDTO inputDTO)
        {
            var newUser = new User(inputDTO.Name, inputDTO.Email);

            if (newUser.Valid)
            {
                await _collection.InsertOneAsync(newUser);

                return(_mapper.Map <UserDTO>(newUser));
            }
            return(null);
        }
Example #6
0
        public async Task <UserDTO> UpdateUser(Guid id, UserInputDTO inputDTO)
        {
            var filter = Builders <User> .Filter.Eq(u => u.Id, id);

            var update = Builders <User> .Update.Set(u => u.Name, inputDTO.Name).
                         Set(u => u.Email, inputDTO.Email).
                         Set(u => u.DateUpdated, DateTime.Now);

            await _collection.UpdateOneAsync(filter, update);

            return(_mapper.Map <UserDTO>(await LoadById(id)));
        }
Example #7
0
 /// <summary>
 /// Method to insert/save User record
 /// </summary>
 /// <param name="user">User records to be inserted/saved</param>
 /// <returns></returns>
 public HttpResponseMessage Post(UserInputDTO userInputDto)
 {
     if (true)//TODO: replace this with validation logic ModelState.IsValid
     {
         var user = Mapper.Map <User>(userInputDto);
         _userService.Add(user);
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, user);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = user.Id }));
         return(response);
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
Example #8
0
 /// <summary>
 /// Method to update user
 /// </summary>
 /// <param name="user">Users record to be updated</param>
 /// <returns></returns>
 public IHttpActionResult Put(UserInputDTO value)
 {
     if (true)//TODO: replace this with validation logic ModelState.IsValid
     {
         var searchedUser = _userService.FindBy(t => t.Id == value.Id);
         if (value == null)
         {
             return(BadRequest("Cannot update user/ user not found"));
         }
         var toBeUpdatedRecord = Mapper.Map <User>(value);
         _userService.Update(searchedUser);
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Example #9
0
 public async Task <UserDTO> UpdateUser([Required] Guid id,
                                        [FromBody] UserInputDTO inputDTO)
 {
     return(await _repository.UpdateUser(id, inputDTO));
 }
Example #10
0
 public async Task <UserDTO> CreateUser([FromBody] UserInputDTO inputDTO)
 {
     return(await _repository.CreateUser(inputDTO));
 }
Example #11
0
 public void CreateUser(UserInputDTO user)
 {
     this.userAppService.RegisterUser(user);
 }