public async Task <IActionResult> Edit(int id, [Bind("ID,Descricao,Referencia")] Categoria categoria) { if (id != categoria.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(categoria); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoriaExists(categoria.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(categoria)); }
public async Task <IActionResult> Edit(long id, [Bind("ProductId,Name,Category,Color,UnitPrice,AvailableQuantity,CratedDate")] Products products) { if (id != products.ProductId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(products); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(products.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(products)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,SecondName,DateOfBirth")] Person person) { if (id != person.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(person); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(person.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,name")] Employee employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employee)); }
public void Update() { Person person = _db.Persons.First(); person.Name = "Test"; _db.Update(person); // In thi case unnecessary _db.SaveChanges(); }
[ValidateAntiForgeryToken] // CSRF protection token public IActionResult Edit(int?id, Person person) { if (id == null) { return(NotFound()); } _context.Update(person); _context.SaveChanges(); TempData["Message"] = "Person edited!"; return(RedirectToAction("Index")); }
public IActionResult Edited(int dishid, Dish thisDish) { if (ModelState.IsValid) { thisDish.DishId = dishid; dbContext.Update(thisDish); dbContext.Entry(thisDish).Property("CreatedAt").IsModified = false; dbContext.SaveChanges(); return(RedirectToAction("Index")); } else { return(View("Edit", thisDish)); } }
public IActionResult UpdateDish(int DishId, Dishes UpDish) { if (ModelState.IsValid) { UpDish.DishId = DishId; dbContext.Update(UpDish); dbContext.Entry(UpDish).Property("CreatedAt").IsModified = false; dbContext.SaveChanges(); return(RedirectToAction("Index")); } else { return(EditDish(DishId)); } }
public IActionResult Edit(int?id, Person person) { if (id == null) { return(NotFound()); } if (ModelState.IsValid) { _context.Update(person); _context.SaveChanges(); TempData["message"] = "Person edited!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "There have been errors"); return(View(person)); }
public async Task <IActionResult> Edit(ProductEditViewModel user_data) { var old_product = await _context.Products.FindAsync(user_data.ID); if (old_product == null) { return(NotFound()); } if (ModelState.IsValid) { try { var updated_product = new Product { ID = user_data.ID, Name = user_data.Name, Price = user_data.Price, Quantity = user_data.Quantity, Image = user_data.Image, }; _context.Update(updated_product); _context.SaveChanges(); } catch (Exception ex) { //Loggin about exception } return(RedirectToRoute("product-index")); } return(View(user_data)); }
public void Update(TEntity entity) { _dbContext.Update(entity); _dbContext.SaveChanges(); }