public async Task <IActionResult> Edit(int id, [Bind("IdTypeOfCar,TypeOfCar1")] TypeOfCar typeOfCar) { if (id != typeOfCar.IdTypeOfCar) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(typeOfCar); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TypeOfCarExists(typeOfCar.IdTypeOfCar)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(typeOfCar)); }
public async Task <IActionResult> Edit(int id, [Bind("IdClient,FullName,PhoneNumber")] Client client) { if (id != client.IdClient) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(client); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(client.IdClient)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(client)); }
public async Task <IActionResult> Edit(int id, [Bind("IdPosition,Name")] Position position) { if (id != position.IdPosition) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(position); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PositionExists(position.IdPosition)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(position)); }
public async Task <IActionResult> Edit(int id, [Bind("IdService,ServiceName,Price")] Service service) { if (id != service.IdService) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(service); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ServiceExists(service.IdService)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(service)); }
public async Task <IActionResult> Edit(int id, [Bind("IdCar,Name,Owner,IdClient,IdTypeOfCar,PathCarImg")] Car car, IFormFile uploadedFile) { if (id != car.IdCar) { return(NotFound()); } if (ModelState.IsValid) { try { // //якщо було вибрано файл то він замінює попередній if (uploadedFile != null) { //збереження зображення // путь к папке Files string path = $"/Files/CarImg/{car.IdCar}_{uploadedFile.FileName}"; // сохраняем файл в папку Files в каталоге wwwroot using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); } FileInfo fileInf = new FileInfo(_appEnvironment.WebRootPath + car.PathCarImg); if (fileInf.Exists) { fileInf.Delete(); } car.PathCarImg = path; } // _context.Update(car); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarExists(car.IdCar)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdClient"] = new SelectList(_context.Clients, "IdClient", "FullName", car.IdClient); ViewData["IdTypeOfCar"] = new SelectList(_context.TypeOfCars, "IdTypeOfCar", "TypeOfCar1", car.IdTypeOfCar); return(View(car)); }
public async Task <IActionResult> Edit(int id, [Bind("IdWorker,IdPosition,FullName,PhoneNumber,Address,Rate,DateOfBirth,PathWorkerImg")] Worker worker, IFormFile uploadedFile) { if (id != worker.IdWorker) { return(NotFound()); } if (ModelState.IsValid) { try { // //якщо було вибрано файл то він замінює попередній if (uploadedFile != null) { //збереження зображення // путь к папке Files string path = $"/Files/WorkerImg/{worker.IdWorker}_{uploadedFile.FileName}"; // сохраняем файл в папку Files в каталоге wwwroot using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); } FileInfo fileInf = new FileInfo(_appEnvironment.WebRootPath + worker.PathWorkerImg); if (fileInf.Exists) { fileInf.Delete(); } worker.PathWorkerImg = path; } // _context.Update(worker); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkerExists(worker.IdWorker)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdPosition"] = new SelectList(_context.Positions, "IdPosition", "Name", worker.IdPosition); return(View(worker)); }
public async Task <IActionResult> Edit(int id, [Bind("IdMaterials,NameMaterial,Price,PathMaterialsImg")] Material material, IFormFile uploadedFile) { if (id != material.IdMaterials) { return(NotFound()); } if (ModelState.IsValid) { try { // //якщо було вибрано файл то він замінює попередній if (uploadedFile != null) { //збереження зображення // путь к папке Files string path = $"/Files/MaterialImg/{material.IdMaterials}_{uploadedFile.FileName}"; // сохраняем файл в папку Files в каталоге wwwroot using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); } FileInfo fileInf = new FileInfo(_appEnvironment.WebRootPath + material.PathMaterialsImg); if (fileInf.Exists) { fileInf.Delete(); } material.PathMaterialsImg = path; } // _context.Update(material); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MaterialExists(material.IdMaterials)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(material)); }
public async Task <IActionResult> Edit(int id, [Bind("IdOrder,Date,IdClient,IdCar,Price")] Order order, int[] idMaterials, int[] idWorkers, int[] idServices) { if (id != order.IdOrder) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(order); // var OrderWorkers = _context.OrderWorkers .Where(p => p.IdOrder == id) .ToListAsync(); foreach (var item in await OrderWorkers) { _context.OrderWorkers.RemoveRange(item); } var MaterialsOrders = _context.MaterialsOrders .Where(p => p.IdOrder == id) .ToListAsync(); foreach (var item in await MaterialsOrders) { _context.MaterialsOrders.RemoveRange(item); } var ServiceOrders = _context.ServiceOrders .Where(p => p.IdOrder == id) .ToListAsync(); foreach (var item in await ServiceOrders) { _context.ServiceOrders.RemoveRange(item); } // foreach (var n in idMaterials) { order.MaterialsOrders.Add(new MaterialsOrder { IdOrderNavigation = order, IdMaterialsNavigation = _context.Materials.FirstOrDefault(p => p.IdMaterials == n) }); } foreach (var n in idWorkers) { order.OrderWorkers.Add(new OrderWorker { IdOrderNavigation = order, IdWorkerNavigation = _context.Workers.FirstOrDefault(p => p.IdWorker == n) }); } foreach (var n in idServices) { order.ServiceOrders.Add(new ServiceOrder { IdOrderNavigation = order, IdServiceNavigation = _context.Services.FirstOrDefault(p => p.IdService == n) }); } // await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.IdOrder)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdCar"] = new SelectList(_context.Cars, "IdCar", "Name", order.IdCar); ViewData["IdClient"] = new SelectList(_context.Clients, "IdClient", "FullName", order.IdClient); return(View(order)); }