Example #1
0
        public ActionResult Create()
        {
            var vm = new LocationEditViewModel
            {
                Areas = mapper.Map<IEnumerable<SelectListItem>>(repository.GetAll<Area>())
            };

            return View(vm);
        }
Example #2
0
        public ActionResult Create(LocationEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var location = new Location
                {
                    Name = viewModel.Name,
                    StreetAddress = viewModel.StreetAddress,
                    StreetAddress2 = viewModel.StreetAddress2,
                    ZipCode = viewModel.ZipCode,
                    AreaId = viewModel.AreaId,
                    UrlSlug = viewModel.Name.ConvertToUrlSlug()
                };

                repository.Add(location);
                repository.SaveChanges();
                return RedirectToRoute("Locations");
            }

            return View(viewModel);
        }
Example #3
0
        public ActionResult Edit(int id, LocationEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var location = repository.Find<Location>(id);
                if (location == null)
                {
                    return HttpNotFound();
                }

                location = mapper.Map(viewModel, location);
                repository.SaveChanges();

                return RedirectToRoute("Locations", new { name = location.UrlSlug });
            }

            return View(viewModel);
        }