Exemplo n.º 1
0
        public SourceCodeApplyEditModel ApplySourceCode(string guid, SourceCodeApplyEditModel model)
        {
            var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(guid);

            if (onlineRequestValidationModel.RequestStatus != OnlineRequestStatus.Valid)
            {
                return new SourceCodeApplyEditModel
                       {
                           RequestValidationModel = onlineRequestValidationModel
                       }
            }
            ;

            model = _eventSchedulerService.ApplySourceCode(model);
            model.RequestValidationModel = onlineRequestValidationModel;

            var tempCart = onlineRequestValidationModel.TempCart;

            if (model.SourceCodeId > 0)
            {
                tempCart.SourceCodeId = model.SourceCodeId;
            }
            else
            {
                tempCart.SourceCodeId = null;
            }

            _tempcartService.SaveTempCart(tempCart);
            return(model);
        }
Exemplo n.º 2
0
        public SourceCodeApplyEditModel ApplySourceCode(long packageId, IEnumerable <long> addOnTestIds, decimal orderTotal, string sourceCode, long eventId, long customerId, SignUpMode signUpMode, decimal shippingAmount = 0, decimal productAmount = 0)
        {
            var model = new SourceCodeApplyEditModel
            {
                OrderTotal = orderTotal,
                SourceCode = sourceCode,
                SignUpMode = (int)signUpMode,
                CustomerId = customerId,
                EventId    = eventId
            };

            if (packageId > 0)
            {
                var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId);
                if (eventPackage != null)
                {
                    model.Package = new OrderedPair <long, decimal>(eventPackage.PackageId, eventPackage.Price);
                }
            }
            if (addOnTestIds != null && addOnTestIds.Count() > 0)
            {
                var eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, addOnTestIds);
                if (eventTests != null && eventTests.Count > 0)
                {
                    model.SelectedTests = eventTests.Select(et => new OrderedPair <long, decimal>(et.TestId, packageId > 0 ? et.WithPackagePrice : et.Price));
                }
            }

            model = ApplySourceCode(model);
            return(model);
        }
Exemplo n.º 3
0
        private bool IsValidPackage(SourceCodeApplyEditModel instance)
        {
            bool isValid = false;

            if (_sourceCode.DiscountType != DiscountType.PerPackage)
            {
                return(true);
            }

            if (_sourceCode.PackageDiscounts != null && _sourceCode.PackageDiscounts.Count() > 0 && instance.Package != null)
            {
                var package = _sourceCode.PackageDiscounts.Where(pd => pd.Id == instance.Package.FirstValue).SingleOrDefault();
                isValid = package != null;
            }

            if (_sourceCode.TestDiscounts != null && _sourceCode.TestDiscounts.Count() > 0 && instance.SelectedTests != null)
            {
                var tests = _sourceCode.TestDiscounts.Where(td => instance.SelectedTests.Select(i => i.FirstValue).Contains(td.Id)).ToArray();
                isValid = tests.Count() > 0;
            }

            if (!isValid)
            {
                _message = _sourceCodelabel + " is not applicable to the selected Package/Test Type.";
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        private bool IsValidForMinimumPurchaseAmount(SourceCodeApplyEditModel instance)
        {
            _message = string.Format("This " + _sourceCodelabel + " is applicable on Minimum Purchase Amount (${0}).",
                                     _sourceCode.MinimumPurchaseAmount != null ? _sourceCode.MinimumPurchaseAmount.Value.ToString("0.00") : "");

            return(_sourceCode.MinimumPurchaseAmount == null || _sourceCode.MinimumPurchaseAmount.Value == 0 || (_sourceCode.MinimumPurchaseAmount.Value > 0 && _sourceCode.MinimumPurchaseAmount.Value <= instance.OrderTotal));
        }
Exemplo n.º 5
0
        private bool IsValidCustomerType(SourceCodeApplyEditModel instance)
        {
            if ((int)_sourceCode.CustomerType > 0)
            {
                if (instance.CustomerId == 0 && _sourceCode.CustomerType == CustomerType.New)
                {
                    return(true);
                }

                var eventCustomers = _eventCustomerRepository.GetbyCustomerId(instance.CustomerId);
                if (_sourceCode.CustomerType == CustomerType.New && (eventCustomers == null || eventCustomers.Count() < 1 || eventCustomers.Where(ec => ec.TestConducted).Count() < 1))
                {
                    return(true);
                }

                if (_sourceCode.CustomerType == CustomerType.Existing && eventCustomers != null && eventCustomers.Count() > 0 && eventCustomers.Where(ec => ec.TestConducted).Count() > 0)
                {
                    return(true);
                }

                _message = _sourceCode.CustomerType == CustomerType.Existing ? "This " + _sourceCodelabel + " is applicable to Existing Customers only (i.e. who have atleast attended one screening Event)." : "This " + _sourceCodelabel + " is applicable to New Customers only.";
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        private bool IsValidSignUpMode(SourceCodeApplyEditModel instance)
        {
            if (_sourceCode.SelectedSignUpModes == null || _sourceCode.SelectedSignUpModes.Count() < 1)
            {
                return(true);
            }

            var count = _sourceCode.SelectedSignUpModes.Where(sm => (int)sm == instance.SignUpMode).Count();

            _message = "Invalid " + _sourceCodelabel + "!";
            return(count > 0);
        }
Exemplo n.º 7
0
        private bool IsValidForMaximumUsageCount(SourceCodeApplyEditModel instance)
        {
            var  count             = _sourceCodeOrderDetailRepository.GetSourceCodeUsageCount(_sourceCode.Id);
            bool repeatForCustomer = false;

            if (instance.CustomerId > 0 && instance.EventId > 0)
            {
                repeatForCustomer = _sourceCodeOrderDetailRepository.IsSourceCodeAppliedforGivenEventCustomer(_sourceCode.Id, instance.EventId, instance.CustomerId);
            }

            _message = "This " + _sourceCodelabel + " has reached its maximum usage count!";
            return(_sourceCode.MaximumNumberTimesUsed < 1 || _sourceCode.MaximumNumberTimesUsed > count || repeatForCustomer);
        }
Exemplo n.º 8
0
        private bool IsValidEvent(SourceCodeApplyEditModel instance)
        {
            if (_sourceCode.EventIds == null || _sourceCode.EventIds.Count() < 1)
            {
                return(true);
            }

            if (_sourceCode.EventIds.Contains(instance.EventId))
            {
                return(true);
            }
            _message = "This " + _sourceCodelabel + " is not applicable for the selected event.";
            return(false);
        }
Exemplo n.º 9
0
        private bool IsValidShippingMode(SourceCodeApplyEditModel instance)
        {
            bool isValid = false;

            if (_sourceCode.DiscountType != DiscountType.PerShipping)
            {
                return(true);
            }

            if (_sourceCode.ShippingDiscounts != null && _sourceCode.ShippingDiscounts.Count() > 0 && instance.SelectedShipping != null)
            {
                var product = _sourceCode.ShippingDiscounts.Where(sd => instance.SelectedShipping.Select(i => i.FirstValue).Contains(sd.Id)).SingleOrDefault();
                isValid = product != null;
            }

            if (!isValid)
            {
                _message = _sourceCodelabel + " is not applicable to the selected Shipping Mode.";
                return(false);
            }

            return(true);
        }
Exemplo n.º 10
0
        public EventCustomerOrderSummaryModel GetEventCustomerOrderSummaryModel(TempCart tempCart, OrderPlaceEditModel orderPlaceEditModel, SourceCodeApplyEditModel sourceCodeModel)
        {
            if (tempCart == null)
            {
                return(new EventCustomerOrderSummaryModel());
            }

            Event theEvent  = null;
            Host  eventHost = null;

            if (tempCart.EventId.HasValue)
            {
                theEvent  = _eventRepository.GetById(tempCart.EventId.Value);
                eventHost = _hostRepository.GetHostForEvent(tempCart.EventId.Value);
            }

            EventSchedulingSlot appointment = null;

            if (tempCart.AppointmentId.HasValue)
            {
                appointment = _slotRepository.GetbyId(tempCart.AppointmentId.Value);
            }

            EventPackage eventPackage = null;

            if (orderPlaceEditModel.SelectedPackageId > 0)
            {
                eventPackage = _eventPackageRepository.GetById(orderPlaceEditModel.SelectedPackageId);
            }

            IEnumerable <EventTest> eventTests = null;

            if (orderPlaceEditModel.SelectedTestIds != null && orderPlaceEditModel.SelectedTestIds.Count() > 0)
            {
                eventTests = _eventTestRepository.GetbyIds(orderPlaceEditModel.SelectedTestIds);
            }

            IEnumerable <ElectronicProduct> products = null;

            if (orderPlaceEditModel.SelectedProductIds != null && orderPlaceEditModel.SelectedProductIds.Count() > 0)
            {
                products = _productRepository.GetByIds(orderPlaceEditModel.SelectedProductIds);
            }

            ShippingOption shippingOption = null;

            if (orderPlaceEditModel.SelectedShippingOptionId > 0)
            {
                shippingOption = _shippingOptionRepository.GetById(orderPlaceEditModel.SelectedShippingOptionId);
            }

            Order order = null;

            if (tempCart.IsCompleted)
            {
                order = _orderRepository.GetOrder(tempCart.CustomerId.Value, tempCart.EventId.Value);
            }
            return(_eventCustomerSummaryModelFactory.Create(theEvent, eventHost, appointment, eventPackage, eventTests, products, shippingOption, sourceCodeModel, order, tempCart.ShippingId));
        }
Exemplo n.º 11
0
        public EventCustomerOrderSummaryModel GetEventCustomerOrderSummaryModel(TempCart tempCart, SourceCodeApplyEditModel sourceCodeModel = null)
        {
            if (tempCart == null)
            {
                return(new EventCustomerOrderSummaryModel());
            }

            Event theEvent  = null;
            Host  eventHost = null;

            if (tempCart.EventId.HasValue)
            {
                theEvent  = _eventRepository.GetById(tempCart.EventId.Value);
                eventHost = _hostRepository.GetHostForEvent(tempCart.EventId.Value);
            }

            EventSchedulingSlot appointment = null;

            if (tempCart.AppointmentId.HasValue)
            {
                appointment = _slotRepository.GetbyId(tempCart.AppointmentId.Value);
            }

            EventPackage eventPackage = null;

            if (tempCart.EventPackageId.HasValue)
            {
                eventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value);
            }

            IEnumerable <EventTest> eventTests = null;
            var testIds = new List <long>();

            if (!string.IsNullOrEmpty(tempCart.TestId))
            {
                string[] testIdStrings = tempCart.TestId.Split(new[] { ',' });
                foreach (var testIdString in testIdStrings)
                {
                    int i = 0;
                    if (int.TryParse(testIdString, out i))
                    {
                        testIds.Add(i);
                    }
                }
            }

            if (testIds.Count > 0)
            {
                eventTests = _eventTestRepository.GetbyIds(testIds);
            }

            IEnumerable <ElectronicProduct> products = null;

            var productIds = new List <long>();

            if (!string.IsNullOrEmpty(tempCart.ProductId))
            {
                string[] productIdStrings = tempCart.ProductId.Split(new[] { ',' });
                foreach (var productIdIdString in productIdStrings)
                {
                    int i = 0;
                    if (int.TryParse(productIdIdString, out i))
                    {
                        productIds.Add(i);
                    }
                }
            }

            if (productIds.Count > 0)
            {
                products = _productRepository.GetByIds(productIds);
            }

            ShippingOption shippingOption = null;

            if (tempCart.ShippingId.HasValue && tempCart.ShippingId.Value > 0)
            {
                shippingOption = _shippingOptionRepository.GetById(tempCart.ShippingId.Value);
            }


            SourceCodeApplyEditModel applySourceCodemodel = sourceCodeModel ?? GetSourceCodeApplied(tempCart);

            Order order = null;

            if (tempCart.IsCompleted)
            {
                order = _orderRepository.GetOrder(tempCart.CustomerId.Value, tempCart.EventId.Value);
            }

            return(_eventCustomerSummaryModelFactory.Create(theEvent, eventHost, appointment, eventPackage, eventTests, products, shippingOption, applySourceCodemodel, order, tempCart.ShippingId));
        }
Exemplo n.º 12
0
        public SourceCodeApplyEditModel GetSourceCodeApplied(TempCart tempCart, SourceCodeApplyEditModel sourceCodeModel = null)
        {
            var model = new SourceCodeApplyEditModel
            {
                SignUpMode = (int)SignUpMode.Online,
                SourceCodeHelpDescription = _toolTipRepository.GetToolTipContentByTag(ToolTipType.SourceCodeHelp)
            };

            if (tempCart == null)
            {
                return(model);
            }

            if (tempCart.EventId.HasValue)
            {
                model.EventId = tempCart.EventId.Value;
            }

            if (tempCart.CustomerId.HasValue)
            {
                model.CustomerId = tempCart.CustomerId.Value;
            }

            decimal orderTotal = 0;

            if (tempCart.EventPackageId.HasValue)
            {
                var eventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value);
                model.Package = new OrderedPair <long, decimal>(eventPackage.PackageId, eventPackage.Price);
                orderTotal   += model.Package.SecondValue;
            }

            if (!string.IsNullOrEmpty(tempCart.TestId))
            {
                var eventTestIds = tempCart.TestId.Split(new[] { ',' }).Select(t => Convert.ToInt64(t.Trim()));
                var eventTests   = _eventTestRepository.GetbyIds(eventTestIds);
                model.SelectedTests = eventTests.Select(et => new OrderedPair <long, decimal>(et.TestId, tempCart.EventPackageId.HasValue ? et.WithPackagePrice : et.Price)).ToArray();
                orderTotal         += model.SelectedTests.Sum(s => s.SecondValue);
            }

            if (tempCart.ShippingId.HasValue && tempCart.ShippingId.Value > 0)
            {
                var shippingOption = _shippingOptionRepository.GetById(tempCart.ShippingId.Value);
                model.ShippingAmount = shippingOption.Price;
                orderTotal          += model.ShippingAmount;
            }

            if (!string.IsNullOrEmpty(tempCart.ProductId))
            {
                var productids = tempCart.ProductId.Split(new[] { ',' }).Select(t => Convert.ToInt64(t.Trim()));
                var products   = _productRepository.GetByIds(productids);
                model.ProductAmount = products.Sum(p => p.Price);
                orderTotal         += model.ProductAmount;
            }

            model.OrderTotal = orderTotal;

            if (sourceCodeModel != null && sourceCodeModel.SourceCodeId > 0)
            {
                var sourceCode = _sourceCodeRepository.GetSourceCodeById(sourceCodeModel.SourceCodeId);
                model.SourceCode = sourceCode.CouponCode;
                model            = ApplySourceCode(model);
            }
            else if (tempCart.SourceCodeId.HasValue && tempCart.SourceCodeId > 0)
            {
                var sourceCode = _sourceCodeRepository.GetSourceCodeById(tempCart.SourceCodeId.Value);
                model.SourceCode = sourceCode.CouponCode;
                model            = ApplySourceCode(model);
            }

            return(model);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        public OnlineSchedulingCustomerInfoEditModel SavePaymentInfo(OnlineSchedulingCustomerInfoEditModel model)
        {
            OnlineSchedulingProcessAndCartViewModel cartModel = model.ProcessAndCartViewModel;
            SourceCodeApplyEditModel sourceCodeModel          = model.SourceCodeApplyEditModel;
            PaymentEditModel         paymentModel             = model.PaymentEditModel;

            var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(cartModel.CartGuid);

            model.RequestValidationModel = onlineRequestValidationModel;

            if (onlineRequestValidationModel.RequestStatus != OnlineRequestStatus.Valid)
            {
                return(model);
            }
            var tempCart = onlineRequestValidationModel.TempCart;


            if (tempCart.EventId.HasValue)
            {
                var summarymodel = _eventSchedulerService.GetEventCustomerOrderSummaryModel(tempCart);

                var couponAmount = sourceCodeModel != null ? sourceCodeModel.DiscountApplied : 0;
                if ((summarymodel.TotalPrice != null && summarymodel.TotalPrice.Value != (paymentModel.Amount + couponAmount)) || (summarymodel.TotalPrice == null && paymentModel.Amount > 0))
                {
                    throw new Exception("Seems like you changed your order. Please go back to the Package screen, and confirm!");
                }

                var result = ValidatePaymentModel(paymentModel);
                if (!result)
                {
                    throw new Exception("Payment error - Please re-enter your payment information or contact our customer care line at " +
                                        _settings.PhoneTollFree);
                }

                var isAppointmentTemporarilyBooked = _slotService.IsSlotTemporarilyBooked(tempCart.InChainAppointmentSlotIds);
                if (!isAppointmentTemporarilyBooked)
                {
                    //throw new Exception("The appointment time selected by you is no longer temporarliy booked for you. Please go back to appointment page to choose the time slot");
                    model.PaymentEditModel.IsTemporaryBookedSlotExpired = true;
                    return(model);
                }


                var isAppointmentBooked = _slotService.IsSlotBooked(tempCart.InChainAppointmentSlotIds);
                if (isAppointmentBooked)
                {
                    throw new Exception("The appointment slot selected by you seems to have exhausted. Please re-select another slot!");
                }
            }
            bool?    paymentSucceded = null;
            Customer customer;

            try
            {
                using (var scope = new TransactionScope())
                {
                    customer = tempCart.CustomerId.HasValue ? _customerRepository.GetCustomer(tempCart.CustomerId.Value) : null;

                    var address = Mapper.Map <AddressEditModel, Address>(paymentModel.ExistingShippingAddress);

                    address = _addressService.SaveAfterSanitizing(address, true);

                    if (customer == null)
                    {
                        throw new Exception("System Failure! Data not saved. Please try again.");
                    }

                    var customerAddress = Mapper.Map <AddressEditModel, Address>(paymentModel.ExistingShippingAddress);
                    customerAddress  = _addressService.SaveAfterSanitizing(customerAddress, true);
                    customer.Address = customerAddress;

                    customer.RequestForNewsLetter = model.RequestForNewsLetter;

                    if (paymentModel.Payments != null && paymentModel.Payments.Where(p => p.PaymentType != PaymentType.Onsite_Value && p.PaymentType != PaymentType.GiftCertificate.PersistenceLayerId).Count() > 0)
                    {
                        if (paymentModel.ExistingBillingAddress != null)
                        {
                            if (customer.BillingAddress != null && customer.BillingAddress.Id > 0)
                            {
                                paymentModel.ExistingBillingAddress.Id = customer.BillingAddress.Id;
                            }

                            var billingAddress = Mapper.Map <AddressEditModel, Address>(paymentModel.ExistingBillingAddress);
                            billingAddress = _addressService.SaveAfterSanitizing(billingAddress, true);

                            customer.BillingAddress = billingAddress;
                        }
                    }
                    else
                    {
                        var billingAddress = Mapper.Map <AddressEditModel, Address>(paymentModel.ExistingShippingAddress);
                        billingAddress = _addressService.SaveAfterSanitizing(billingAddress, true);

                        customer.BillingAddress = billingAddress;
                    }

                    _customerService.SaveCustomer(customer, customer.CustomerId);

                    tempCart.SourceCodeId = sourceCodeModel == null || sourceCodeModel.SourceCodeId < 1
                                                ? null
                                                : (long?)sourceCodeModel.SourceCodeId;

                    tempCart.ShippingAddressId = address.Id;
                    tempCart.ScreenResolution  = cartModel.ScreenResolution;

                    if (paymentModel.Payments != null)
                    {
                        tempCart.PaymentMode = "";

                        if (paymentModel.Payments.Any(p => p.ChargeCard != null))
                        {
                            tempCart.PaymentMode += PaymentType.CreditCard.Name + ",";
                        }

                        if (paymentModel.Payments.Any(p => p.ECheck != null))
                        {
                            tempCart.PaymentMode += PaymentType.ElectronicCheck.Name + ",";
                        }

                        if (paymentModel.Payments.Any(p => p.GiftCertificate != null))
                        {
                            tempCart.PaymentMode += PaymentType.GiftCertificate.Name + ",";
                        }

                        if (paymentModel.Payments.Any(p => p.PaymentType == (int)PaymentType.Onsite_Value))
                        {
                            tempCart.PaymentMode += PaymentType.PayLater_Text + ",";
                        }

                        tempCart.PaymentMode = tempCart.PaymentMode.Substring(0, tempCart.PaymentMode.LastIndexOf(","));
                    }

                    tempCart.PaymentAmount = paymentModel.Amount;
                    try
                    {
                        _eventSchedulerService.CreateOrder(tempCart, paymentModel);
                        paymentSucceded = true;
                    }
                    catch (Exception ex)
                    {
                        _paymentController.VoidCreditCardGatewayRequests(paymentModel);
                        paymentSucceded = false;
                        throw new Exception("\nOnline Payment. Message: " + ex.Message + ". \n\t Stack Trace: " + ex.StackTrace);
                    }

                    tempCart.IsPaymentSuccessful = true;
                    tempCart.IsCompleted         = true;
                    _tempcartService.SaveTempCart(tempCart);

                    UpdateProspectCustomer(tempCart, customer);
                    scope.Complete();
                }

                try
                {
                    var account = _corporateAccountRepository.GetbyEventId(tempCart.EventId.Value);

                    if (account == null || account.SendWelcomeEmail)
                    {
                        var welcomeEmailViewModel = _emailNotificationModelsFactory.GetWelcomeWithUserNameNotificationModel(customer.UserLogin.UserName, customer.Name.FullName, customer.DateCreated);
                        _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.CustomerWelcomeEmailWithUsername, EmailTemplateAlias.CustomerWelcomeEmailWithUsername, welcomeEmailViewModel, customer.Id, customer.CustomerId, Request.RequestUri.OriginalString);
                    }

                    var eventData = _eventRepository.GetById(tempCart.EventId.Value);

                    _customerRegistrationService.SendAppointmentConfirmationMail(customer, eventData, customer.CustomerId, Request.RequestUri.OriginalString, account);

                    //If somebody registered within 24 hours of the event Date then send notification.
                    if (eventData.EventDate.AddDays(-1).Date <= DateTime.Now.Date)
                    {
                        var appointmentBookedInTwentyFourHoursNotificationModel = _emailNotificationModelsFactory.GetAppointmentBookedInTwentyFourHoursModel(tempCart.EventId.Value, tempCart.CustomerId.Value);
                        _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.AppointmentBookedInTwentyFourHours, EmailTemplateAlias.AppointmentBookedInTwentyFourHours, appointmentBookedInTwentyFourHoursNotificationModel, 0, customer.CustomerId, Request.RequestUri.OriginalString);
                    }

                    _callQueueCustomerRepository.UpdateOtherCustomerStatus(customer.CustomerId, tempCart.ProspectCustomerId.HasValue ? tempCart.ProspectCustomerId.Value : 0, CallQueueStatus.Completed, customer.CustomerId);

                    _eventSchedulingSlotService.SendEventFillingNotification(tempCart.EventId.Value, customer.CustomerId);
                }
                catch (Exception)
                {
                    //throw  new Exception("\nOnline Payment. Exception caused while sending notification. Message: " + ex.Message);
                }
            }
            catch (InvalidAddressException ex)
            {
                throw new Exception("Address provided by you is not a valid address. " + ex.Message);
            }
            catch (Exception)
            {
                if (paymentSucceded != null && paymentSucceded == false)
                {
                    tempCart.IsPaymentSuccessful = false;
                    tempCart.IsCompleted         = false;
                    tempCart.PaymentMode         = "";
                    tempCart.SourceCodeId        = 0;
                    tempCart.ShippingAddressId   = null;
                    _tempcartService.SaveTempCart(tempCart);
                    throw new Exception("OOPS! Payment could not be settled. Please try again or Call our Care Agent at " + _settings.PhoneTollFree);
                }

                throw new Exception("OOPS! Some error while generating the Order. Please try again or Call our Care Agent at " + _settings.PhoneTollFree);
            }

            return(model);
        }
        public EventCustomerOrderSummaryModel Create(Event eventInfo, Host host, EventSchedulingSlot appointmentSlot, EventPackage eventPackage, IEnumerable <EventTest> eventTests, IEnumerable <Product> products, ShippingOption shippingOption,
                                                     SourceCodeApplyEditModel sourceCodeApplyEditModel, Order order, long?shippingOptionId)
        {
            var model = new EventCustomerOrderSummaryModel();

            if (eventInfo != null)
            {
                model.EventId            = eventInfo.Id;
                model.EventType          = eventInfo.EventType;
                model.EventDate          = eventInfo.EventDate;
                model.Host               = host.OrganizationName;
                model.Address            = Mapper.Map <Address, AddressViewModel>(host.Address);
                model.CaptureInsuranceId = eventInfo.CaptureInsuranceId;
            }

            if (appointmentSlot != null)
            {
                model.AppointmentTime = appointmentSlot.StartTime;
            }

            decimal totalPrice = 0;

            if (eventPackage != null)
            {
                model.Package     = new OrderedPair <string, decimal>(eventPackage.Package.Name, eventPackage.Price);
                model.PackageTest = eventPackage.Tests.Select(ept => ept.Test.Name).ToArray();
                totalPrice        = eventPackage.Price;
            }

            if (eventTests != null)
            {
                model.AdditionalTests = eventTests.Select(et => new OrderedPair <string, decimal>(et.Test.Name, eventPackage != null ? et.WithPackagePrice : et.Price)).ToArray();

                var testPrice = eventTests.Select(et => eventPackage != null ? et.WithPackagePrice : et.Price).Sum();
                totalPrice += testPrice;
            }

            if (products != null)
            {
                model.Product = products.Select(p => new OrderedPair <string, decimal>(p.Name, p.Price)).ToArray();
                var productPrice = products.Select(p => p.Price).Sum();
                totalPrice += productPrice;
            }

            if (shippingOption != null)
            {
                model.ShippingOption = new OrderedPair <string, decimal>(shippingOption.Name, shippingOption.Price);
                totalPrice          += shippingOption.Price;
            }

            model.TotalPrice = totalPrice;

            if (sourceCodeApplyEditModel != null)
            {
                model.DiscountAmount = sourceCodeApplyEditModel.DiscountApplied;
                model.SourceCode     = sourceCodeApplyEditModel.SourceCode;
            }

            if (order != null)
            {
                var cancelledOrderDetail = order.OrderDetails.Where(od => od.DetailType == OrderItemType.CancellationFee).Select(od => od).LastOrDefault();
                if (cancelledOrderDetail != null)
                {
                    var paymentsApplied = order.PaymentsApplied.Where(pa => pa.DataRecorderMetaData.DateCreated > cancelledOrderDetail.DataRecorderMetaData.DateCreated.AddMinutes(5)).Select(pd => pd);
                    model.AmountPaid = paymentsApplied.Sum(pa => pa.Amount);
                }
                else
                {
                    model.AmountPaid = order.TotalAmountPaid;
                }
            }

            model.ShippingOptionId = shippingOptionId;
            return(model);
        }