public async Task Store(NaturalPersonDto dto) { NaturalPerson person = new NaturalPerson(dto.Name, dto.Birthday, dto.Gender); StoreAddress(dto, person); StoreDocument(dto, person); if (!person.Validate()) { NotifyDomainValidations(person.ValidationResult); } if (!_notifier.HasNotification()) { _naturalPersonRepository.Add(person); await _unitOfWork.Commit(); } }
public void Add(NaturalPersonViewModel model) { if (!_personRepository.IsIdDocumentUnique(model.IdDocument)) { throw new BusinessRuleException("IdDocument", "ID Document already informed."); } if (!_personRepository.IsEmailUnique(model.Email)) { throw new BusinessRuleException("Email", "Email already informed."); } var person = new NaturalPerson( model.Name, model.IdDocument, model.Birthday, model.Gender.Value, model.Email) { Address = new Address( model.Country, model.State, model.City, model.ZipCode, model.AddressLine1, model.AddressLine2) }; _personRepository.Add(person); _personRepository.SaveChanges(); }