示例#1
0
        public JsonResult GetStreets(int countryId, int cityId)

        {
            List <StreetDTO> streets;

            try
            {
                streets = _addressService.GetStreets(countryId, cityId);
            }
            catch (NullReferenceException ex)
            {
                return(Json("None Street was found!!!"));
            }

            var street = JsonConvert.SerializeObject(streets);

            return(Json(street));
        }
        public IActionResult Edit(int id)
        {
            CreatePlaceDTO place;

            try
            {
                place = _placesService.GetById(id);
            }
            catch (NullReferenceException e)
            {
                _logger.Log(LogLevel.Error, $"Place with id={id} doesn`t exist");
                return(View("Error", new ErrorViewModel()
                {
                    ErrorMessage = "The place that you are looking for doesn`t exist."
                }));
            }


            var placeModel = Mapper.Map <CreatePlaceViewModel>(place);

            if (place == null)
            {
                _logger.Log(LogLevel.Error, $"Place with id={id} requested for edit was not found");
                return(View("Error", new ErrorViewModel()
                {
                    ErrorMessage = "The place that you are looking for was not found ."
                }));
            }

            ViewBag.UserId    = _userManager.GetUserId(User);
            ViewBag.Countries = _addressService.GetCountries();
            ViewBag.Cities    = _addressService.GetCities(placeModel.CountryId);
            ViewBag.Streets   = _addressService.GetStreets(placeModel.CountryId, placeModel.CityId);
            ViewBag.Types     = _placesService.GetTypes();
            return(View(placeModel));
        }