Exemple #1
0
        public async Task <ServiceResponse <Contact> > AddContactAsync(Contact contact)
        {
            var serviceResponse = new ServiceResponse <Contact>();

            if (await DoesContactExist(contact.UserId, contact.FirstName, contact.LastName))
            {
                serviceResponse.Success = false;
                serviceResponse.Message = "Contact Already Exists";

                return(serviceResponse);
            }

            try
            {
                var addedContact = await _contactsContext.AddAsync(contact);

                await _contactsContext.SaveChangesAsync();

                serviceResponse.ReturnResource = addedContact.Entity;

                return(serviceResponse);
            }
            catch (Exception ex)
            {
                serviceResponse.Message = $"An error occurred while trying to add contact {ex.Message}";

                return(serviceResponse);
            }
        }
        public async Task AddContactAsync(string numberPhone, Dictionary <string, string> data)
        {
            var contact = InitContact(numberPhone);

            ContactAddData(contact, data);
            await context.AddAsync(contact);

            await context.SaveChangesAsync();
        }