Ejemplo n.º 1
0
        public async Task <IActionResult> GetAllListingsForUser()
        {
            try
            {
                var id   = HttpContext.User.FindFirst(ClaimTypes.Email).Value;
                var user = await _userManager.FindByEmailAsync(id);

                var allListings = await _listingCommand.GetAllListingsForUserCommand(user.Id);

                var profile = await _userCommand.GetUserProfile(user);

                var reviews = await _userCommand.GetUserReviews(user.Id);

                var response = new GetProfileForUserSettingsResponse()
                {
                    UserListingCollectionDto = allListings,
                    UserProfileDto           = profile,
                    UserProfileReviewList    = reviews
                };

                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.LogError($"error while getting profile for user: {ex}");
                return(StatusCode((int)HttpStatusCode.InternalServerError, "error while getting profile for user"));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetUserProfileById(string id)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(id);

                if (user == null)
                {
                    return(BadRequest("User does not exist"));
                }

                var profile  = _userCommand.GetUserProfile(user).Result;
                var listings = await _listingCommand.GetAllListingsForUserCommand(user.Id);

                var review = await _userCommand.GetUserReviews(user.Id);

                var response = new GetProfileForUserSettingsResponse()
                {
                    UserProfileDto           = profile,
                    UserListingCollectionDto = listings,
                    UserProfileReviewList    = review
                };

                return(Ok(new
                {
                    Profile = response,
                    Success = true,
                    Message = "Successfully loaded profile"
                }));
            }
            catch (Exception e)
            {
                _logger.LogError($"error while getting listing: {e}");
                return(StatusCode((int)HttpStatusCode.InternalServerError, "error while getting listing"));
            }
        }