示例#1
0
 public void Delete(TEntity entity)
 {
     if (Context.Entry(entity).State == EntityState.Detached)
     {
         _dbSet.Attach(entity);
     }
     _dbSet.Remove(entity);
     Context.SaveChanges();
 }
 public ActionResult Edit([Bind(Include = "Id,Name")] Destination destination)
 {
     if (ModelState.IsValid)
     {
         db.Entry(destination).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(destination));
 }
示例#3
0
 public async Task <bool> UpdateCustomerAsync(Customer customer)
 {
     //Will update all properties of the Customer
     _Context.Customers.Attach(customer);
     _Context.Entry(customer).State = EntityState.Modified;
     try
     {
         return(await _Context.SaveChangesAsync() > 0 ? true : false);
     }
     catch (Exception exp)
     {
         _Logger.LogError($"Error in {nameof(UpdateCustomerAsync)}: " + exp.Message);
     }
     return(false);
 }