Esempio n. 1
0
        public ViewResult New()
        {
            var continents = _context.Continents.ToList();

            var viewModel = new NewTourViewModel
            {
                Continents = continents
            };

            return(View("TourForm", viewModel));
        }
Esempio n. 2
0
        public ActionResult Edit(int id)
        {
            var tour = _context.Tours.SingleOrDefault(t => t.Id == id);

            if (tour == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new NewTourViewModel
            {
                Tour       = tour,
                Continents = _context.Continents.ToList()
            };

            return(View("TourForm", viewModel));
        }
Esempio n. 3
0
        public ActionResult Save(Tour tour)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new NewTourViewModel
                {
                    Tour       = tour,
                    Continents = _context.Continents.ToList()
                };
                return(View("TourForm", viewModel));
            }
            if (tour.Id == 0)
            {
                _context.Tours.Add(tour);
            }
            else
            {
                var tourInDb = _context.Tours.Single(t => t.Id == tour.Id);
                tourInDb.Name        = tour.Name;
                tourInDb.Description = tour.Description;
                tourInDb.Days        = tour.Days;
                tourInDb.Nights      = tour.Nights;
                tourInDb.Price       = tour.Price;
                tourInDb.Capacity    = tour.Capacity;
                tourInDb.ContinentId = tour.ContinentId;
            }

            try
            {
                _context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e);
            }

            return(RedirectToAction("Index", "Tours"));
        }