public async Task <IActionResult> Edit(int id, [Bind("Id,ExportDate,IdRepair,Description")] GoodsDeliveryNote goodsDeliveryNote) { if (id != goodsDeliveryNote.Id) { return(NotFound()); } if (ModelState.IsValid) { try { goodsDeliveryNote.UpdateAt = DateTime.Now; _context.Update(goodsDeliveryNote); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GoodsDeliveryNoteExists(goodsDeliveryNote.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdRepair"] = new SelectList(_context.Repairs, "Id", "Id", goodsDeliveryNote.IdRepair); return(View(goodsDeliveryNote)); }
public async Task <IActionResult> Edit(int?id, Employee employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { //------------------------------------------- if (employee.ImageFile != null) { string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(employee.ImageFile.FileName); string extension = Path.GetExtension(employee.ImageFile.FileName); fileName = fileName + extension; employee.Image = "../assets/img/" + fileName; var checkFile = Path.Combine(wwwRootPath + "/assets/img/", employee.ImageFile.FileName); //Save image to wwwroot/image if (!System.IO.File.Exists(checkFile)) { string path = Path.Combine(wwwRootPath + "/assets/img/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await employee.ImageFile.CopyToAsync(fileStream); } } } //------------------------------------------- _context.Update(employee); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public async Task <IActionResult> Edit(int id, Pay pay) { if (id != pay.Id) { return(NotFound()); } if (ModelState.IsValid) { try { pay.Paid += pay.owe; pay.Update_at = DateTime.Now; _context.Update(pay); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PayExists(pay.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdRepair"] = new SelectList(_context.Repairs, "Id", "Id", pay.IdRepair); return(View(pay)); }
public async Task <IActionResult> Edit(int idRepair, DetailRepair detailRepair) { if (idRepair != detailRepair.IdRepair) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(detailRepair); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); } catch (DbUpdateConcurrencyException) { if (!DetailRepairExists(detailRepair.IdRepair)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Details", "Repairs", new { id = idRepair })); } ViewData["IdRepair"] = new SelectList(_context.Repairs, "Id", "Id", detailRepair.IdRepair); ViewData["IdWork"] = new SelectList(_context.Works, "Id", "Id", detailRepair.IdWork); return(View(detailRepair)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,IdMaterial,UpdateAt,Price")] PriceMaterial priceMaterial) { if (id != priceMaterial.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(priceMaterial); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PriceMaterialExists(priceMaterial.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdMaterial"] = new SelectList(_context.Materials, "Id", "Id", priceMaterial.IdMaterial); return(View(priceMaterial)); }
public async Task <IActionResult> ResetConfirmed(string username) { var account = _context.Accounts.Find(username); if (account == null) { return(NotFound()); } if (ModelState.IsValid) { try { account.Password = "******"; // default pass: 12345678 _context.Update(account); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountExists(account.UserName)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(account)); }
public async Task <IActionResult> Edit(int idGoodsReceivedNote, DetailGoodsReceivedNote detailGoodsReceivedNote) { if (idGoodsReceivedNote != detailGoodsReceivedNote.IdGoodsReceivedNote) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(detailGoodsReceivedNote); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DetailGoodsReceivedNoteExists(detailGoodsReceivedNote.IdGoodsReceivedNote)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), new { id = detailGoodsReceivedNote.IdGoodsReceivedNote })); } ViewData["IdGoodsReceivedNote"] = new SelectList(_context.GoodsReceivedNotes, "Id", "Id", detailGoodsReceivedNote.IdGoodsReceivedNote); ViewData["MaterialName"] = new SelectList(_context.Materials, "Id", "Name"); return(View(detailGoodsReceivedNote)); }
public async Task <IActionResult> Edit(int idGoodsDeliveryNote, DetailGoodsDeliveryNote detailGoodsDeliveryNote) { if (idGoodsDeliveryNote != detailGoodsDeliveryNote.IdGoodsDeliveryNote) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(detailGoodsDeliveryNote); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "cập nhật vật tư thành công"); } catch (DbUpdateConcurrencyException) { if (!DetailGoodsDeliveryNoteExists(detailGoodsDeliveryNote.IdGoodsDeliveryNote)) { return(NotFound()); } else { throw; } } var idRepair = _context.GoodsDeliveryNotes.Include(a => a.IdRepairNavigation).Where(a => a.Id == detailGoodsDeliveryNote.IdGoodsDeliveryNote).FirstOrDefault().IdRepair; return(RedirectToAction("Details", "Repairs", new { id = idRepair })); } ViewData["IdGoodsDeliveryNote"] = new SelectList(_context.GoodsDeliveryNotes, "Id", "Id", detailGoodsDeliveryNote.IdGoodsDeliveryNote); ViewData["IdMaterial"] = new SelectList(_context.Materials, "Id", "Name", detailGoodsDeliveryNote.IdMaterial); return(View(detailGoodsDeliveryNote)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Position position) { if (id != position.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(position); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PositionExists(position.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(position)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Phone,Email,Address,Description")] Supplier supplier) { if (id != supplier.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(supplier); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); } catch (DbUpdateConcurrencyException) { if (!SupplierExists(supplier.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(supplier)); }
public async Task <IActionResult> Edit(int id, Work work) { if (id != work.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(work); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); } catch (DbUpdateConcurrencyException) { if (!WorkExists(work.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdService"] = new SelectList(_context.Services, "Id", "Name"); return(View(work)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ModelName")] CarModel carModel) { if (id != carModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(carModel); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); } catch (DbUpdateConcurrencyException) { if (!CarModelExists(carModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(carModel)); }
public async Task <IActionResult> Edit(int id, TypeOfSupply typeOfSupply) { if (id != typeOfSupply.Id) { return(NotFound()); } if (ModelState.IsValid) { try { typeOfSupply.UpdateAt = DateTime.Now; _context.Update(typeOfSupply); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); } catch (DbUpdateConcurrencyException) { if (!TypeOfSupplyExists(typeOfSupply.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(typeOfSupply)); }
public async Task <IActionResult> Edit(int id, GoodsReceivedNote goodsReceivedNote) { if (id != goodsReceivedNote.Id) { return(NotFound()); } if (ModelState.IsValid) { try { goodsReceivedNote.UpdateAt = DateTime.Now; _context.Update(goodsReceivedNote); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GoodsReceivedNoteExists(goodsReceivedNote.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var supplier = _context.Suppliers.Select(i => i.Name).ToList(); ViewData["IdSupplier"] = new SelectList(_context.Suppliers, "Id", "Name", supplier); return(View(goodsReceivedNote)); }
public async Task <IActionResult> Edit(int?id, Customer customer) { if (id != customer.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customer); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); //History History history = new History(); history.DateHistory = DateTime.Now; history.UserName = HttpContext.Session.GetString("SessionUserName"); history.Event = "Cập nhật thông tin khách hàng " + customer.Name; _context.Add(history); await _context.SaveChangesAsync(); //============================ } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,IdCar,DateOfFactoryEntry,DateFinished,State")] Repair repair) { if (id != repair.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(repair); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); //History History history = new History(); history.DateHistory = DateTime.Now; history.UserName = HttpContext.Session.GetString("SessionUserName"); history.Event = "Cập nhật thông tin nhập xuất xưởng cho xe của khách hàng " + _context.Cars.Include(c => c.IdCustomerNavigation).Where(c => c.Id == repair.IdCar).Select(c => c.IdCustomerNavigation.Name).FirstOrDefault(); _context.Add(history); await _context.SaveChangesAsync(); //============================ } catch (DbUpdateConcurrencyException) { if (!RepairExists(repair.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdCar"] = new SelectList(_context.Cars, "Id", "Id", repair.IdCar); return(View(repair)); }
public async Task <IActionResult> Edit(int id, Car car) { if (id != car.Id) { return(NotFound()); } if (ModelState.IsValid) { try { //------------------------------------------- if (car.ImageFile != null) { string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(car.ImageFile.FileName); string extension = Path.GetExtension(car.ImageFile.FileName); fileName = fileName + extension; car.Image = "../assets/img/" + fileName; var checkFile = Path.Combine(wwwRootPath + "/assets/img/", car.ImageFile.FileName); //Save image to wwwroot/image if (!System.IO.File.Exists(checkFile)) { string path = Path.Combine(wwwRootPath + "/assets/img/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await car.ImageFile.CopyToAsync(fileStream); } } } //------------------------------------------- _context.Update(car); await _context.SaveChangesAsync(); HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); //History History history = new History(); history.DateHistory = DateTime.Now; history.UserName = HttpContext.Session.GetString("SessionUserName"); var infoCar = _context.Cars.Include(c => c.IdCustomerNavigation).Where(c => c.IdCustomer == car.IdCustomer).FirstOrDefault(); history.Event = "Cập nhật thông tin xe của khách hàng " + infoCar.IdCustomerNavigation.Name; _context.Add(history); await _context.SaveChangesAsync(); //============================ } catch (DbUpdateConcurrencyException) { if (!CarExists(car.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdCustomer"] = new SelectList(_context.Customers, "Id", "Id", car.IdCustomer); return(View(car)); }
public async Task <IActionResult> Edit(int?id, Material material) { if (id != material.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (material.ImageFile != null) { string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(material.ImageFile.FileName); string extension = Path.GetExtension(material.ImageFile.FileName); fileName = fileName + extension; material.Image = "../assets/img/" + fileName; var checkFile = Path.Combine(wwwRootPath + "/assets/img/", material.ImageFile.FileName); //Save image to wwwroot/image if (!System.IO.File.Exists(checkFile)) { string path = Path.Combine(wwwRootPath + "/assets/img/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await material.ImageFile.CopyToAsync(fileStream); } } } material.UpdateAt = DateTime.Now; _context.Update(material); await _context.SaveChangesAsync(); var priceCheck = _context.PriceMaterials.Where(p => p.IdMaterial == material.Id).OrderByDescending(p => p.UpdateAt).First().Price; if (priceCheck != material.Price) { PriceMaterial priceMaterial = new PriceMaterial(); priceMaterial.IdMaterial = material.Id; priceMaterial.UpdateAt = DateTime.Now; priceMaterial.Price = material.Price; _context.Add(priceMaterial); await _context.SaveChangesAsync(); } HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công"); //History History history = new History(); history.DateHistory = DateTime.Now; history.UserName = HttpContext.Session.GetString("SessionUserName"); history.Event = "Cập nhật thông tin vật tư " + material.Name; _context.Add(history); await _context.SaveChangesAsync(); //============================ } catch (DbUpdateConcurrencyException) { if (!SupplyExists(material.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var type = _context.TypeOfSupplies.Select(i => i.Name).ToList(); ViewData["TypeName"] = new SelectList(_context.TypeOfSupplies, "Id", "Name", type); return(View(material)); }