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());
        }
Example #2
0
        public T Get(int id)
        {
            var entity = dbContext.Set <T>().Find(id);

            return(entity);
        }
Example #3
0
 public Repository()
 {
     dbContext  = new PersonDbContext("DataAccessEntities");
     this.dbSet = dbContext.Set <T>();
 }
Example #4
0
 public Repository(PersonDbContext db)
 {
     Db    = db;
     DbSet = db.Set <TEntity>();
 }
Example #5
0
 public void AddPerson(Person person)
 {
     person.PersonId = Guid.NewGuid();
     _context.Set <Person>().Add(person);
     _context.SaveChanges();
 }
Example #6
0
 public void AddPhone(Phone phone)
 {
     phone.PhoneId = Guid.NewGuid();
     _context.Set <Phone>().Add(phone);
     _context.SaveChanges();
 }
Example #7
0
 public virtual TEntity Fetch(int id)
 {
     return(_context.Set <TEntity>().Find(id));
 }