public IHttpActionResult PutInfrastructure(int id, Infrastructure infrastructure) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != infrastructure.Infrastructure_id) { return(BadRequest()); } db.Entry(infrastructure).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InfrastructureExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public virtual async Task <(T, bool)> UpdateAsync(T entity) { var entityKeyName = GetEntityKeyName(entity); var entityKeyValue = GetEntityKeyValue(entity, entityKeyName); var existingEntity = await GetByIdAsync(entityKeyValue, entityKeyName); if (existingEntity == null) { _logger.LogInformation("Notfound Entity."); return(entity, false); } _logger.LogInformation("State of Existing Entity: " + _dbContext.Entry(existingEntity).State.ToString()); _logger.LogInformation("State of Entity Before SetModified: " + _dbContext.Entry(entity).State.ToString()); this.SetModifiedEntityState(entity, entityKeyName); _logger.LogInformation("State of Entity After SetModified: " + _dbContext.Entry(entity).State.ToString()); return(entity, await CommitSaveChangesAsync()); }