public async Task <IActionResult> Edit(int id, [Bind("Id,CarId,DriverId,EngineType,EngineSize,FuelConsumption,Description")] Review review)
        {
            if (id != review.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarId"]    = new SelectList(_context.Car, "Id", "Name", review.CarId);
            ViewData["DriverId"] = new SelectList(_context.Driver, "Id", "FirstName", review.DriverId);
            return(View(review));
        }
        public async Task <IActionResult> Edit(int id, IFormFile imageUrl, [Bind("Id,FirstName,LastName,LicenceSince,DriverPicture")] Driver driver)
        {
            if (id != driver.Id)
            {
                return(NotFound());
            }

            DriversController uploadImage = new DriversController(_context, webHostingEnvironment);

            driver.DriverPicture = uploadImage.UploadedFile(imageUrl);

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(driver);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DriverExists(driver.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(driver));
        }
        public async Task <IActionResult> Edit(long id, [Bind("Id,Tm,V,VN,Cf,VT,Img,FImg")] CarsModel carsModel)
        {
            if (id != carsModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(carsModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarsModelExists(carsModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(carsModel));
        }
Exemple #4
0
        public async Task <IActionResult> Edit(int id, IFormFile imageUrl, [Bind("Id,Name,ModelYear,Type,ManufacturerId,CarPicture")] Car car)
        {
            if (id != car.Id)
            {
                return(NotFound());
            }

            CarsController uploadImage = new CarsController(_context, webHostingEnvironment);

            car.CarPicture = uploadImage.UploadedFile(imageUrl);

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ManufacturerId"] = new SelectList(_context.Set <Manufacturer>(), "Id", "Name", car.ManufacturerId);
            return(View(car));
        }
Exemple #5
0
        public async Task <IActionResult> Edit(int id, IFormFile imageUrl, [Bind("Id,Name,Country,Headquarters,Founded,ManufacturerPicture")] Manufacturer manufacturer)
        {
            if (id != manufacturer.Id)
            {
                return(NotFound());
            }

            ManufacturersController uploadImage = new ManufacturersController(_context, webHostingEnvironment);

            manufacturer.ManufacturerPicture = uploadImage.UploadedFile(imageUrl);

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(manufacturer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ManufacturerExists(manufacturer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(manufacturer));
        }
Exemple #6
0
        public async Task <IActionResult> EditReview(int id, ReviewEditViewModel entry)
        {
            if (entry.Review.Id != id)
            {
                return(NotFound());
            }

            var review = await _context.Review
                         .Include(r => r.Car)
                         .Include(r => r.Driver)
                         .FirstOrDefaultAsync(m => m.Id == id);

            if (review == null)
            {
                return(NotFound());
            }

            AppUser user = await userManager.GetUserAsync(User);

            if (review.DriverId != user.DriverId)
            {
                return(RedirectToAction("AccessDenied", "Account", null));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    review.FuelConsumption = entry.Review.FuelConsumption;
                    review.Description     = entry.Review.Description;
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(RedirectToAction(nameof(EditReview)));
        }