Ejemplo n.º 1
0
        public async Task <int> UpdateAsync(UpdateContactRecordInput input)
        {
            var contactRecordToUpdate = await _contactRecordRepository.GetByIdAsync(input.Id);

            //TO-DO: Create own Exception
            if (contactRecordToUpdate == null)
            {
                throw new ContactRecordNotFoundException("ContactRecord doesn't exists");
            }

            //TO-DO: Use Automapper
            var address     = new Core.ValueObjects.Address(input.Address.State, input.Address.City, input.Address.ZipCode, input.Address.Street, input.Address.Number);
            var phoneNumber = new Core.ValueObjects.PhoneNumber(input.PhoneNumber.PersonalNumber, input.PhoneNumber.WorkNumber);

            contactRecordToUpdate.Name             = input.Name;
            contactRecordToUpdate.Email            = input.Email;
            contactRecordToUpdate.ProfileImagePath = input.ProfileImagePath;
            contactRecordToUpdate.Company          = input.Company;
            contactRecordToUpdate.BirthDate        = input.BirthDate;
            contactRecordToUpdate.Address          = address;
            contactRecordToUpdate.PhoneNumber      = phoneNumber;

            _contactRecordRepository.Update(contactRecordToUpdate);

            return(await _contactRecordRepository.UnitOfWork.SaveChangesAsync());
        }
Ejemplo n.º 2
0
        public async Task <int> AddAsync(CreateContactRecordInput input)
        {
            var existContactRecord = await _contactRecordRepository.GetByEmailAsync(input.Email);

            //TO-DO: Create own Exception
            if (existContactRecord != null)
            {
                throw new ContactRecordExistsException("ContactRecord alerady exists");
            }

            //TO-DO: Use Automapper
            var address       = new Core.ValueObjects.Address(input.Address.State, input.Address.City, input.Address.ZipCode, input.Address.Street, input.Address.Number);
            var phoneNumber   = new Core.ValueObjects.PhoneNumber(input.PhoneNumber.PersonalNumber, input.PhoneNumber.WorkNumber);
            var contactRecord = new Core.Entities.ContactRecord(input.Name, input.Company, input.ProfileImagePath, input.Email, input.BirthDate, phoneNumber, address);

            await _contactRecordRepository.AddAsync(contactRecord);

            return(await _contactRecordRepository.UnitOfWork.SaveChangesAsync());
        }