/// <summary> /// Adds validation rules to the specification which encapsulates validation rules. /// </summary> /// <param name="household">Household on which to modify data.</param> /// <param name="command">Command for adding a household member to a given household on the current users household account.</param> /// <param name="specification">Specification which encapsulates validation rules.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="household"/>, <paramref name="command"/> or <paramref name="specification"/> is null.</exception> public override void AddValidationRules(IHousehold household, HouseholdAddHouseholdMemberCommand command, ISpecification specification) { ArgumentNullGuard.NotNull(household, nameof(household)) .NotNull(command, nameof(command)) .NotNull(specification, nameof(specification)); string currentMailAddress = ClaimValueProvider.MailAddress; string mailAddressToAdd = command.MailAddress; specification.IsSatisfiedBy(() => CommonValidations.HasValue(command.MailAddress), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "MailAddress"))) .IsSatisfiedBy(() => CommonValidations.IsLengthValid(command.MailAddress, 1, 128), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.LengthForPropertyIsInvalid, "MailAddress", 1, 128))) .IsSatisfiedBy(() => CommonValidations.ContainsIllegalChar(command.MailAddress) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "MailAddress"))) .IsSatisfiedBy(() => _domainObjectValidations.IsMailAddress(command.MailAddress), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, command.MailAddress, "MailAddress"))) .IsSatisfiedBy(() => CommonValidations.Equals(mailAddressToAdd, currentMailAddress, StringComparison.OrdinalIgnoreCase) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.CannotModifyHouseholdMembershipForYourself))); }
/// <summary> /// Creates a household member. /// </summary> /// <param name="mailAddress">Mail address for the household member.</param> /// <param name="membership">Membership.</param> /// <param name="membershipExpireTime">Date and time for when the membership expires.</param> /// <param name="activationCode">Activation code for the household member.</param> /// <param name="creationTime">Date and time for when the household member was created.</param> /// <param name="domainObjectValidations">Implementation for common validations used by domain objects in the food waste domain.</param> protected HouseholdMember(string mailAddress, Membership membership, DateTime?membershipExpireTime, string activationCode, DateTime creationTime, IDomainObjectValidations domainObjectValidations = null) { ArgumentNullGuard.NotNullOrWhiteSpace(mailAddress, nameof(mailAddress)) .NotNullOrWhiteSpace(activationCode, nameof(activationCode)); _domainObjectValidations = domainObjectValidations ?? DomainObjectValidations.Create(); if (_domainObjectValidations.IsMailAddress(mailAddress) == false) { throw new IntranetSystemException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, mailAddress, "mailAddress")); } _mailAddress = mailAddress; _membership = membership; _membershipExpireTime = membershipExpireTime; _activationCode = activationCode; _creationTime = creationTime; }
/// <summary> /// Executes the command which adds a household member. /// </summary> /// <param name="command">Command which adds a household member.</param> /// <returns>Service receipt.</returns> public virtual ServiceReceiptResponse Execute(HouseholdMemberAddCommand command) { if (command == null) { throw new ArgumentNullException("command"); } var translationInfo = HouseholdDataRepository.Get <ITranslationInfo>(command.TranslationInfoIdentifier); Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(translationInfo), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.TranslationInfoIdentifier))) .IsSatisfiedBy(() => CommonValidations.HasValue(command.MailAddress), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "MailAddress"))) .IsSatisfiedBy(() => CommonValidations.IsLengthValid(command.MailAddress, 1, 128), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.LengthForPropertyIsInvalid, "MailAddress", 1, 128))) .IsSatisfiedBy(() => CommonValidations.ContainsIllegalChar(command.MailAddress) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "MailAddress"))) .IsSatisfiedBy(() => _domainObjectValidations.IsMailAddress(command.MailAddress), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, command.MailAddress, "MailAddress"))) .Evaluate(); var householdMember = HouseholdDataRepository.Insert <IHouseholdMember>(new HouseholdMember(command.MailAddress)); _welcomeLetterDispatcher.Dispatch(householdMember, householdMember, translationInfo); return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(householdMember, translationInfo.CultureInfo)); }