public async Task <IActionResult> GetAllLocations() { try { var locations = await locationsRepository.GetAllLocations(); if (locations == null || !locations.Any()) { var error = new NotFoundException("No locations data found"); return(StatusCode(StatusCodes.Status404NotFound, new CustomException <NotFoundException>(error).GetException())); } var resource = mapper.Map <IEnumerable <Location>, IEnumerable <LocationResource> >(locations); var response = new OkResponse <IEnumerable <LocationResource> >(resource, "Everything is good"); return(StatusCode(StatusCodes.Status200OK, response)); } catch (Exception err) { var errMessage = $"Source: {err.Source}\n Message: {err.Message}\n StackTrace: {err.StackTrace}\n"; if (err is SqlException) { var error = new InternalServerException(errMessage); return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException())); } else { var error = new BadRequestException(errMessage); return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException())); } } }
public async Task <ActionResult <IEnumerable <Location> > > GetAllLocations() { var response = await locationsRepository.GetAllLocations(); var viewModel = mapper.Map <IEnumerable <Location> >(response); return(Ok(viewModel)); }
public IActionResult Get() { try { return(Ok(_repository.GetAllLocations())); } catch (Exception) { return(BadRequest("Oopss!")); } }
async Task <IQueryable <Location> > IRequestHandler <GetLocationsQuery, IQueryable <Location> > .Handle(GetLocationsQuery request, CancellationToken cancellationToken) { var locations = _locationsRepository.GetAllLocations(); return(locations); }