public async Task <IActionResult> PutPerson(int id, Person person) { if (id != person.Id) { return(BadRequest()); } person.IsActive = true; var local = _context.Set <Person>() .Local .FirstOrDefault(entry => entry.Id.Equals(id)); if (local != null) { // detach _context.Entry(local).State = EntityState.Detached; } _context.Entry(person).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public T Get(int id) { var entity = dbContext.Set <T>().Find(id); return(entity); }
public Repository() { dbContext = new PersonDbContext("DataAccessEntities"); this.dbSet = dbContext.Set <T>(); }
public Repository(PersonDbContext db) { Db = db; DbSet = db.Set <TEntity>(); }
public void AddPerson(Person person) { person.PersonId = Guid.NewGuid(); _context.Set <Person>().Add(person); _context.SaveChanges(); }
public void AddPhone(Phone phone) { phone.PhoneId = Guid.NewGuid(); _context.Set <Phone>().Add(phone); _context.SaveChanges(); }
public virtual TEntity Fetch(int id) { return(_context.Set <TEntity>().Find(id)); }