/// <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;
            }
        }
Esempio n. 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;
            }
        }
        /// <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>
        /// 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));
        }
Esempio n. 6
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));
        }