public async Task Update(NaturalPersonDto dto)
        {
            NaturalPerson person = await _naturalPersonRepository.GetById(dto.Id);

            UpdateNaturalPerson(dto, person);

            await _updateAddressService.Update(person.AddressId, dto.Address);

            await _updateDocumentService.Update(person.DocumentId, dto.Document);

            if (!person.Validate())
            {
                NotifyDomainValidations(person.ValidationResult);
            }

            if (!_notifier.HasNotification())
            {
                _naturalPersonRepository.Update(person);
                await _unitOfWork.Commit();
            }
        }
예제 #2
0
        public async Task UpdateAsync(NaturalPersonViewModel model)
        {
            var person = await _personRepository.GetAsync(model.Id);

            if (person == null)
            {
                return;
            }

            person.Name   = model.Name;
            person.Gender = model.Gender.Value;
            person.Email  = model.Email;
            person.SetBirthday(model.Birthday);
            person.SetIdDocument(model.IdDocument);

            // Address is optional, if country not informed delete address entity
            if (!string.IsNullOrWhiteSpace(model.Country))
            {
                if (person.Address == null)
                {
                    person.Address = new Address(
                        model.Country, model.State, model.City, model.ZipCode, model.AddressLine1, model.AddressLine2);
                }
                else
                {
                    person.Address.ChangeAddress(
                        model.Country, model.State, model.City, model.ZipCode, model.AddressLine1, model.AddressLine2);
                }
            }
            else
            {
                person.Address = null;
            }

            _personRepository.Update(person);

            _personRepository.SaveChanges();
        }