コード例 #1
0
        private CityCreateOrUpdateViewModel PrepareCreateCity()
        {
            var cityViewModel = new CityCreateOrUpdateViewModel();

            // country
            var allCountries = _countryRepository.GetAll();

            cityViewModel.AvailableCountry.Add(new SelectListItem()
            {
                Text  = "Please Select The Country:",
                Value = "0"
            });

            foreach (var country in allCountries)
            {
                var countrySelectListItem = new SelectListItem()
                {
                    Value = country.Id.ToString(),
                    Text  = country.Title
                };
                cityViewModel.AvailableCountry.Add(countrySelectListItem);
            }

            return(cityViewModel);
        }
コード例 #2
0
        public ActionResult Create(CityCreateOrUpdateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var cityModel = new City()
                {
                    Title   = model.Title,
                    Show    = model.Show,
                    StateId = model.StateId
                };

                _cityRepository.Add(cityModel);
                _cityRepository.Complete();

                return(RedirectToAction("List"));
            }

            return(RedirectToAction("Create"));
        }
コード例 #3
0
        public ActionResult Edit(CityCreateOrUpdateViewModel city)
        {
            if (ModelState.IsValid)
            {
                if (city == null)
                {
                    throw new ArgumentException("bad request");
                }
                var addressModel = _cityRepository.Get(city.Id);
                addressModel.Title   = city.Title;
                addressModel.Show    = city.Show;
                addressModel.StateId = city.StateId;

                _cityRepository.Update(addressModel);
                _cityRepository.Complete();

                return(View("List"));
            }
            ModelState.AddModelError(" ", "Problem");
            return(View());
        }
コード例 #4
0
        public ActionResult Edit(int id)
        {
            if (id == 0)
            {
                throw new ArgumentException("bad request");
            }
            var city = _cityRepository.Get(id);

            if (city == null)
            {
                throw new ArgumentException("bad request");
            }

            var cityModel = new CityCreateOrUpdateViewModel()
            {
                Title = city.Title,

                StateId   = city.StateId,
                CountryId = city.State.CountryId,
                Show      = city.Show
            };

            return(View("Edit", cityModel));
        }