Пример #1
0
        public async Task <IActionResult> Create([Bind("ParkId,Name,Description,City,State,WebsiteLink,ParkMapLink")] Park park, List <IFormFile> files)
        {
            if (ModelState.IsValid)
            {
                // 1. Save the park model first, creates a unique id for the inserted park.
                _context.Add(park);
                await _context.SaveChangesAsync();

                // 2. Save the ImageFiles in Images folder and get new Filenames.
                var newFileNames = ImageProcessor.SaveImageFilesToDrive(files);

                // 3. Save FileName and path in db.
                foreach (var newfileName in newFileNames)
                {
                    var imageFileName = new ImageFileName()
                    {
                        FileName = newfileName,
                        ParkId   = park.ParkId
                    };
                    _context.ImageFileNames.Add(imageFileName);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(park));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("RideId,Name,Description,Height,Length,TopSpeed,GForce,RideType,ThrillType,MaterialType,WebsiteLink,BuildDate,Manufacturer,ParkId")] Ride ride, List <IFormFile> files)
        {
            if (ModelState.IsValid)
            {
                // 1. Save the ride model first, creates a unique id for the inserted park.
                _context.Add(ride);
                await _context.SaveChangesAsync();

                // 2. Save the ImageFiles in Images folder and get new Filenames.
                var newFileNames = ImageProcessor.SaveImageFilesToDrive(files);

                // 3. Save FileName and path in db.
                foreach (var newfileName in newFileNames)
                {
                    var imageFileName = new ImageFileName()
                    {
                        FileName = newfileName,
                        RideId   = ride.RideId
                    };
                    _context.ImageFileNames.Add(imageFileName);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ParkId"] = new SelectList(_context.Parks, "ParkId", "ParkId", ride.ParkId);
            return(View(ride));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("VisitRideId,VisitId,RideId,VisitRideRating,VisitRideComments")] VisitRide visitRide)
        {
            if (ModelState.IsValid)
            {
                _context.Add(visitRide);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RideId"]  = new SelectList(_context.Rides, "RideId", "RideId", visitRide.RideId);
            ViewData["VisitId"] = new SelectList(_context.Visits, "VisitId", "VisitId", visitRide.VisitId);
            return(View(visitRide));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("VisitId,ParkId,VisitDate,VisitRating,VisitComments")] Visit visit)
        {
            if (ModelState.IsValid)
            {
                visit.UserId = GetUserId();
                _context.Add(visit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ParkId"] = new SelectList(_context.Parks, "ParkId", "ParkId", visit.ParkId);
            return(View(visit));
        }