// [Authorize(Policy = "Customer")] public async Task <IActionResult> GetAdminResponses(PaginationParameters resourceParameters) { var id = User.Claims.FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.Id)?.Value; var responses = _usersRepository.GetAdminResponses(id, resourceParameters); var prevLink = responses.HasPrevious ? _resourceUriHelper.CreateResourceUri(resourceParameters, ResourceUriType.PrevoiusPage, nameof(GetAdminResponses)) : null; var nextLink = responses.HasNext ? _resourceUriHelper.CreateResourceUri(resourceParameters, ResourceUriType.NextPage, nameof(GetAdminResponses)) : null; Response.Headers.Add("X-Pagination", Helpers.PaginationMetadata.GeneratePaginationMetadata(responses, resourceParameters, prevLink, nextLink)); var responsesDto = new List <AdminResponseToReturnDto>(); foreach (var v in responses) { var dto = Mapper.Map <AdminResponseToReturnDto>(v); dto.Email = _usersRepository.GetAdminById(v.AdminId).Identity.Email; responsesDto.Add(dto); } return(Ok(responsesDto)); }
public async Task <IActionResult> GetCommentsForDriver(Guid driverId, [FromQuery] PaginationParameters paginationParameters) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var driver = _usersRepository.GetDriverById(driverId); if (driver == null) { return(NotFound()); } var comments = await _usersRepository.GetDriverComments(driverId, paginationParameters); var prevLink = comments.HasPrevious ? _resourceUriHelper.CreateResourceUri(paginationParameters, ResourceUriType.PrevoiusPage, nameof(GetCommentsForDriver)) : null; var nextLink = comments.HasNext ? _resourceUriHelper.CreateResourceUri(paginationParameters, ResourceUriType.NextPage, nameof(GetCommentsForDriver)) : null; Response.Headers.Add("X-Pagination", Helpers.PaginationMetadata.GeneratePaginationMetadata(comments, paginationParameters, prevLink, nextLink)); var commentsDto = new List <DriverCommentDto>(); foreach (var c in comments) { var comment = Mapper.Map <DriverCommentDto>(c); var user = _usersRepository.GetCustomerById(c.CustomerId); comment.PictureId = user.Identity.ProfilePicture?.Id; comment.FirstName = user.Identity.FirstName; comment.LastName = user.Identity.LastName; commentsDto.Add(comment); } return(Ok(commentsDto)); }
public async Task <IActionResult> GetDriverHistory(TripHistoryResourceParameters resourceParameters) { var driverId = User.Claims.FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.DriverId)?.Value; var trips = _tripsRepository.GetTripHistoriesForDriver(Guid.Parse(driverId), resourceParameters); var prevLink = trips.HasPrevious ? _resourceUriHelper.CreateResourceUri(resourceParameters, ResourceUriType.PrevoiusPage, nameof(GetDriverHistory)) : null; var nextLink = trips.HasNext ? _resourceUriHelper.CreateResourceUri(resourceParameters, ResourceUriType.NextPage, nameof(GetDriverHistory)) : null; Response.Headers.Add("X-Pagination", Helpers.PaginationMetadata.GeneratePaginationMetadata(trips, resourceParameters, prevLink, nextLink)); var tripsToReturn = new List <TripHistoryDto>(); foreach (var t in trips) { var from = t.From; var to = t.To; tripsToReturn.Add(new TripHistoryDto() { CustomerId = t.CustomerId, DriverId = t.DriverId, Rating = t.Rating, Id = t.Id, From = Helpers.Location.PointToPlaceDto(from), To = Helpers.Location.PointToPlaceDto(to), FinishTime = t.FinishTime, Price = t.Price, Distance = t.Distance }); } return(Ok(tripsToReturn)); }
public async Task <IActionResult> GetUsers(UserResourceParameters resourceParameters) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var users = await _usersRepository.GetUsers(resourceParameters); var prevLink = users.HasPrevious ? _resourceUriHelper.CreateResourceUri(resourceParameters, ResourceUriType.PrevoiusPage, nameof(GetUsers)) : null; var nextLink = users.HasNext ? _resourceUriHelper.CreateResourceUri(resourceParameters, ResourceUriType.NextPage, nameof(GetUsers)) : null; Response.Headers.Add("X-Pagination", Helpers.PaginationMetadata.GeneratePaginationMetadata(users, resourceParameters, prevLink, nextLink)); List <UserDto> userDtos = new List <UserDto>(); foreach (var user in users) { var userDto = Mapper.Map <UserDto>(user); var claims = await _userManager.GetClaimsAsync(user); foreach (var c in claims) { if (c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.Rol) { userDto.Roles.Add(c.Value); } if (c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.CustomerId || c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.DriverId || c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.AdminId) { userDto.Ids[c.Type] = c.Value; } } userDto.ProfilePictureId = user.ProfilePicture?.Id; userDtos.Add(userDto); } return(Ok(userDtos)); }