public Worker Add(Worker item) { using(var ctx = new TestDatabaseEntities()) { ctx.Workers.Add(item); ctx.SaveChanges(); } return item; }
public bool Update(Worker item) { using (var ctx = new TestDatabaseEntities()) { Worker wrkUpdate = ctx.Workers.Where(w => w.id == item.id).First(); if (wrkUpdate != null) { wrkUpdate.FirstName = item.FirstName; wrkUpdate.LastName = item.LastName; wrkUpdate.Position = item.Position; wrkUpdate.Phone = item.Phone; } else { return false; } ctx.Entry(wrkUpdate).State = EntityState.Modified; ctx.SaveChanges(); } return true; }