public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name,SurName,Login,NumberPhone,Password,PasswordConfirm")] Driver driver) { if (id != driver.Id) { return(NotFound()); } 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(Guid id, [Bind("Id,Title")] City city) { if (id != city.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(city); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityExists(city.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Title,TypeCar,Number_of_the_car,Capacity,Comment")] Car car) { if (id != car.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(car); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(car.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(car)); }
public async Task <IActionResult> Edit(Guid id, Order order) { if (id != order.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Routes"] = (await _context.Routes.Include(r => r.CityFrom).Include(r => r.CityTo).ToListAsync()) .ConvertAll(c => new SelectListItem { Text = $"{c.CityFrom.Title} - {c.CityTo.Title}", Value = c.Id.ToString() }); //ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Id"); return(View(order)); }
//Route route public async Task <IActionResult> Edit(Guid id, RouteViewModel routeViewModel, IFormFile picture, string oldPicture) { if (id != routeViewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (picture != null) { var fileName = Path.Combine(_env.WebRootPath, "uploads", Path.GetFileName(picture.FileName)); picture.CopyTo(new FileStream(fileName, FileMode.Create)); } var route = new Route { Id = routeViewModel.Id, Price = routeViewModel.Price, Description = routeViewModel.Description, CityFrom = await _context.Cities.FindAsync(routeViewModel.CityFromId), CityTo = await _context.Cities.FindAsync(routeViewModel.CityToId), Img = picture != null ? picture.FileName : oldPicture }; _context.Attach(route); _context.Update(route); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RouteExists(routeViewModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Cities"] = (await _context.Cities.ToListAsync()).ConvertAll(c => new SelectListItem { Text = c.Title, Value = c.Id.ToString() }); return(View(routeViewModel)); }