Exemple #1
0
        public JsonResult GetCities(int id)
        {
            List <CityDTO> cities;

            try
            {
                cities = _addressService.GetCities(id);
            }
            catch (NullReferenceException ex)
            {
                return(Json("None City was found!!!"));
            }
            var city = JsonConvert.SerializeObject(cities);

            return(Json(city));
        }
        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));
        }