public HttpResponseMessage GetAllCities(PaginationModel paging) { ResponseStatus response = new ResponseStatus(); try { var data = _repository.GetAllCities(paging.PageSize, paging.PageNumber); if (data.Count() > 0) { response.isSuccess = true; response.serverResponseTime = System.DateTime.Now; return(Request.CreateResponse(HttpStatusCode.OK, new { data, response })); } else { response.isSuccess = false; response.serverResponseTime = System.DateTime.Now; return(Request.CreateResponse(HttpStatusCode.BadRequest, new { response })); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something Worng !", ex)); } }
public async Task <ActionResult <CityModel[]> > Get() { try { var results = await _repository.GetAllCities(); if (!results.Any()) { return(NotFound("No cities in the database")); } return(_mapper.Map <CityModel[]>(results)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database failure")); } }
public IActionResult Get() { return(Ok(_citiesRepository.GetAllCities())); }
public IActionResult Get() { return(Ok(_citiesRepository.GetAllCities().Select(x => new CityViewModel(x)))); }