public async Task <bool> Update(ContactPhone phone, int contactId, int phoneId) { using (var ctx = new ContactBookDbContext()) { var entity = ctx.Contacts .IncludeFilter(x => x.Phones.Where(z => z.Id == phoneId)) .Single(x => x.Id == contactId); if (entity.Phones.Count == 0) { return(false); } ctx.Phones.RemoveRange(entity.Phones); ctx.Phones.Add(new ContactPhone { ContactId = contactId, PhoneNumber = phone.PhoneNumber, Type = phone.Type, }); await ctx.SaveChangesAsync(); return(true); } }
public async Task <bool> Update(ContactEmail email, int contactId, int emailId) { using (var ctx = new ContactBookDbContext()) { var entity = ctx.Contacts .IncludeFilter(x => x.Emails.Where(z => z.Id == emailId)) .Single(x => x.Id == contactId); if (entity.Emails.Count == 0) { return(false); } ctx.Emails.RemoveRange(entity.Emails); ctx.Emails.Add(new ContactEmail { ContactId = contactId, Email = email.Email, Type = email.Type, }); await ctx.SaveChangesAsync(); return(true); } }
public ContactsController(ContactBookDbContext context) { _context = context; }