Пример #1
0
        public ActionResult AddCountry(CountryModel model)
        {
            if (ModelState.IsValid)
            {
                var country = new Country(model.Name);
                Context.AddCountry(country);

                Context.SaveChanges();
            }

            return JsonView(ModelState.IsValid,"_AddCountry", model);
        }
Пример #2
0
        public ActionResult EditCountry(CountryModel model)
        {
            if (ModelState.IsValid)
            {
                Country country;
                if (!Context.Countries.TryGetById(model.Id, out country))
                    throw new InvalidOperationException(string.Format("country with id {0} was not found", model.Id));

                country.Name = model.Name;
                Context.SaveChanges();
            }

            return JsonView(ModelState.IsValid, "_EditCountry", model);
        }
Пример #3
0
        public ActionResult EditCountry(long id)
        {
            Country country;
            if (!Context.Countries.TryGetById(id, out country))
                throw new InvalidOperationException(string.Format("country with id {0} was not found", id));

            var model = new CountryModel
            {
                Id = country.Id,
                Name = country.Name
            };

            return PartialView("_EditCountry", model);
        }