public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,PhoneNumber,EmailAddress")] CSOEmployee cSOEmployee) { if (id != cSOEmployee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cSOEmployee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CSOEmployeeExists(cSOEmployee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cSOEmployee)); }
public async Task <IActionResult> Edit(int id, Contact contact) { if (id != contact.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(contact); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(contact.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(contact)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Nombre,Cedula,Pagina_Web,Direccion,Telefono,Sector,IDUsuario")] Cliente cliente) { if (id != cliente.ID) { return(NotFound()); } if (ModelState.IsValid) { cliente.IDUsuario = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); try { _context.Update(cliente); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClienteExists(cliente.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cliente)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Article,Name,Price")] PartType partType) { if (id != partType.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(partType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PartTypeExists(partType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(partType)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Titulo,DiaHora,Virtual,IDCliente,IDUsuario")] Reunion reunion) { if (id != reunion.ID) { return(NotFound()); } if (ModelState.IsValid) { try { reunion.IDUsuario = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); _context.Update(reunion); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReunionExists(reunion.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IDCliente"] = new SelectList(_context.Cliente, "IDCliente", "Nombre", reunion.IDCliente); return(View(reunion)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,OrderDate,Discount")] 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))); } return(View(order)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Titulo,Detalle,Quien_reporto,Estado_Actual,IDCliente,IDUsuario")] Ticket ticket) { if (id != ticket.ID) { return(NotFound()); } if (ModelState.IsValid) { try { ticket.IDUsuario = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); _context.Update(ticket); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TicketExists(ticket.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IDCliente"] = new SelectList(_context.Cliente, "IDCliente", "Nombre", ticket.IDCliente); return(View(ticket)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Nombre,Apellidos,Correo,Telefono,Puesto,IDCliente,IDUsuario")] Contacto contacto) { if (id != contacto.ID) { return(NotFound()); } if (ModelState.IsValid) { try { contacto.IDUsuario = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); _context.Update(contacto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactoExists(contacto.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IDCliente"] = new SelectList(_context.Cliente, "IDCliente", "Nombre", contacto.IDCliente); return(View(contacto)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Username,Password,Tipo")] Usuario usuario) { if (id != usuario.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(usuario); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsuarioExists(usuario.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(usuario)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,BuildingName,PropertyNumber,AddressLine1,AddressLine2,AddressLine3,PostCode")] Address address) { if (id != address.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(address); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(address.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(address)); }
public async Task <IActionResult> Edit(string id, [Bind("ID,Name,SetupDate,CostCenterCode")] Client client) { if (id != client.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(client); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(client.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(client)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Vendor vendor) { if (id != vendor.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(vendor); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VendorExists(vendor.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(vendor)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,EngineCapacity,EngineType,DriveUnitType,TransmissionType,VendorId")] CarModel carModel) { if (id != carModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(carModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarModelExists(carModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } PopulateVendorsDropDownList(carModel.VendorId); return(View(carModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Description,DateTime,ComType")] Communication communication) { if (id != communication.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(communication); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommunicationExists(communication.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(communication)); }
public async Task <IActionResult> Edit(int id, [Bind("ServiceProductId,Summary,DurationDays,ID,Price")] ServiceProduct serviceProduct) { if (id != serviceProduct.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(serviceProduct); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ServiceProductExists(serviceProduct.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(serviceProduct)); }
public async Task <IActionResult> Edit(int id, [Bind("TangibleProductId,Manufacture,Model,EndOfLife,ID,Price")] TangibleProduct tangibleProduct) { if (id != tangibleProduct.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tangibleProduct); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TangibleProductExists(tangibleProduct.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tangibleProduct)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,StartDate,EndDate,WarrantyExpiry,discount")] ClientService clientService) { if (id != clientService.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(clientService); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientServiceExists(clientService.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(clientService)); }
public async Task <IActionResult> Edit(int id, [Bind("Id")] InternalEmployee internalEmployee) { if (id != internalEmployee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(internalEmployee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InternalEmployeeExists(internalEmployee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(internalEmployee)); }
public async Task <IActionResult> EditCar(int id, [Bind("Id,VIN,Year,Price,ColorId,TestDrive,CarModelId,PartnerId")] Car car) { if (id != car.Id) { return(NotFound()); } try { var existedCar = await _context.Cars.SingleOrDefaultAsync(x => x.Id == id); if (ModelState.IsValid) { existedCar.VIN = car.VIN; existedCar.Year = car.Year; existedCar.Price = car.Price; existedCar.ColorId = car.ColorId; existedCar.TestDrive = car.TestDrive; existedCar.CarModelId = car.CarModelId; existedCar.PartnerId = car.PartnerId; _context.Update(existedCar); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CarModelId"] = new SelectList(_context.CarModels.Include(c => c.Vendor).AsNoTracking(), "Id", null); ViewData["ColorId"] = new SelectList(_context.CarColors, "Id", "Name", car.ColorId); ViewData["PartnerId"] = new SelectList(_context.Partners, "Id", "Name", car.PartnerId); return(View(car)); } catch (DbUpdateConcurrencyException) { if (!CarExists(car.Id)) { return(NotFound()); } else { throw; } } }
public async Task <Ticket> Update(Ticket t, Staff s) { using (_context = CRMContextFactory.getContext()) { _context.Update(t); var history = new TicketHistory(); history.idStaffAssigned = t.idStaffAssignedTo; history.idTicket = t.idTicket; history.idTicketStatus = t.idTicketStatus; history.dtChanged = DateTime.Now; history.idStaffAssigns = s.idStaff; _context.TicketHistories.Add(history); await _context.SaveChangesAsync(); return(t); } }
public async Task <IActionResult> Edit(int id, Company company) { if (id != company.Id) { return(NotFound()); } List <Business> businessesList = _context.Business.ToList(); ViewBag.data = businessesList; if (ModelState.IsValid) { try { _context.Update(company); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompanyExists(company.Id)) { return(NotFound()); } else { throw; } } catch (DbUpdateException) { ModelState.AddModelError("", "NIP is taken"); return(View(company)); } return(RedirectToAction(nameof(Index))); } return(View(company)); }
public async Task <IActionResult> Edit(int id, User user) { if (id != user.Id) { return(NotFound()); } var adminnumber = await _context.User.CountAsync(m => m.RoleId == 1); //var user1 = await _context.User.FirstOrDefaultAsync(m => m.Login == user.Login); //var user2 = await _context.User.FindAsync(id); try { var user1 = await _context.User.AsNoTracking().FirstOrDefaultAsync(m => m.Login == user.Login); //var user1 = await _context.User.FirstOrDefaultAsync(m => m.Login == user.Login); if (user1 == null || id == user1.Id) { //try //{ if (ModelState.IsValid) { //_context.Update(user1); //_context.Remove(user1); ViewBag.Message = null; if (adminnumber > 2 || user.RoleId == 1) { if (!IsMD5(user.Password)) { user.Password = HashPassword(user.Password); } _context.Update(user); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } else { ViewBag.Message = String.Format("You cannot demote more admins! There must be at least 2 of them!"); return(View(user)); } } return(View(user)); //} //catch (Exception) //{ // if (!UserExists(user.Id)) // { // return NotFound(); // } // else // { // } //} //return RedirectToAction("Index"); } else { ModelState.AddModelError("", "Login is taken"); return(View(user)); } } catch (Exception) { //throw; try { if (ModelState.IsValid) { if (id != user.Id) { return(NotFound()); } if (!IsMD5(user.Password)) { user.Password = HashPassword(user.Password); } _context.Update(user); await _context.SaveChangesAsync(); return(View(user)); } else { return(View(user)); } } catch (Exception) { //throw; ModelState.AddModelError("", "Invalid data"); return(View(user)); } } }
public async Task <IActionResult> Edit(int id, User user) { if (id != user.Id) { return(NotFound()); } var adminnumber = await _context.User.CountAsync(m => m.RoleId == 1); ViewBag.Message = null; //if(user1.Id != 0) { // var login = user1.Login; //} try { int x = await LoginUnChangedAsync(id, user.Login); //var user1 = await _context.User.FirstOrDefaultAsync(m => m.Login == user.Login); if (x < 3 /*user1.Id == 0 || user1.Id == id*/) { if (ModelState.IsValid) { //_context.Update(user1); //_context.Remove(user1); if (adminnumber > 2 || user.RoleId == 1) { if (!IsMD5(user.Password)) { user.Password = HashPassword(user.Password); } //_context.Add(user); _context.Update(user); await _context.SaveChangesAsync(); if (x == 1 || user.RoleId != Convert.ToInt32(User.FindFirst("role").Value)) { await HttpContext.SignOutAsync(); string role = await ReturnRole(user.Login); var claims = new List <Claim> { new Claim("user", user.Login), new Claim("role", role) }; await HttpContext.SignInAsync(new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies", "user", "role"))); } return(RedirectToAction("Details")); } else { ViewBag.Message = String.Format("You cannot delete more admins! There must be at least 2 of them!"); return(View(user)); } } return(View(user)); } else { ModelState.AddModelError("", "Login is taken"); return(View(user)); } } catch (Exception) { //throw; try { if (!IsMD5(user.Password)) { user.Password = HashPassword(user.Password); } _context.Update(user); await _context.SaveChangesAsync(); await HttpContext.SignOutAsync(); string role = await ReturnRole(user.Login); var claims = new List <Claim> { new Claim("user", user.Login), new Claim("role", role) }; await HttpContext.SignInAsync(new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies", "user", "role"))); return(RedirectToAction("Details")); } catch (Exception) { //throw; ModelState.AddModelError("", "Invalid data"); return(View(user)); } } //user1 = await _context.User.FirstOrDefaultAsync(m => m.Login == user.Login); //var user2 = await _context.User.FindAsync(id); //if (ModelState.IsValid) //{ // if (user1 == null || user1.Login == user2.Login) // { // try // { // _context.Update(user1); // //else { // //_context.Add(user1); // //} // //_context.Update(user); // await _context.SaveChangesAsync(); // } // catch (DbUpdateConcurrencyException) // { // if (!UserExists(user.Id)) // { // return NotFound(); // } // else // { // throw; // } // } // await HttpContext.SignOutAsync(); // return Redirect("/"); // } // else // { // ModelState.AddModelError("", "Login is taken"); // return View(user); // } //} //return View(user); }