public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Address,MobileNo,Email,CityId")] Customer customer) { if (id != customer.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", customer.CityId); return(View(customer)); }
public async Task <bool> UpdateAsync(CustomerEntity customer) { _context.Update(customer); await _context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CountryCode")] Country country) { if (id != country.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(country); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CountryExists(country.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(country)); }
public async Task UpdateCustomerAsync( Guid customerId, int age, CancellationToken cancellationToken = default) { var entity = await _customerDbContext.Customers.FindAsync( keyValues : new object[] { customerId }, cancellationToken : cancellationToken); if (entity != null) { entity.Age = age; _customerDbContext.Update(entity); await _customerDbContext.SaveChangesAsync(cancellationToken); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CountryId")] 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))); } ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "CountryCode", city.CountryId); return(View(city)); }
public int Upsert(Customer customer) { var customerFromDb = Get(customer.FirstName, customer.LastName); if (customerFromDb == null) { _dbContext.Add(customer); } else { customerFromDb.updateFrom(customer); _dbContext.Update(customerFromDb); } return(_dbContext.SaveChanges()); }
public async Task <T> UpdateAsync(T entity) { if (entity == null) { throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null"); } try { _context.Update(entity); await _context.SaveChangesAsync(); return(entity); } catch (Exception ex) { throw new Exception($"{nameof(entity)} could not be updated: {ex.Message}"); } }