Exemple #1
0
        private async Task <bool> handleActivation(Order order)
        {
            var activated = await membershipRepository.ActivateMembership(order);

            if (activated)
            {
                return(await emailRepository.SendActivationMail(order));
            }

            return(false);
        }
Exemple #2
0
        public async Task ProcessAsync(Order order)
        {
            foreach (var cartItem in order.CartItems.Values)
            {
                var membershipItem = cartItem.Item as MembershipItem;
                if (membershipItem == null)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(membershipItem.MembershipEmail))
                {
                    throw new ArgumentNullException(nameof(membershipItem.MembershipEmail));
                }

                if (Equals(membershipItem.MembershipId, Guid.Empty))
                {
                    throw new ArgumentException($"{nameof(membershipItem.MembershipEmail)} is not set.");
                }

                string message = string.Empty;
                string title   = string.Empty;

                // TODO : the if statement should check the item SKU and act based on that; kept is like this for simplicity
                if (cartItem.Item.Name == Constants.ItemNames.MembershipActivation)
                {
                    // TODO: ValidateMembership Id and throw if it is not valid or doesnt exist; Alternatively it could also happens in the repo

                    await membershipRepository.ActivateMembership(membershipItem.MembershipId);

                    title   = Messages.MembershipActivationEmailTitle;
                    message = Messages.MembershipActivationEmailTemplate;
                }
                else if (cartItem.Item.Name == Constants.ItemNames.MembershipUpgrade)
                {
                    // TODO: ValidateMembership class to verify the new class is higher than the current one (downgrade is not supported here)

                    await membershipRepository.UpgradeMembership(membershipItem.MembershipId, membershipItem.MembershipClass);

                    title   = Messages.MembershipUpgradeEmailTitle;
                    message = string.Format(Messages.MembershipActivationEmailTemplate, membershipItem.MembershipClass);
                }

                await emailClient.Send(membershipItem.MembershipEmail, title, message);
            }

            //TODO : optional sending an email to the customer with all the memberships that got activated or upgraded
            //await this.emailClient.Send(order.Customer.Address, title, message);
        }