Exemplo n.º 1
0
        public ServiceResult CancelRegistration(int existingRegistrationId)
        {
            var              result          = new ServiceResult();
            IEmailService    emailService    = new EmailService();
            IDiscountService discountService = new DiscountService(this._repository, false);

            Registration cancelReg = _repository.Registrations.Find(x => x.RegistrationId == existingRegistrationId);

            cancelReg.RegistrationStatus = RegistrationStatus.Cancelled;
            cancelReg.DateUpdated        = DateTime.Now;

            var newTransferCode = new RedemptionCode
            {
                GeneratingRegistrationId = existingRegistrationId,
                Code = discountService.GenerateDiscountCode(),
                RedemptionCodeType = RedemptionCodeType.StraightValue,
                Value        = GetRegistrationPathValue(existingRegistrationId),
                DiscountType = DiscountType.Dollars
            };

            result = discountService.CreateRedemptionCode(newTransferCode);

            if (!_sharedRepository)
            {
                _repository.SaveChanges();
                emailService.SendCancellationEmail(newTransferCode.DiscountItemId);
            }


            return(result);
        }
Exemplo n.º 2
0
        public ServiceResult CancelRegistration(int existingRegistrationId)
        {
            var result = new ServiceResult();
            IEmailService emailService = new EmailService();
            IDiscountService discountService = new DiscountService(this._repository, false);

            Registration cancelReg = _repository.Registrations.Find(x => x.RegistrationId == existingRegistrationId);
            cancelReg.RegistrationStatus = RegistrationStatus.Cancelled;
            cancelReg.DateUpdated = DateTime.Now;

            var newTransferCode = new RedemptionCode
            {
                GeneratingRegistrationId = existingRegistrationId,
                Code = discountService.GenerateDiscountCode(),
                RedemptionCodeType = RedemptionCodeType.StraightValue,
                Value = GetRegistrationPathValue(existingRegistrationId),
                DiscountType = DiscountType.Dollars
            };

            result = discountService.CreateRedemptionCode(newTransferCode);

            if (!_sharedRepository)
            {
                _repository.SaveChanges();
                emailService.SendCancellationEmail(newTransferCode.DiscountItemId);
            }

            return result;
        }
Exemplo n.º 3
0
        public ServiceResult TransferRegistration(int existingRegistrationId, string name, string email)
        {
            ServiceResult result = null;

            IEmailService emailService    = new EmailService();
            var           discountService = new DiscountService(this._repository, false);

            Registration transferReg = _repository.Registrations.Find(x => x.RegistrationId == existingRegistrationId);

            transferReg.RegistrationStatus = RegistrationStatus.Held;
            transferReg.DateUpdated        = DateTime.Now;

            var newTransferCode = new RedemptionCode
            {
                GeneratingRegistrationId = existingRegistrationId,
                Code = discountService.GenerateDiscountCode(),
                RedemptionCodeType = RedemptionCodeType.Transfer,
                Value        = GetRegistrationPathValue(existingRegistrationId),
                DiscountType = DiscountType.Dollars
            };

            result = discountService.CreateRedemptionCode(newTransferCode);

            if (!_sharedRepository)
            {
                _repository.SaveChanges();
                emailService.SendTransferEmail(newTransferCode.DiscountItemId, name, email);
            }

            return(result);
        }
Exemplo n.º 4
0
        public ServiceResult TransferRegistration(int existingRegistrationId, string name, string email)
        {
            ServiceResult result = null;

            IEmailService emailService = new EmailService();
            var discountService = new DiscountService(this._repository, false);

            Registration transferReg = _repository.Registrations.Find(x => x.RegistrationId == existingRegistrationId);
            transferReg.RegistrationStatus = RegistrationStatus.Held;
            transferReg.DateUpdated = DateTime.Now;

            var newTransferCode = new RedemptionCode
            {
                GeneratingRegistrationId = existingRegistrationId,
                Code = discountService.GenerateDiscountCode(),
                RedemptionCodeType = RedemptionCodeType.Transfer,
                Value = GetRegistrationPathValue(existingRegistrationId),
                DiscountType = DiscountType.Dollars
            };

            result = discountService.CreateRedemptionCode(newTransferCode);

            if (!_sharedRepository)
            {
                _repository.SaveChanges();
                emailService.SendTransferEmail(newTransferCode.DiscountItemId, name, email);
            }

            return result;
        }
Exemplo n.º 5
0
        private bool ApplyDiscount(CartSummary cartSummary, SessionCart currentCart)
        {
            DiscountItem discount = _repository.DiscountItems.Find(x => x.Code.ToLower() == currentCart.DiscountCode.ToLower());

            if (discount != null)
            {
                if (cartSummary.TotalCost == 0) {
                    discount = null;
                    currentCart.DiscountCode = null;
                    cartSummary.SummaryMessages.Add("You cannot apply a discount code to this cart. There are no charges.");
                }

                if (discount is RedemptionCode)
                {
                    var discountableRegList = cartSummary.CartItems.Where(x => x.PurchaseType == PurchaseType.Registration && x.Discountable == true).OrderByDescending(x => x.ItemCost).ToList();

                    if (discountableRegList.Count() > 0)
                    {
                        RedemptionCode code = (RedemptionCode)discount;

                        IDiscountService discountService = new DiscountService(this._repository, false);
                        ServiceResult validationResult = discountService.ValidateDiscount(code);

                        if (validationResult.Success)
                        {
                            var cost = discountableRegList[0].ItemCost;
                            var discountValue = code.DiscountType == DiscountType.Dollars ? code.Value : cost * (code.Value / 100);

                            discountableRegList[0].DiscountItemId = code.DiscountItemId;
                            discountableRegList[0].DiscountDescription = code.Code;
                            discountableRegList[0].DiscountType = code.DiscountType;
                            discountableRegList[0].DiscountValue = discountableRegList[0].ItemTotal <= 0 ? cost : discountValue;

                            if (NeedToRemoveProcessingFee(currentCart, code))
                                RemoveProcessingFee(cartSummary);
                        }
                        else
                            cartSummary.SummaryMessages.Add(validationResult.GetServiceErrors().First().ErrorMessage);
                    }
                    else
                        cartSummary.SummaryMessages.Add("There are no applicable items for this discount.");
                }

                if (discount is Coupon)
                {
                    Coupon coupon = (Coupon)discount;
                    IDiscountService discountService = new DiscountService(this._repository, false);
                    ServiceResult validationResult = discountService.ValidateDiscount(coupon);

                    if (validationResult.Success)
                    {
                        switch (coupon.CouponType)
                        {
                            case CouponType.Registration:
                                var discountableRegList = cartSummary.CartItems.Where(
                                                x => x.PurchaseType == PurchaseType.Registration &&
                                                x.Discountable == true &&
                                                x.EventId == ((coupon.EventId.HasValue) ? coupon.EventId.Value : x.EventId)).OrderByDescending(x => x.ItemCost).ToList();

                                if (discountableRegList.Any())
                                {
                                    var cost = discountableRegList[0].ItemCost;
                                    var discountValue = coupon.DiscountType == DiscountType.Dollars ? coupon.Value : cost * (coupon.Value / 100);
                                    var discountedCost = cost - discountValue;

                                    discountableRegList[0].DiscountItemId = coupon.DiscountItemId;
                                    discountableRegList[0].DiscountDescription = coupon.Code;
                                    discountableRegList[0].DiscountType = coupon.DiscountType;
                                    discountableRegList[0].DiscountValue = discountableRegList[0].ItemTotal <= 0 ? cost : discountValue;

                                    if (NeedToRemoveProcessingFee(currentCart, coupon))
                                        RemoveProcessingFee(cartSummary);
                                }
                                else
                                    cartSummary.SummaryMessages.Add("There are no applicable items for this discount.");

                                break;
                        }
                    }
                    else
                        cartSummary.SummaryMessages.Add(validationResult.GetServiceErrors().First().ErrorMessage);
                }
            }
            else
                cartSummary.SummaryMessages.Add("This discount does not exist.");

            return cartSummary.SummaryMessages.Count <= 0;
        }
Exemplo n.º 6
0
        private bool ApplyDiscount(CartSummary cartSummary, SessionCart currentCart)
        {
            DiscountItem discount = _repository.DiscountItems.Find(x => x.Code.ToLower() == currentCart.DiscountCode.ToLower());

            if (discount != null)
            {
                if (cartSummary.TotalCost == 0)
                {
                    discount = null;
                    currentCart.DiscountCode = null;
                    cartSummary.SummaryMessages.Add("You cannot apply a discount code to this cart. There are no charges.");
                }

                if (discount is RedemptionCode)
                {
                    var discountableRegList = cartSummary.CartItems.Where(x => x.PurchaseType == PurchaseType.Registration && x.Discountable == true).OrderByDescending(x => x.ItemCost).ToList();

                    if (discountableRegList.Count() > 0)
                    {
                        RedemptionCode code = (RedemptionCode)discount;

                        IDiscountService discountService  = new DiscountService(this._repository, false);
                        ServiceResult    validationResult = discountService.ValidateDiscount(code);

                        if (validationResult.Success)
                        {
                            var cost          = discountableRegList[0].ItemCost;
                            var discountValue = code.DiscountType == DiscountType.Dollars ? code.Value : cost * (code.Value / 100);

                            discountableRegList[0].DiscountItemId      = code.DiscountItemId;
                            discountableRegList[0].DiscountDescription = code.Code;
                            discountableRegList[0].DiscountType        = code.DiscountType;
                            discountableRegList[0].DiscountValue       = discountableRegList[0].ItemTotal <= 0 ? cost : discountValue;

                            if (NeedToRemoveProcessingFee(currentCart, code))
                            {
                                RemoveProcessingFee(cartSummary);
                            }
                        }
                        else
                        {
                            cartSummary.SummaryMessages.Add(validationResult.GetServiceErrors().First().ErrorMessage);
                        }
                    }
                    else
                    {
                        cartSummary.SummaryMessages.Add("There are no applicable items for this discount.");
                    }
                }

                if (discount is Coupon)
                {
                    Coupon           coupon           = (Coupon)discount;
                    IDiscountService discountService  = new DiscountService(this._repository, false);
                    ServiceResult    validationResult = discountService.ValidateDiscount(coupon);

                    if (validationResult.Success)
                    {
                        switch (coupon.CouponType)
                        {
                        case CouponType.Registration:
                            var discountableRegList = cartSummary.CartItems.Where(
                                x => x.PurchaseType == PurchaseType.Registration &&
                                x.Discountable == true &&
                                x.EventId == ((coupon.EventId.HasValue) ? coupon.EventId.Value : x.EventId)).OrderByDescending(x => x.ItemCost).ToList();

                            if (discountableRegList.Any())
                            {
                                var cost           = discountableRegList[0].ItemCost;
                                var discountValue  = coupon.DiscountType == DiscountType.Dollars ? coupon.Value : cost * (coupon.Value / 100);
                                var discountedCost = cost - discountValue;

                                discountableRegList[0].DiscountItemId      = coupon.DiscountItemId;
                                discountableRegList[0].DiscountDescription = coupon.Code;
                                discountableRegList[0].DiscountType        = coupon.DiscountType;
                                discountableRegList[0].DiscountValue       = discountableRegList[0].ItemTotal <= 0 ? cost : discountValue;

                                if (NeedToRemoveProcessingFee(currentCart, coupon))
                                {
                                    RemoveProcessingFee(cartSummary);
                                }
                            }
                            else
                            {
                                cartSummary.SummaryMessages.Add("There are no applicable items for this discount.");
                            }

                            break;
                        }
                    }
                    else
                    {
                        cartSummary.SummaryMessages.Add(validationResult.GetServiceErrors().First().ErrorMessage);
                    }
                }
            }
            else
            {
                cartSummary.SummaryMessages.Add("This discount does not exist.");
            }

            return(cartSummary.SummaryMessages.Count <= 0);
        }
Exemplo n.º 7
0
        public ServiceResult ValidateRedemptionCodeForUserId(string code, int userId)
        {
            DiscountService discountService = new DiscountService(this._repository, false);

            return(discountService.ValidateRedemptionCodeForUserId(code, userId));
        }
Exemplo n.º 8
0
        public ServiceResult ValidateRedemptionCode(string code)
        {
            DiscountService discountService = new DiscountService(this._repository, false);

            return(discountService.ValidateRedemptionCode(code));
        }
Exemplo n.º 9
0
 public ServiceResult ValidateRedemptionCodeForUserId(string code, int userId)
 {
     DiscountService discountService = new DiscountService(this._repository, false);
     return discountService.ValidateRedemptionCodeForUserId(code, userId);
 }
Exemplo n.º 10
0
 public ServiceResult ValidateRedemptionCode(string code)
 {
     DiscountService discountService = new DiscountService(this._repository, false);
     return discountService.ValidateRedemptionCode(code);
 }