Пример #1
0
        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));
            }
        }
Пример #2
0
        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"));
            }
        }
Пример #3
0
 public IActionResult Get()
 {
     return(Ok(_citiesRepository.GetAllCities()));
 }
Пример #4
0
 public IActionResult Get()
 {
     return(Ok(_citiesRepository.GetAllCities().Select(x => new CityViewModel(x))));
 }