public async Task <IActionResult> PutCustomer(int id, Customer customer) { if (id != customer.IdentityNumber) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Remove(TModel entity) { if (_dbContext.Entry(entity).State == EntityState.Detached) { ModelDbSets.Attach(entity); } ModelDbSets.Remove(entity); }
public async Task <TEntity> UpdateAsync(TEntity entityToUpdate) { _context.Entry(entityToUpdate).State = EntityState.Modified; await _context.SaveChangesAsync(); return(entityToUpdate); }
public bool Update(Customer customer) { //method 1 //int isUpdated = 0; //Customer aCustomer = _db.customers.FirstOrDefault(c => c.CustomerID == customer.CustomerID); //aCustomer.CustomerName = customer.CustomerName; //isUpdated = _db.SaveChanges(); //if (isUpdated > 0) // return true; //else // return false; //method 2 int isUpdated = 0; _db.Entry(customer).State = EntityState.Modified; isUpdated = _db.SaveChanges(); if (isUpdated > 0) { return(true); } else { return(false); } }
public IHttpActionResult PutCustomer(int id, Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customer.ID) { return(BadRequest()); } db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <HttpResponseMessage> EditCustomer([FromBody] Customer customer) { try { System.Threading.Thread.Sleep(1000);//Delay simulation db.Entry(customer).State = EntityState.Modified; int result = await db.SaveChangesAsync(); response = Request.CreateResponse(HttpStatusCode.OK, result == 1); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.ExpectationFailed, ex.ToString()); } return(response); }
public ActionResult edit(Customer emp) { Customer employee = db.Customers.Where(c => c.ID == emp.ID).FirstOrDefault(); db.Entry(employee).CurrentValues.SetValues(emp); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Name")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "ID,name,CustomerTYpe")] customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit([Bind(Include = "CustomerID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit([Bind(Include = "Id,Name,Sales,Active,DateCreated")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,BirthDate,UserName,Password,Address,City,ZipCode,IsAdmin")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit([Bind(Include = "Id,Fname,Lname,gender,Dob,Mobile,Mobil2,Address,Remark,Appdate,Followup,Status")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit([Bind(Include = "ID,customerPhoneNumber,customerName,customerId,active")] PhoneNumber phoneNumber) { if (ModelState.IsValid) { db.Entry(phoneNumber).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(phoneNumber)); }
public ActionResult Edit([Bind(Include = "Id")] Description description) { if (ModelState.IsValid) { db.Entry(description).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(description)); }
public ActionResult Edit([Bind(Include = "Id,FirstName,LastName")] CustomerList customerList) { if (ModelState.IsValid) { db.Entry(customerList).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerList)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit([Bind(Include = "Id,Date,Total,Description,CustomerId")] Order order) { if (ModelState.IsValid) { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", order.CustomerId); return(View(order)); }
public ActionResult GridViewPartialAddNew(Customer customer) { var model = db.Customers; if (ModelState.IsValid) { try { db.Entry(customer).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("GridViewPartial", db.Customers.ToList())); }
public IActionResult Edit(Customer customer) { CustomerDbContext db = new CustomerDbContext(); db.Entry(customer).State = Microsoft.EntityFrameworkCore.EntityState.Modified; bool isSave = db.SaveChanges() > 0; if (isSave) { return(RedirectToAction("List")); } return(RedirectToAction("List")); }
public bool UpdateCustomer(Customer customer) { int isExecuted = 0; db.Entry(customer).State = EntityState.Modified; isExecuted = db.SaveChanges(); if (isExecuted > 0) { return(true); } return(false); }
public IActionResult Delete(int?id) { CustomerDbContext db = new CustomerDbContext(); Customer customer = db.Customers.Find(id); customer.isDeleted = true; db.Entry(customer).State = Microsoft.EntityFrameworkCore.EntityState.Modified; bool isSave = db.SaveChanges() > 0; if (isSave) { return(RedirectToAction("List")); } return(RedirectToAction("List")); }
public void EditCustomer(Customer customer) { var cust = _customerDBContext.Customers.AsNoTracking().Where(q => q.CustomerId == customer.CustomerId); foreach (var cus in cust) { if ((customer.CustomerId == cus.CustomerId)) { _customerDBContext.Customers.Remove(cus); } } _customerDBContext.Attach(customer); IEnumerable <EntityEntry> noChangeEntities = _customerDBContext.ChangeTracker.Entries().Where(x => x.State == EntityState.Unchanged); foreach (EntityEntry cusEE in noChangeEntities) { cusEE.State = EntityState.Modified; } _customerDBContext.Entry(customer).State = EntityState.Modified; _customerDBContext.SaveChanges(); }
public async Task <IActionResult> PutCustomer([FromRoute] int id, [FromBody] Customer customer) { customer.id = id; customer.Country = _context.Country.Single(c => c.CountryId == customer.Country.CountryId); _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public bool update(Customer customer) { db.Entry(customer).State = EntityState.Modified; return(db.SaveChanges() > 0); }
public void UpdateCustomer(Customer customer) { _context.Customers.Update(customer); _context.Entry(customer).State = Microsoft.EntityFrameworkCore.EntityState.Modified; }
private void AssertModified(Customer customer) { db.ChangeTracker.DetectChanges(); Assert.AreEqual(EntityState.Modified, db.Entry(customer).State, "Entity state"); }
public void Update(Customer customer) { _dbContext.Entry(customer).State = EntityState.Modified; }
public virtual bool Update(T entity) { db.Entry(entity).State = EntityState.Modified; return(db.SaveChanges() > 0); }
public void Update(TEntity item) { _context.Entry(item).State = EntityState.Modified; _context.SaveChanges(); }