public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
public IHttpActionResult PutDriver(int id, MicWay.Driver.Library.Models.Driver driver) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != driver.Id) { return(BadRequest()); } db.Entry(driver).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DriverExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutDriver(int id, Driver driver) { try { string.Format("PutDriver({0}, Driver driver)", id); if (!ModelState.IsValid) { //collect all the errors foreach (ModelState modelState in ModelState.Values) { foreach (ModelError error in modelState.Errors) { LogUtil.Error(error.Exception); } } return(BadRequest(ModelState)); } if (id != driver.Id) { return(BadRequest()); } //Validate the data sent ValidateDriverDetails(driver); db.Entry(driver).State = EntityState.Modified; await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { if (!DriverExists(id)) { return(NotFound()); } else { LogUtil.Error(e); throw new Exception(string.Format("The following error has occurred: {0}", e.Message)); } } catch (Exception e) { LogUtil.Error(e); throw new Exception(string.Format("The following error has occurred: {0}", e.Message)); } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(Model.Driver driver) { _context.Entry(driver).State = EntityState.Modified; }