Ejemplo n.º 1
0
        public OrderPlaceEditModel SaveSelectedPackage(string guid, long selectedEventPackageId)
        {
            var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(guid);
            var model = new OrderPlaceEditModel {
                RequestValidationModel = onlineRequestValidationModel
            };

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

            var tempCart = onlineRequestValidationModel.TempCart;

            if (tempCart.AppointmentId > 0)
            {
                _onlinePackageService.ReleaseSlotsOnScreeningtimeChanged(tempCart, selectedEventPackageId, tempCart.TestId);
            }

            tempCart.EventPackageId = selectedEventPackageId;

            _onlinePackageService.UpdateTestPurchased(tempCart);

            _tempcartService.SaveTempCart(tempCart);

            if (tempCart.EventId.HasValue && tempCart.EventId > 0 && !string.IsNullOrEmpty(tempCart.Gender))
            {
                model.UpsellTestAvailable = _onlinePackageService.IsUpsellTestAvailable(tempCart);
                var allAdditionalTests = _onlinePackageService.GetAdditionalTest(tempCart);
                model.IsAdditionalTestAvailable = allAdditionalTests != null && allAdditionalTests.Any();
            }

            return(model);
        }
Ejemplo n.º 2
0
        public void ReleaseSlotsOnScreeningtimeChanged(TempCart tempCart, long newEventPackageId, string newEventTestIds)
        {
            var newEvenTestIds = new List <long>();

            if (!string.IsNullOrEmpty(newEventTestIds))
            {
                newEventTestIds.Split(',').ToList().ForEach(t => newEvenTestIds.Add(Convert.ToInt64(t)));
                newEvenTestIds.RemoveAll(t => t == 0);
            }

            //var existingEventTestIds = new List<long>();
            //if (!string.IsNullOrEmpty(tempCart.TestId))
            //{
            //    tempCart.TestId.Split(',').ToList().ForEach(t => existingEventTestIds.Add(Convert.ToInt64(t)));
            //    existingEventTestIds.RemoveAll(t => t == 0);
            //}

            //var isOrderChanged = newEventPackageId != tempCart.EventPackageId || (!newEvenTestIds.All(existingEventTestIds.Contains) || !existingEventTestIds.All(newEvenTestIds.Contains));

            var screeningTime = _eventPackageSelectorService.GetScreeningTime(tempCart.EventPackageId.Value, newEvenTestIds);

            if (!tempCart.InChainAppointmentSlotIds.IsNullOrEmpty())//&& isOrderChanged
            {
                var testIds = new List <long>();
                if (newEvenTestIds != null && newEvenTestIds.Any())
                {
                    var eventTests = _eventTestRepository.GetbyIds(newEvenTestIds);
                    if (eventTests != null && !eventTests.IsNullOrEmpty())
                    {
                        eventTests.ForEach(et => testIds.Add(et.TestId));
                    }
                }

                var newPackageId = _eventPackageRepository.GetById(newEventPackageId).PackageId;

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

                var slots = _eventSchedulingSlotService.AdjustAppointmentSlot(tempCart.EventId.Value, screeningTime, tempCart.InChainAppointmentSlotIds, newPackageId, testIds, theEvent.LunchStartTime, theEvent.LunchDuration);

                if (slots == null)
                {
                    _eventSchedulingSlotRepository.ReleaseSlots(tempCart.InChainAppointmentSlotIds);
                    tempCart.AppointmentId           = null;
                    tempCart.InChainAppointmentSlots = null;
                    tempCart.PreliminarySelectedTime = null;
                }
                else
                {
                    var eventSchedulingSlots = slots as EventSchedulingSlot[] ?? slots.ToArray();
                    tempCart.AppointmentId           = eventSchedulingSlots.OrderBy(s => s.StartTime).First().Id;
                    tempCart.PreliminarySelectedTime = eventSchedulingSlots.OrderBy(s => s.StartTime).First().StartTime;
                    tempCart.InChainAppointmentSlots = string.Join(",", eventSchedulingSlots.Select(s => s.Id.ToString()).ToArray());
                }

                _tempcartService.SaveTempCart(tempCart);
            }
        }
Ejemplo n.º 3
0
        public void SaveOnlineHealthAssessment(OnlineHealthAssessmentQuestionAnswer model, TempCart tempCart)
        {
            _healthAssessmentService.Save(new HealthAssessmentEditModel
            {
                CustomerId         = tempCart.CustomerId.Value,
                EventId            = tempCart.EventId.Value,
                QuestionEditModels = model.QuestionEditModels
            }, 0);

            var customer = _customerRepository.GetCustomer(tempCart.CustomerId.Value);

            customer.Height = model.Height > 0 ? new Height {
                TotalInches = model.Height
            } : null;
            customer.Weight = model.Weight > 0 ? new Weight(model.Weight) : null;

            customer.Race  = (Race)model.Race;
            customer.Waist = model.Waist;

            _customerService.SaveCustomer(customer, customer.CustomerId);

            if ((!tempCart.IsHafFilled.HasValue || !tempCart.IsHafFilled.Value) && !model.QuestionEditModels.IsNullOrEmpty())
            {
                tempCart.IsHafFilled = true;
            }

            _tempcartService.SaveTempCart(tempCart);
        }
Ejemplo n.º 4
0
        public PreQualificationViewModel SavePreQualificationAnswer(PreQualificationViewModel model)
        {
            var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(model.Guid);

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

            var tempCart = onlineRequestValidationModel.TempCart;

            if (!string.IsNullOrEmpty(tempCart.Gender) && tempCart.Gender != model.Gender && !string.IsNullOrEmpty(tempCart.TestId) && tempCart.EventId.HasValue)
            {
                Gender gender;
                System.Enum.TryParse(model.Gender, out gender);

                var testIds = tempCart.TestId.Split(',').Select(long.Parse).ToList();

                var eventTests = _eventTestRepository.GetTestsForEventByRole(tempCart.EventId.Value, (long)Roles.Customer, (long)gender);
                if (!eventTests.IsNullOrEmpty())
                {
                    testIds         = eventTests.Where(x => testIds.Contains(x.Id)).Select(x => x.Id).ToList();
                    tempCart.TestId = string.Join(",", testIds);
                }
            }
            tempCart.Gender = model.Gender;
            tempCart.Dob    = model.Dob;

            _tempcartService.SaveTempCart(tempCart);

            onlineRequestValidationModel.TempCart = tempCart;
            if (model.AskPreQualificationQuestion)
            {
                _onlineEventService.SaveAnswer(model);
            }
            return(model);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public SchedulingCustomerEditModel RegisterCustomer(String guid, SchedulingCustomerEditModel customerEditModel)
        {
            if (!string.IsNullOrEmpty(customerEditModel.HomeNumber))// To eliminate masking
            {
                customerEditModel.HomeNumber = customerEditModel.HomeNumber.Replace("-", "").Replace("(", "").Replace(")", "").Replace(" ", "");
            }

            if (!string.IsNullOrEmpty(customerEditModel.PhoneCell))// To eliminate masking
            {
                customerEditModel.PhoneCell = customerEditModel.PhoneCell.Replace("-", "").Replace("(", "").Replace(")", "").Replace(" ", "");
            }

            var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(guid);

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

            if (!customerEditModel.DateofBirth.HasValue)
            {
                throw new Exception("Please enter Date of Birth!");
            }

            if (customerEditModel.DateofBirth.Value.GetAge() < _settings.MinimumAgeForScreening)
            {
                throw new Exception(string.Format("Customers below {0} years of age are not allowed for screening.In case of any queries, please call us at {1}", _settings.MinimumAgeForScreening, _settings.PhoneTollFree));
            }

            var customer  = _customerService.SaveCustomer(customerEditModel, onlineRequestValidationModel.TempCart.IsExistingCustomer);
            var userLogin = _userLoginRepository.GetByUserId(customer.Id);

            _passwordChangeLogService.Update(userLogin.Id, new SecureHash(userLogin.Password, userLogin.Salt), customer.CustomerId);
            onlineRequestValidationModel.TempCart.CustomerId      = customer.CustomerId;
            onlineRequestValidationModel.TempCart.MarketingSource = customerEditModel.MarketingSource;

            var tempCart = onlineRequestValidationModel.TempCart;

            _tempcartService.SaveTempCart(tempCart);


            var doesEventCustomerAlreadyExists = tempCart.CustomerId.HasValue ? _eventSchedulerService.DoesEventCustomerAlreadyExists(tempCart.CustomerId.Value, tempCart.EventId.Value) : null;

            if (doesEventCustomerAlreadyExists != null && doesEventCustomerAlreadyExists.FirstValue)
            {
                throw new Exception(doesEventCustomerAlreadyExists.SecondValue);
            }

            customer = tempCart.CustomerId.HasValue ? _customerRepository.GetCustomer(tempCart.CustomerId.Value) : null;
            if (tempCart.ProspectCustomerId.HasValue)
            {
                var prospectCustomer = _prospectCustomerRepository.GetById(tempCart.ProspectCustomerId.Value);
                prospectCustomer.CustomerId                 = customer.CustomerId;
                prospectCustomer.Tag                        = ProspectCustomerTag.OnlineSignup;
                prospectCustomer.IsConverted                = false;
                prospectCustomer.Status                     = (long)ProspectCustomerConversionStatus.NotConverted;
                prospectCustomer.ConvertedOnDate            = DateTime.Now;
                prospectCustomer.Address.StreetAddressLine1 = customer.Address.StreetAddressLine1;
                prospectCustomer.Address.StreetAddressLine2 = customer.Address.StreetAddressLine2;
                prospectCustomer.Address.City               = customer.Address.City;
                prospectCustomer.Address.State              = _stateRepository.GetState(customer.Address.StateId).Name;
                prospectCustomer.Address.ZipCode.Zip        = customer.Address.ZipCode.Zip;
                prospectCustomer.MarketingSource            = customer.MarketingSource;
                prospectCustomer.CallBackPhoneNumber        = customer.HomePhoneNumber;
                prospectCustomer.Email                      = customer.Email;
                prospectCustomer.TagUpdateDate              = DateTime.Now;
                _prospectCustomerRepository.Save(prospectCustomer);
            }
            else
            {
                var prospectCustomer = ((IProspectCustomerRepository)_prospectCustomerRepository).GetProspectCustomerByCustomerId(customer.CustomerId);
                if (prospectCustomer != null)
                {
                    prospectCustomer.CustomerId                 = customer.CustomerId;
                    prospectCustomer.Tag                        = ProspectCustomerTag.OnlineSignup;
                    prospectCustomer.IsConverted                = false;
                    prospectCustomer.Status                     = (long)ProspectCustomerConversionStatus.NotConverted;
                    prospectCustomer.ConvertedOnDate            = DateTime.Now;
                    prospectCustomer.Address.StreetAddressLine1 = customer.Address.StreetAddressLine1;
                    prospectCustomer.Address.StreetAddressLine2 = customer.Address.StreetAddressLine2;
                    prospectCustomer.Address.City               = customer.Address.City;
                    prospectCustomer.Address.State              = _stateRepository.GetState(customer.Address.StateId).Name;
                    prospectCustomer.Address.ZipCode.Zip        = customer.Address.ZipCode.Zip;
                    prospectCustomer.MarketingSource            = customer.MarketingSource;
                    prospectCustomer.CallBackPhoneNumber        = customer.HomePhoneNumber;
                    prospectCustomer.Email                      = customer.Email;
                    prospectCustomer.TagUpdateDate              = DateTime.Now;
                    _prospectCustomerRepository.Save(prospectCustomer);
                }
            }
            return(customerEditModel);
        }
Ejemplo n.º 7
0
        public EventAppointmentOnlineListModel SaveEventAppointmentSlotOnline(TempCart tempCart)
        {
            if (tempCart.EventPackageId == null || tempCart.AppointmentId == null)
            {
                return(GetEventAppointmentSlotOnline(tempCart));
            }


            var selectedAppointmentId = tempCart.AppointmentId.Value;

            if (tempCart.InChainAppointmentSlotIds != null && tempCart.InChainAppointmentSlotIds.Any())
            {
                _eventSchedulingSlotRepository.ReleaseSlots(tempCart.InChainAppointmentSlotIds);
                tempCart.AppointmentId           = null;
                tempCart.InChainAppointmentSlots = null;
                tempCart.PreliminarySelectedTime = null;
            }


            var eventTestIds = new List <long>();
            var testIds      = new List <long>();

            if (!string.IsNullOrEmpty(tempCart.TestId))
            {
                tempCart.TestId.Split(',').ForEach(x => eventTestIds.Add(Convert.ToInt64(x)));
                var eventTests = _eventTestRepository.GetbyIds(eventTestIds).ToList();
                if (eventTests != null && !eventTests.IsNullOrEmpty())
                {
                    eventTests.ForEach(et => testIds.Add(et.TestId));
                }
            }

            var eventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value);


            var screeningTime = _eventPackageSelectorService.GetScreeningTime(tempCart.EventPackageId.Value, eventTestIds);
            var result        = _eventSchedulingSlotService.BookSlotTemporarily(selectedAppointmentId, screeningTime, eventPackage.PackageId, testIds);

            if (result == null)
            {
                throw new Exception("The slot selected by you is no longer available as it is booked for another customer. Please Choose another slot or select any other preferable hour.");
            }

            var eventSchedulingSlots = result as EventSchedulingSlot[] ?? result.ToArray();
            var selectedSlotIds      = eventSchedulingSlots.Select(x => x.Id).ToList();

            if (!selectedSlotIds.Any())
            {
                tempCart.AppointmentId           = null;
                tempCart.InChainAppointmentSlots = string.Empty;
                tempCart.IsUsedAppointmentSlotExpiryExtension = null;
                return(GetEventAppointmentSlotOnline(tempCart));
            }


            var slotFirst = eventSchedulingSlots.OrderBy(s => s.StartTime).First();

            tempCart.AppointmentId           = slotFirst.Id;
            tempCart.PreliminarySelectedTime = slotFirst.StartTime;
            tempCart.InChainAppointmentSlots = string.Join(",", selectedSlotIds);
            tempCart.IsUsedAppointmentSlotExpiryExtension = null;
            _tempcartService.SaveTempCart(tempCart);

            return(GetEventAppointmentSlotOnline(tempCart));
        }