Beispiel #1
0
        protected override bool IsValid(PropertyValidatorContext context)
        {
            if (context.Instance == null || !(context.Instance is SourceCodeApplyEditModel))
            {
                return(false);
            }

            var instance = context.Instance as SourceCodeApplyEditModel;

            if (!string.IsNullOrEmpty(instance.SourceCode))
            {
                _sourceCode = _sourceCodeRepository.GetSourceCodeByCode(instance.SourceCode.Trim());
            }

            foreach (var func in _isValidatorList)
            {
                var result = func();
                if (!result)
                {
                    return(false);
                }
            }

            foreach (var func in _isParemterizedValidatorList)
            {
                var result = func(instance);
                if (!result)
                {
                    return(false);
                }
            }
            // TODO: To Apply Existing Customer/New Customer Check
            return(true);
        }
        //TODO: This will be pulled into the UpdateSourceCode in EventCustomerRepository once old order system is removed.
        private bool UpdateSourceCodeForExistingOrder(long eventCustomerId, string sourceCode, long userId, long shellId, long roleId)
        {
            IUniqueItemRepository <EventCustomer> itemRepository = new EventCustomerRepository();
            EventCustomer eventCustomer = itemRepository.GetById(eventCustomerId);

            var creatorOrganizationRoleUser = IoC.Resolve <IOrgRoleUserModelBinder>().ToDomain(
                IoC.Resolve <ISessionContext>().UserSession.CurrentOrganizationRole,
                IoC.Resolve <ISessionContext>().UserSession.UserId);

            var newSourceCode = _sourceCodeRepository.GetSourceCodeByCode(sourceCode);

            if (creatorOrganizationRoleUser == null || newSourceCode == null)
            {
                return(false);
            }

            try
            {
                var order = _orderRepository.GetOrder(eventCustomer.CustomerId, eventCustomer.EventId);

                OrderDetail orderDetail = _orderController.GetActiveOrderDetail(order);

                if (orderDetail == null)
                {
                    return(false);
                }

                newSourceCode.CouponValue = orderDetail.SourceCodeOrderDetail != null ? orderDetail.SourceCodeOrderDetail.Amount : 0.00m;

                return(_orderController.UpdateOrder(order, newSourceCode, creatorOrganizationRoleUser.Id) != null);
            }
            catch (ObjectNotFoundInPersistenceException <Order> )
            {
                return(false);
            }
        }
        public SourceCodeApplyEditModel ApplySourceCode(SourceCodeApplyEditModel model)
        {
            var result = _sourceCodeValidator.Validate(model);

            if (!result.IsValid)
            {
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage(result.Errors.First().ErrorMessage);
                return(model);
            }

            var sourceCode = _sourceCodeRepository.GetSourceCodeByCode(model.SourceCode.Trim());

            model.SourceCodeId = sourceCode.Id;

            switch (sourceCode.DiscountType)
            {
            case DiscountType.PerOrder:
                model.DiscountApplied = Calculate(sourceCode.CouponValue, model.OrderTotal, sourceCode.DiscountValueType);
                break;

            case DiscountType.PerPackage:
                if (sourceCode.PackageDiscounts != null)
                {
                    var packageDiscount = sourceCode.PackageDiscounts.Where(pd => pd.Id == model.Package.FirstValue).SingleOrDefault();

                    if (packageDiscount != null)
                    {
                        model.DiscountApplied = Calculate(packageDiscount.DiscountAmount, model.Package.SecondValue, packageDiscount.DiscountValueType);
                    }
                }

                if (sourceCode.TestDiscounts != null && model.SelectedTests != null)
                {
                    foreach (var test in model.SelectedTests)
                    {
                        var testDiscount = sourceCode.TestDiscounts.Where(td => td.Id == test.FirstValue).SingleOrDefault();

                        if (testDiscount != null)
                        {
                            model.DiscountApplied += Calculate(testDiscount.DiscountAmount, test.SecondValue, testDiscount.DiscountValueType);
                        }
                    }
                }
                break;

            case DiscountType.PerProduct:
                if (sourceCode.ProductDiscounts != null && model.SelectedProducts != null)
                {
                    foreach (var product in model.SelectedProducts)
                    {
                        var prooductDiscount = sourceCode.ProductDiscounts.Where(pd => pd.Id == product.FirstValue).SingleOrDefault();

                        if (prooductDiscount != null)
                        {
                            model.DiscountApplied = Calculate(prooductDiscount.DiscountAmount, product.SecondValue, prooductDiscount.DiscountValueType);
                        }
                    }
                }
                break;

            case DiscountType.PerShipping:
                if (sourceCode.ShippingDiscounts != null && model.SelectedShipping != null)
                {
                    foreach (var shipping in model.SelectedShipping)
                    {
                        var shippingDiscount = sourceCode.ShippingDiscounts.Where(sd => sd.Id == shipping.FirstValue).SingleOrDefault();

                        if (shippingDiscount != null)
                        {
                            model.DiscountApplied = Calculate(shippingDiscount.DiscountAmount, shipping.SecondValue, shippingDiscount.DiscountValueType);
                        }
                    }
                }
                break;
            }

            return(model);
        }
Beispiel #4
0
        public TempCart SaveSelectedEvent(TempCart tempCart, OnlineSelectedEventEditModel model)
        {
            long sourceCodeId = 0;

            if (!string.IsNullOrEmpty(model.CouponCode))
            {
                var sourceCode = _sourceCodeRepository.GetSourceCodeByCode(model.CouponCode);
                if (sourceCode != null)
                {
                    sourceCodeId = sourceCode.Id;
                }
            }

            if (tempCart == null)
            {
                tempCart = new TempCart
                {
                    ZipCode        = model.ZipCode,
                    EventId        = model.EventId,
                    InvitationCode = model.InvitationCode,
                    CorpCode       = model.InvitationCode,
                    Radius         = model.Radius,
                    Guid           = Guid.NewGuid().ToString(),
                    EntryPage      = model.RequestUrl,
                    ExitPage       = model.RequestUrl,
                    SourceCodeId   = sourceCodeId > 0 ? (long?)sourceCodeId : null
                };
            }
            else
            {
                if (tempCart.EventId != model.EventId)
                {
                    tempCart.ZipCode                 = string.IsNullOrEmpty(model.ZipCode) ? tempCart.ZipCode : model.ZipCode;
                    tempCart.Radius                  = model.Radius.HasValue ? model.Radius : tempCart.Radius;
                    tempCart.EventId                 = model.EventId;
                    tempCart.ExitPage                = model.RequestUrl;
                    tempCart.EventPackageId          = null;
                    tempCart.TestId                  = null;
                    tempCart.ShippingId              = null;
                    tempCart.ProductId               = null;
                    tempCart.PreliminarySelectedTime = null;
                    tempCart.AppointmentId           = null;
                    tempCart.InChainAppointmentSlots = null;

                    if (tempCart.AppointmentId.HasValue)
                    {
                        _eventSchedulingSlotRepository.ReleaseSlots(tempCart.InChainAppointmentSlotIds);
                    }
                }
            }

            if (tempCart.Id > 0)
            {
                tempCart.DateModified = DateTime.Now;
            }
            else
            {
                tempCart.DateCreated = DateTime.Now;
            }

            tempCart = _tempCartRepository.Save(tempCart);

            return(tempCart);
        }