public async Task <IHttpActionResult> GetUsersPaging(int?pageSize, int?page = 1) { if (pageSize == null || pageSize < 0 || page < 0 || page == null) { return(BadRequest()); } var requestResult = await _hc.GetAsync(_externalUser.GetLink()); if (!requestResult.IsSuccessStatusCode) { return(Conflict()); } var data = await requestResult .Content .ReadAsAsync <IEnumerable <UserModel> >(); var mappedUserViewModel = Mapper.Map <IEnumerable <UserModel>, IEnumerable <UserViewModel> >(data); foreach (var item in mappedUserViewModel) { item.Links = new List <LinkHATEOAS>() { CreatorHateoas.CreateHateoas("self", $"{Url.Link("DefaultApi", new { id = item.Id})}", "GET") }; } return(Ok(_pagination.GetPaging(mappedUserViewModel, (int)pageSize, (int)page))); }
public async Task <IHttpActionResult> GetUsers(long id) { var requestResult = await _hc.GetAsync(_externalUser.GetLink()); if (!requestResult.IsSuccessStatusCode) { return(Conflict()); } var data = await requestResult .Content .ReadAsAsync <IEnumerable <UserModel> >(); var dataById = data.FirstOrDefault(x => x.Id == id); if (dataById == null) { return(NotFound()); } var mappedUserViewModel = Mapper.Map <UserModel, UserViewModel>(dataById); mappedUserViewModel.Links = new List <LinkHATEOAS>() { CreatorHateoas.CreateHateoas("self", $"{Request.RequestUri.AbsoluteUri}", "GET") }; return(Ok(mappedUserViewModel)); }
public async Task <IHttpActionResult> GetUserAlbums(long id) { var asyncAlbums = await _hc.GetAsync(_externalAlbum.GetLink()); if (!asyncAlbums.IsSuccessStatusCode) { return(Conflict()); } var allAlbums = await asyncAlbums .Content .ReadAsAsync <IEnumerable <Album> >(); var filterById = allAlbums.Where(x => x.UserId == id); foreach (var item in filterById) { item.Links = new List <LinkHATEOAS>() { CreatorHateoas.CreateHateoas("self", $"{Url.Link("DefaultApi",new { id = item.Id})}", "GET") }; } var mappedAlbumViewModel = Mapper.Map <IEnumerable <Album>, IEnumerable <AlbumInfoViewModel> >(filterById); return(Ok(mappedAlbumViewModel)); }
public async Task <IHttpActionResult> GetAlbums() { var asyncAlbums = await _hc.GetAsync(_externalAlbum.GetLink()); var asyncUsers = await _hc.GetAsync(_externalUser.GetLink()); if (!asyncAlbums.IsSuccessStatusCode || !asyncAlbums.IsSuccessStatusCode) { return(Conflict()); } var allAlbums = await asyncAlbums .Content .ReadAsAsync <IEnumerable <Album> >(); var allUsers = await asyncUsers .Content .ReadAsAsync <IEnumerable <UserModel> >(); var mappedUserViewModel = Mapper.Map <IEnumerable <UserModel>, IEnumerable <UserViewModel> >(allUsers); var mappedAlbumViewModel = Mapper.Map <IEnumerable <Album>, IEnumerable <AlbumViewModel> >(allAlbums); foreach (var item in mappedAlbumViewModel) { item.User = mappedUserViewModel .FirstOrDefault(x => x.Id == item.UserId); } foreach (var item in mappedAlbumViewModel) { item.Links = new List <LinkHATEOAS>() { CreatorHateoas.CreateHateoas("self", $"{Url.Link("DefaultApi",new { id = item.Id})}", "GET") }; } return(Ok(mappedAlbumViewModel)); }