public async Task <IActionResult> PutContact(int id, Contact contact)
        {
            if (id != contact.id)
            {
                return(BadRequest());
            }

            _context.Entry(contact).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task <T> SaveAsync(T input)
        {
            if (input.Id == Guid.Empty)
            {
                dbSet.Add(input);
            }
            else
            {
                dbSet.Update(input);
            }
            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

            return(input);
        }
Example #3
0
        public async Task DeleteWithDetails(Guid id)
        {
            var person = await _dbContext.Persons.FindAsync(id).ConfigureAwait(false);

            _dbContext.Persons.Remove(person);

            var communicationInfos = await _dbContext.CommunicationInfos.Where(x => x.PersonId == id && !x.IsDeleted).ToListAsync().ConfigureAwait(false);

            _dbContext.CommunicationInfos.RemoveRange(communicationInfos);

            await _dbContext.SaveChangesAsync().ConfigureAwait(false);
        }
 public Task AddAsync(PhoneEntry phoneEntry)
 {
     _dbContext.AddAsync(phoneEntry);
     return(_dbContext.SaveChangesAsync());
 }