Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Length,Price,Rating,IncludesMeals")] Tour tour)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tour);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tour));
        }
        public async Task <IActionResult> Create([Bind("Name,X,Y,Description,MinTime")] Location location)
        {
            if (ModelState.IsValid)
            {
                _context.Add(location);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(location));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("LocationId,Place,Continent")] Location location)
        {
            if (ModelState.IsValid)
            {
                _context.Add(location);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(location));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("TourTypeID,Label")] TourType tourType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tourType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tourType));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Image,EventDate,LocationId")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LocationId"] = new SelectList(_context.Locations, "LocationId", "LocationId", city.LocationId);
            return(View(city));
        }
        public async Task <IActionResult> AddOrEdit([FromForm] TourViewModel t)
        {
            if (ModelState.IsValid)
            {
                if (t.TourId == 0)
                {
                    var tour = new Tour();
                    tour.TourId      = t.TourId;
                    tour.ToursName   = t.ToursName;
                    tour.Country     = t.Country;
                    tour.Description = t.Description;
                    tour.DaysCost    = t.DaysCost;
                    tour.ImgSrc      = "/Images/NoImageFound.png";
                    _context.Add(tour);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    var tour = _context.Tours.FirstOrDefault(u => u.TourId == t.TourId);
                    tour.TourId      = t.TourId;
                    tour.ToursName   = t.ToursName;
                    tour.Country     = t.Country;
                    tour.Description = t.Description;
                    tour.DaysCost    = t.DaysCost;
                    tour.ImgSrc      = t.ImgSrc;

                    _context.Update(tour);

                    await _context.SaveChangesAsync();
                }
                if (t.uploadedFile != null)
                {
                    // путь к папке Files
                    string path = "/Images/" + t.uploadedFile.FileName;
                    // сохраняем файл в папку Files в каталоге wwwroot
                    using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                    {
                        await t.uploadedFile.CopyToAsync(fileStream);
                    }
                    var tour = _context.Tours.FirstOrDefault(u => u.TourId == t.TourId);
                    tour.ImgSrc = path;
                    _context.Tours.Update(tour);
                    _context.SaveChanges();
                }
            }
            return(RedirectToAction(nameof(Index)));;
        }
        public async Task <IActionResult> Create([Bind("Location_TourID,TourID,LocationID")] Location_Tour location_Tour)
        {
            if (ModelState.IsValid)
            {
                location_Tour.Location = _context.Locations.Find(location_Tour.LocationID);
                _context.Add(location_Tour);
                var tour = _context.Tours.Find(location_Tour.TourID);
                tour.Location_Tour.Add(location_Tour);
                tour.MinDuration += location_Tour.Location.MinTime;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Tours"));
            }
            ViewData["LocationID"] = new SelectList(_context.Locations, "LocationID", "Name", location_Tour.LocationID);
            ViewData["TourID"]     = new SelectList(_context.Tours, "TourID", "Name", location_Tour.TourID);
            return(View(location_Tour));
        }
        public async Task <IActionResult> AddOrEdit([Bind("TourId,TourTitle,Description,ParkCode")] Tour tour)
        {
            if (ModelState.IsValid)
            {
                if (tour.TourId == 0)
                {
                    _context.Add(tour);
                }
                else
                {
                    _context.Update(tour);
                }


                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tour));
        }