Ejemplo n.º 1
0
        public ActionResult Create()
        {
            var vm = new ManageHostEditViewModel
            {
                HostSite = new HostSite(),
                Counties = GetCountySelectListItem(_dataContext.Counties.OrderBy(c => c.Name))
            };

            return View(vm);
        }
Ejemplo n.º 2
0
        public ActionResult Create(ManageHostEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.HostSite.UrlFriendlyName = Regex.Replace(model.HostSite.Name, @"[^\w]+", "-", RegexOptions.IgnoreCase);
                _dataContext.HostSites.Add(model.HostSite);
                _dataContext.SaveChanges();

                return RedirectToAction("Detail", new {model.HostSite.Id});
            }

            return View(model);
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, FormCollection form)
        {
            var model = _dataContext.HostSites.Single(h => h.Id == id);

            model.UrlFriendlyName = Regex.Replace(model.Name, @"[^\w]+", "-", RegexOptions.IgnoreCase);

            if (TryUpdateModel(model, "HostSite"))
            {
                _dataContext.SaveChanges();
                return RedirectToAction("Detail", new { model.Id });
            }

            var vm = new ManageHostEditViewModel
                {
                    HostSite = model,
                    Counties = GetCountySelectListItem(_dataContext.Counties.OrderBy(c => c.Name))
                };

            return View(vm);
        }
Ejemplo n.º 4
0
        public ActionResult Edit(int id)
        {
            var host = _dataContext.HostSites.Single(h => h.Id == id);

            var vm = new ManageHostEditViewModel
                {
                    HostSite = host,
                    Counties = GetCountySelectListItem(_dataContext.Counties.OrderBy(c => c.Name))
                };

            return View(vm);
        }