public async Task <IActionResult> ContactAdd(ContactBook contactBook)
        {
            db.ContactBooks.Add(contactBook);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #2
0
 public async Task DeleteAllContacts()
 {
     using (var context = new ContactBookContext())
     {
         context.Contacts.RemoveRange(context.Contacts);
         await context.SaveChangesAsync();
     }
 }
Пример #3
0
        public async Task <bool> RemoveContactByPhoneID(int phoneID)
        {
            using (var context = new ContactBookContext())
            {
                var phone = await context.PhoneNumbers.SingleOrDefaultAsync(f => f.PhoneNumberID == phoneID);

                if (phone != null)
                {
                    context.PhoneNumbers.Remove(phone);
                    await context.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #4
0
        public async Task <bool> RemoveContactByAddressID(int addressID)
        {
            using (var context = new ContactBookContext())
            {
                var address = await context.Addresses.SingleOrDefaultAsync(f => f.AddressID == addressID);

                if (address != null)
                {
                    context.Addresses.Remove(address);
                    await context.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #5
0
        public async Task <bool> RemoveContactByEmailID(int emailID)
        {
            using (var context = new ContactBookContext())
            {
                var email = await context.Emails.SingleOrDefaultAsync(f => f.EmailID == emailID);

                if (email != null)
                {
                    context.Emails.Remove(email);
                    await context.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #6
0
        public async Task <bool> RemoveContactById(int id)
        {
            using (var context = new ContactBookContext())
            {
                var contact = await context.Contacts.SingleOrDefaultAsync(f => f.Id == id);

                if (contact != null)
                {
                    context.Contacts.Remove(contact);
                    await context.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }