Ejemplo n.º 1
0
        /// <summary>
        /// Functionality which can handle a query for getting some data for a household member.
        /// </summary>
        /// <param name="query">Query for getting some data for a household member.</param>
        /// <returns>View of the selected data.</returns>
        public virtual TView Query(TQuery query)
        {
            ArgumentNullGuard.NotNull(query, nameof(query));

            ITranslationInfo translationInfo = GetTranslationInfo(query);

            IHouseholdMember householdMember = HouseholdDataRepository.HouseholdMemberGetByMailAddress(ClaimValueProvider.MailAddress);

            if (householdMember == null)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberNotCreated));
            }
            if (ShouldBeActivated && householdMember.IsActivated == false)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberNotActivated));
            }
            if (ShouldHaveAcceptedPrivacyPolicy && householdMember.IsPrivacyPolicyAccepted == false)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberHasNotAcceptedPrivacyPolicy));
            }
            if (householdMember.HasRequiredMembership(RequiredMembership) == false)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberHasNotRequiredMembership));
            }

            TData data = GetData(householdMember, query, translationInfo);

            return(ObjectMapper.Map <TData, TView>(data, translationInfo?.CultureInfo));
        }
        /// <summary>
        /// Gets the current users household member account.
        /// </summary>
        /// <param name="translationInfoIdentifier">Identifier of the translation informations which should be used in the translation.</param>
        /// <returns>Current users household member account.</returns>
        private IHouseholdMember HouseholdMemberGetCurrent(Guid translationInfoIdentifier)
        {
            var mailAddress     = _claimValueProvider.MailAddress;
            var householdMember = HouseholdDataRepository.HouseholdMemberGetByMailAddress(mailAddress);

            if (householdMember != null)
            {
                return(householdMember);
            }
            var householdMemberIdentifier = _logicExecutor.HouseholdMemberAdd(mailAddress, translationInfoIdentifier);

            return(HouseholdDataRepository.Get <IHouseholdMember>(householdMemberIdentifier));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes the functionality which can handle a command for modifying some data on a household member.
        /// </summary>
        /// <param name="command">Command for modifying some data on a household member.</param>
        /// <returns>Service receipt.</returns>
        public virtual ServiceReceiptResponse Execute(TCommand command)
        {
            ArgumentNullGuard.NotNull(command, nameof(command));

            IHouseholdMember householdMember = HouseholdDataRepository.HouseholdMemberGetByMailAddress(ClaimValueProvider.MailAddress);

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(householdMember), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberNotCreated)))
            .IsSatisfiedBy(() => ShouldBeActivated == false || householdMember.IsActivated, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberNotActivated)))
            .IsSatisfiedBy(() => ShouldHaveAcceptedPrivacyPolicy == false || householdMember.IsPrivacyPolicyAccepted, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberHasNotAcceptedPrivacyPolicy)))
            .IsSatisfiedBy(() => householdMember.HasRequiredMembership(RequiredMembership), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberHasNotRequiredMembership)))
            .Evaluate();

            AddValidationRules(householdMember, command, Specification);

            Specification.Evaluate();

            IIdentifiable identifiableDomainObject = ModifyData(householdMember, command);

            return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(identifiableDomainObject));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Modifies the data.
        /// </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>
        /// <returns>The updated household.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="household"/> or <paramref name="command"/> is null.</exception>
        public override IIdentifiable ModifyData(IHousehold household, HouseholdAddHouseholdMemberCommand command)
        {
            ArgumentNullGuard.NotNull(household, nameof(household))
            .NotNull(command, nameof(command));

            ITranslationInfo translationInfo = HouseholdDataRepository.Get <ITranslationInfo>(command.TranslationInfoIdentifier);
            IHouseholdMember householdMemberForMailAddress = household.HouseholdMembers.SingleOrDefault(householdMember => string.Compare(householdMember.MailAddress, command.MailAddress, StringComparison.OrdinalIgnoreCase) == 0);

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(translationInfo), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.TranslationInfoIdentifier)))
            .IsSatisfiedBy(() => CommonValidations.IsNull(householdMemberForMailAddress), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberAlreadyExistsOnHousehold, command.MailAddress)))
            .Evaluate();

            IHouseholdMember householdMemberToAdd = HouseholdDataRepository.HouseholdMemberGetByMailAddress(command.MailAddress);

            if (householdMemberToAdd == null)
            {
                Guid householdMemberToAddIdentifier = _logicExecutor.HouseholdMemberAdd(command.MailAddress, translationInfo.Identifier ?? default(Guid));
                householdMemberToAdd = HouseholdDataRepository.Get <IHouseholdMember>(householdMemberToAddIdentifier);
            }

            household.HouseholdMemberAdd(householdMemberToAdd);

            return(HouseholdDataRepository.Update(household));
        }