Beispiel #1
0
        public async Task <IActionResult> GetUser(int id)
        {
            var user = await datingRepository.GetUser(id);

            var photo = user.Photos
                        .SingleOrDefault(x => x.Id == id);
            var photos = user.Photos
                         .Select(x => new PhotoForDetailedDto(id: x.Id,
                                                              url: x.Url,
                                                              description: x.Description,
                                                              dateAdded: x.DateAdded,
                                                              isMain: x.IsMain))
                         .ToArray();
            var userDetails = new UserForDetailedDto(id: user.Id,
                                                     username: user.Username,
                                                     gender: user.Gender,
                                                     age: user.DateOfBirth.CalculateAge(),
                                                     knownAs: user.KnownAs,
                                                     created: user.Created,
                                                     lastActive: user.LastActive,
                                                     introduction: user.Introduction,
                                                     interests: user.Interests,
                                                     city: user.City,
                                                     country: user.Country,
                                                     photoUrl: photo.Url,
                                                     photos: photos);

            return(Ok(userDetails));
        }
Beispiel #2
0
        public async Task <IActionResult> GetUser(int id)
        {
            User user = await _repo.GetUser(id);

            UserForDetailedDto userToReturn = _mapper.Map <UserForDetailedDto>(user);

            return(Ok(userToReturn));
        }
        public async Task <IActionResult> GetUser(int id)
        {
            var user = await _datingRepository.GetUser(id);

            UserForDetailedDto mappedUser = _mapper.Map <UserForDetailedDto>(user);

            return(Ok(mappedUser));
        }
        public async Task <IActionResult> GetUser(int id)
        {
            bool isCurrentUser = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value) == id;
            User user          = await _datingRepo.GetUser(id, isCurrentUser);

            UserForDetailedDto userToReturn = _mapper.Map <UserForDetailedDto>(user);

            return(Ok(userToReturn));
        }
Beispiel #5
0
        public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto)
        {
            if (await _repo.UserExists(userForRegisterDto.Username))
            {
                return(BadRequest("Username already exists"));
            }

            User userToCreate = _mapper.Map <User>(userForRegisterDto);

            User createdUser = await _repo.Register(userToCreate, userForRegisterDto.Password);

            UserForDetailedDto userToReturn = _mapper.Map <UserForDetailedDto>(createdUser);

            return(CreatedAtRoute(nameof(UsersController.GetUser), new { controller = typeof(UsersController).ControllerName(), id = createdUser.Id }, userToReturn));
        }
        public async Task <IActionResult> Register(UserForDetailedDto userForDetailedDto)
        {
            userForDetailedDto.UserName = userForDetailedDto.UserName.ToLower();
            if (await _repo.UserExistAsync(userForDetailedDto.UserName))
            {
                return(BadRequest("Username allready exists"));
            }

            var UserToCreate = new User
            {
                UserName = userForDetailedDto.UserName
            };

            var createUser = await _repo.Register(UserToCreate, userForDetailedDto.Password);

            return(StatusCode(201));
        }
Beispiel #7
0
        public async Task <IActionResult> GetUser(int id)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var userToReturn = new UserForDetailedDto();

            if (id == currentUserId)
            {
                var user = await _repo.GetUserAllPhotos(id);

                userToReturn = _mapper.Map <UserForDetailedDto>(user);
            }
            else
            {
                var user = await _repo.GetUser(id);

                userToReturn = _mapper.Map <UserForDetailedDto>(user);
            }

            return(Ok(userToReturn));
        }
Beispiel #8
0
        public async Task <IActionResult> Register([FromBody] UserForRegisterDto userForRegisterDto)
        {
            // userForRegisterDto.Username = userForRegisterDto.Username.ToLower();
            // if (await _authRepo.UserExists(userForRegisterDto.Username))
            //     return BadRequest("Username already exists");

            User userToCreate = _mapper.Map <User>(userForRegisterDto);

            var result = await _userManager.CreateAsync(userToCreate, userForRegisterDto.Password);

            // var createdUser = await _authRepo.Register(userToCreate, userForRegisterDto.Password);

            UserForDetailedDto userToReturn = _mapper.Map <UserForDetailedDto>(userToCreate);

            if (result.Succeeded)
            {
                return(Ok(new {
                    token = CreateAuthToken(userToCreate),
                    user = userToReturn
                }));
            }

            return(BadRequest(result.Errors));
        }