/// <summary>
        /// Executes the command which adds a household to the current users household account.
        /// </summary>
        /// <param name="command">Command for adding a household to the current users household account.</param>
        /// <returns>Service receipt.</returns>
        public virtual ServiceReceiptResponse Execute(HouseholdAddCommand 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.Name), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "Name")))
            .IsSatisfiedBy(() => CommonValidations.IsLengthValid(command.Name, 1, 64), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.LengthForPropertyIsInvalid, "Name", 1, 64)))
            .IsSatisfiedBy(() => CommonValidations.ContainsIllegalChar(command.Name) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "Name")))
            .IsSatisfiedBy(() => command.Description == null || CommonValidations.HasValue(command.Description), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "Description")))
            .IsSatisfiedBy(() => command.Description == null || CommonValidations.IsLengthValid(command.Description, 1, 2048), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.LengthForPropertyIsInvalid, "Description", 1, 2048)))
            .IsSatisfiedBy(() => command.Description == null || CommonValidations.ContainsIllegalChar(command.Description) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "Description")))
            .Evaluate();

            var household = HouseholdDataRepository.Insert <IHousehold>(new Household(command.Name, command.Description));

            try
            {
                var householdMember = HouseholdMemberGetCurrent(translationInfo.Identifier.HasValue ? translationInfo.Identifier.Value : default(Guid));
                household.HouseholdMemberAdd(householdMember);

                var updatedHousehold = HouseholdDataRepository.Update(household);

                return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(updatedHousehold, translationInfo.CultureInfo));
            }
            catch
            {
                HouseholdDataRepository.Delete(household);
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Upgrade membership on the current users household member account.
        /// </summary>
        /// <param name="householdMember">Household member on which the membership should be upgraded.</param>
        /// <param name="command">Command for upgrading the membership on the current users household member account.</param>
        /// <returns>Household member with the upgraded membership.</returns>
        public override IIdentifiable ModifyData(IHouseholdMember householdMember, HouseholdMemberUpgradeMembershipCommand command)
        {
            if (householdMember == null)
            {
                throw new ArgumentNullException("householdMember");
            }
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var dataProvider    = HouseholdDataRepository.Get <IDataProvider>(command.DataProviderIdentifier);
            var handlesPayments = dataProvider != null && dataProvider.HandlesPayments;

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(dataProvider), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.DataProviderIdentifier)))
            .IsSatisfiedBy(() => handlesPayments, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.DataProviderDoesNotHandlesPayments, dataProvider != null ? dataProvider.Name : null)))
            .Evaluate();

            var paymentReceipt  = string.IsNullOrWhiteSpace(command.PaymentReceipt) ? null : Convert.FromBase64String(command.PaymentReceipt);
            var insertedPayment = HouseholdDataRepository.Insert <IPayment>(new Payment(householdMember, dataProvider, command.PaymentTime, command.PaymentReference, paymentReceipt));

            try
            {
                householdMember.PaymentAdd(insertedPayment);
                householdMember.MembershipApply((Membership)Enum.Parse(typeof(Membership), command.Membership));

                return(HouseholdDataRepository.Update(householdMember));
            }
            catch
            {
                HouseholdDataRepository.Delete(insertedPayment);
                throw;
            }
        }
示例#3
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>
        /// Modifies the data.
        /// </summary>
        /// <param name="household">Household on which to modify data.</param>
        /// <param name="command">Command for updating a household to 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, HouseholdUpdateCommand command)
        {
            ArgumentNullGuard.NotNull(household, nameof(household))
            .NotNull(command, nameof(command));

            household.Name        = command.Name;
            household.Description = command.Description;

            return(HouseholdDataRepository.Update(household));
        }
        /// <summary>
        /// Activate the current users household member account.
        /// </summary>
        /// <param name="householdMember">Household member which should be activated.</param>
        /// <param name="command">Command for activating the current users household member account.</param>
        /// <returns>The activated household member.</returns>
        public override IIdentifiable ModifyData(IHouseholdMember householdMember, HouseholdMemberActivateCommand command)
        {
            if (householdMember == null)
            {
                throw new ArgumentNullException("householdMember");
            }

            householdMember.ActivationTime = DateTime.Now;

            return(HouseholdDataRepository.Update(householdMember));
        }
        /// <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));
        }
        /// <summary>
        /// Modifies the data.
        /// </summary>
        /// <param name="household">Household on which to modify data.</param>
        /// <param name="command">Command for removing a household member from 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, HouseholdRemoveHouseholdMemberCommand command)
        {
            ArgumentNullGuard.NotNull(household, nameof(household))
            .NotNull(command, nameof(command));

            IHouseholdMember householdMemberForMailAddress = household.HouseholdMembers.SingleOrDefault(householdMember => string.Compare(householdMember.MailAddress, command.MailAddress, StringComparison.OrdinalIgnoreCase) == 0);

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(householdMemberForMailAddress), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.HouseholdMemberDoesNotExistOnHousehold, command.MailAddress)))
            .Evaluate();

            household.HouseholdMemberRemove(householdMemberForMailAddress);

            return(HouseholdDataRepository.Update(household));
        }
示例#8
0
        /// <summary>
        /// Gets the translation information which should be used to translate data selected by this query.
        /// </summary>
        /// <param name="query">Query for getting some data for a household member.</param>
        /// <returns>Translation information which should be used to translate data selected by this query.</returns>
        private ITranslationInfo GetTranslationInfo(TQuery query)
        {
            ArgumentNullGuard.NotNull(query, nameof(query));

            HouseholdMemberTranslatableDataGetQueryBase householdMemberTranslatableDataGetQuery = query as HouseholdMemberTranslatableDataGetQueryBase;

            if (householdMemberTranslatableDataGetQuery == null)
            {
                return(null);
            }

            ITranslationInfo translationInfo = HouseholdDataRepository.Get <ITranslationInfo>(householdMemberTranslatableDataGetQuery.TranslationInfoIdentifier);

            if (translationInfo == null)
            {
                throw new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, householdMemberTranslatableDataGetQuery.TranslationInfoIdentifier));
            }

            return(translationInfo);
        }
示例#9
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));
        }
示例#10
0
        /// <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));
        }
示例#11
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));
        }