public UpdatedStatus Update(T updatedEntity) { UpdatedStatus operationStatus = UpdatedStatus.Failed; try { helpDeskContext _db = new helpDeskContext(); T currentEntity = _db.Set <T>().FirstOrDefault(ent => ent.Id == updatedEntity.Id); _db.Entry(currentEntity).OriginalValues["Timer"] = updatedEntity.Timer; _db.Entry(currentEntity).CurrentValues.SetValues(updatedEntity); if (_db.SaveChanges() == 1) //shoudl throw if stale; { operationStatus = UpdatedStatus.Ok; } } catch (DbUpdateConcurrencyException dbx) { operationStatus = UpdatedStatus.Stale; Console.WriteLine("Problem in " + MethodBase.GetCurrentMethod().Name + dbx.Message); } catch (Exception ex) { Console.WriteLine("Problem in " + MethodBase.GetCurrentMethod().Name + ex.Message); } return(operationStatus); }
public List <T> GetAll() { return(_db.Set <T>().ToList()); }