/// <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;
            }
        }
Ejemplo 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;
            }
        }