public void UpdateTestPurchased(TempCart tempCart) { if (tempCart.EventPackageId.HasValue) { var userGender = !string.IsNullOrEmpty(tempCart.Gender) ? ((long)(Gender)Enum.Parse(typeof(Gender), tempCart.Gender, true)) : (long)Gender.Unspecified; var theEvent = _eventRepository.GetById(tempCart.EventId.Value); var eventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value); var eventTests = theEvent.EnableAlaCarteOnline ? _eventTestRepository.GetTestsForEventByRole(tempCart.EventId.Value, (long)Roles.Customer, userGender) : null; if (eventPackage.Tests.Any()) { var packageTestIds = eventPackage.Tests.Select(x => x.Id).ToList(); var panelTestId = (long)(userGender == (long)Gender.Male ? TestType.MenBloodPanel : TestType.WomenBloodPanel); var panelTestGroup = (panelTestId == (long)TestType.MenBloodPanel ? TestGroup.MensBloodPanelTestIds : TestGroup.WomenBloodPanelTestIds); long panelEventTestId = 0; var panelEventTestGroup = new List <long>(); if (!eventTests.IsNullOrEmpty()) { panelEventTestId = eventTests.Any(x => x.TestId == panelTestId) ? eventTests.First(x => x.TestId == panelTestId).Id : 0; panelEventTestGroup = eventTests.Where(et => panelTestGroup.Contains(et.TestId)).Select(x => x.Id).ToList(); } var seletectedTests = new List <long>(); var purchasedPanelTest = false; if (!string.IsNullOrWhiteSpace(tempCart.TestId)) { seletectedTests.AddRange(tempCart.TestId.Split(',').Select(long.Parse).ToList()); } if (seletectedTests.Any() && packageTestIds.Any() && panelEventTestId > 0) { seletectedTests = seletectedTests.Where(x => !packageTestIds.Contains(x)).ToList(); purchasedPanelTest = packageTestIds.Any(x => x == panelEventTestId); } if (purchasedPanelTest) { seletectedTests = seletectedTests.Where(x => !panelEventTestGroup.Contains(x)).ToList(); } tempCart.TestId = null; if (seletectedTests.Any()) { var selectedTestIds = string.Join(",", seletectedTests); tempCart.TestId = selectedTestIds; } } } }
public int GetScreeningTime(Order order) { var eventPackageOrderItem = order.OrderDetails.SingleOrDefault(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.DetailType == OrderItemType.EventPackageItem); EventPackage eventPackage = null; if (eventPackageOrderItem != null) { var eventPackageId = eventPackageOrderItem.OrderItem.ItemId; eventPackage = _eventPackageRepository.GetById(eventPackageId); } var eventTestIds = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.DetailType == OrderItemType.EventTestItem).Select(od => od.OrderItem.ItemId).ToArray(); var eventTests = eventTestIds.Any() ? _eventTestRepository.GetbyIds(eventTestIds) : null; return(GetScreeningTime(eventPackage, eventTests)); }
public GoogleAnalyticsEnableReportingDataModel GetGoogleAnalyticsViewModel(TempCart tempCart) { if (tempCart == null || !tempCart.IsCompleted) { return(new GoogleAnalyticsEnableReportingDataModel()); } var model = new GoogleAnalyticsEnableReportingDataModel(); if (tempCart.EventPackageId.HasValue) { model.EventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value); } if (!string.IsNullOrEmpty(tempCart.TestId)) { var testIdStrings = tempCart.TestId.Split(new[] { ',' }); if (testIdStrings.Any()) { long id; var testIds = testIdStrings.Where(p => long.TryParse(p, out id)).Select(p => Convert.ToInt64(p)).ToArray(); if (testIds.Count() > 0) { model.EventTests = _eventTestRepository.GetbyIds(testIds); } } } if (!string.IsNullOrEmpty(tempCart.ProductId)) { var productIdStrings = tempCart.ProductId.Split(new[] { ',' }); if (productIdStrings.Any()) { long id; var productIds = productIdStrings.Where(p => long.TryParse(p, out id)).Select(p => Convert.ToInt64(p)).ToArray(); if (productIds.Count() > 0) { model.Products = _productRepository.GetByIds(productIds); } } } if (tempCart.ShippingId.HasValue && tempCart.ShippingId.Value > 0) { model.Shipping = _shippingOptionRepository.GetById(tempCart.ShippingId.Value).Price; } Order order = _orderRepository.GetOrder(tempCart.CustomerId.Value, tempCart.EventId.Value); model.TotalPrice = order.DiscountedTotal; model.CustomerId = tempCart.CustomerId.Value; var customer = _customerRepository.GetCustomer(tempCart.CustomerId.Value); model.Address = _addressService.GetAddress(customer.Address.Id); return(model); }
public HafModel Get(HafFilter filter) { var theEvent = _eventRepository.GetById(filter.EventId); if (!theEvent.HealthAssessmentTemplateId.HasValue || theEvent.HealthAssessmentTemplateId.Value <= 0) { return(null); } var customer = _customerRepository.GetCustomer(filter.CustomerId); var template = _healthAssessmentTemplateRepository.GetById(theEvent.HealthAssessmentTemplateId.Value); var genericQuestionIds = new List <long>(); var list = new List <KeyValuePair <long, List <long> > >(); IsFemale = customer.Gender == Gender.Female; //Get Generic Question from Event Templates genericQuestionIds.AddRange(template.QuestionIds); var order = _orderRepository.GetOrder(filter.CustomerId, filter.EventId); var eventpackageId = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.EventPackageItem).Select(od => od.OrderItem.ItemId).FirstOrDefault(); var isKynIntegrationEnabled = _eventPodRepository.IsKynIntegrationEnabled(filter.EventId); var eventTestIds = new List <long>(); if (eventpackageId > 0) { var eventPackage = _eventPackageRepository.GetById(eventpackageId); if (eventPackage.HealthAssessmentTemplateId.HasValue && eventPackage.HealthAssessmentTemplateId.Value > 0) { var packageTemplate = _healthAssessmentTemplateRepository.GetById(eventPackage.HealthAssessmentTemplateId.Value); genericQuestionIds.AddRange(packageTemplate.QuestionIds); } eventTestIds.AddRange(eventPackage.Tests.Select(t => t.Id)); } list.Add(new KeyValuePair <long, List <long> >(0, genericQuestionIds)); eventTestIds.AddRange(order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.EventTestItem).Select(od => od.OrderItem.ItemId)); var eventTests = _eventTestRepository.GetbyIds(eventTestIds); var testWiseQuestion = GetTestQuestionKeyValuePairs(eventTestIds, isKynIntegrationEnabled, eventTests); if (testWiseQuestion != null) { list.AddRange(testWiseQuestion); } var hafModel = GetHafModel(list, eventTests, filter.EventId, filter.CustomerId, filter.SetChildQuestion, filter.VersionNumber) ?? new HafModel(); hafModel.EventId = filter.EventId; hafModel.CustomerId = filter.CustomerId; return(hafModel); }
public void GetbyId_ValidId_Tester() { var eventPackage = _eventPackageRepository.GetById(73563); Assert.IsNotNull(eventPackage); Assert.AreEqual(eventPackage.Id, 73563); Assert.AreEqual(eventPackage.PackageId, 124); Assert.AreEqual(eventPackage.EventId, 24759); Assert.IsNotNull(eventPackage.Tests); Assert.IsNotEmpty(eventPackage.Tests.ToArray()); }
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); }
public void ChangePackage(CustomerOrderDetail customerOrderDetail) { using (var scope = new TransactionScope()) { try { var eventid = customerOrderDetail.EventId; var customerid = customerOrderDetail.CustomerId; var order = GetOrder(customerid, eventid); IOrderController orderController = new OrderController(); var orderDetail = orderController.GetActiveOrderDetail(order); if (order == null || order.OrderDetails.IsEmpty()) { return; } var orderables = new List <IOrderable>(); var selectedTestIds = new List <long>(); if (customerOrderDetail.PreApprovedTestIds != null && customerOrderDetail.PreApprovedTestIds.Any()) { selectedTestIds = customerOrderDetail.PreApprovedTestIds.ToList(); } long packageId = 0; if (customerOrderDetail.PrePackageId > 0) { var eventPackage = _eventPackageRepository.GetByEventAndPackageIds(eventid, customerOrderDetail.PrePackageId); if (eventPackage != null) { packageId = eventPackage.PackageId; } } if (packageId == 0) { if (orderDetail.OrderItem.OrderItemType == OrderItemType.EventPackageItem) { var eventPackage = _eventPackageRepository.GetById(orderDetail.OrderItem.ItemId); packageId = eventPackage.PackageId; } } if (packageId > 0) { orderables.Add(_eventPackageRepository.GetByEventAndPackageIds(eventid, packageId)); selectedTestIds = RemoveTestsAlreadyInPackage(selectedTestIds, eventid, packageId); } if (!selectedTestIds.IsNullOrEmpty()) { var eventTests = _eventTestRepository.GetByEventAndTestIds(eventid, selectedTestIds); if (packageId > 0) { foreach (var eventTest in eventTests) { eventTest.Price = eventTest.WithPackagePrice; } } orderables.AddRange(eventTests); } var indentedLineItemsAdded = false; // TODO: applying hook to the system all the indented line items will be attached to the first order item. foreach (var orderable in orderables) { if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem)) { _orderController.AddItem(orderable, 1, customerid, 1, null, null, null, OrderStatusState.FinalSuccess); indentedLineItemsAdded = true; } else { _orderController.AddItem(orderable, 1, customerid, 1, OrderStatusState.FinalSuccess); } } _orderController.PlaceOrder(order); scope.Complete(); } catch (Exception exception) { _logger.Error("Some Error occured" + exception.Message); } } }
private void UpdateCustomerOrder(long eventId, long customerId, IEnumerable <long> testIds, long orgUserId) { var order = _orderRepository.GetOrder(customerId, eventId); if (order != null && !order.OrderDetails.IsEmpty()) { var orderDetail = _orderController.GetActiveOrderDetail(order); var eventTestOrderDetails = order.OrderDetails.Where(od => od.OrderItem.OrderItemType == OrderItemType.EventTestItem).Select(od => od).ToArray(); var packageId = 0L; if (orderDetail.OrderItem.OrderItemType == OrderItemType.EventPackageItem) { var eventPackage = _eventPackageRepository.GetById(orderDetail.OrderItem.ItemId); packageId = eventPackage.PackageId; } var orderables = new List <IOrderable>(); var selectedTestIds = testIds.ToList(); if (packageId > 0) { IEventPackageRepository eventPackageRepository = new EventPackageRepository(); var eventPackage = eventPackageRepository.GetByEventAndPackageIds(eventId, packageId); orderables.Add(eventPackage); RemoveTestsAlreadyInPackage(eventId, packageId, selectedTestIds); } if (!eventTestOrderDetails.IsNullOrEmpty()) { var eventTestIds = eventTestOrderDetails.Select(od => od.OrderItem.ItemId).ToArray(); var eventTestInOrder = _eventTestRepository.GetbyIds(eventTestIds); var testAlreadyInOrders = eventTestInOrder.Select(et => et.TestId).ToArray(); selectedTestIds = selectedTestIds.Where(x => !testAlreadyInOrders.Contains(x)).ToList(); if (testAlreadyInOrders.Any(x => AbiGroup.Contains(x))) { selectedTestIds.RemoveAll(AbiGroup.Contains); } if (testAlreadyInOrders.Any(x => DpnMonofilamentGroup.Contains(x))) { selectedTestIds.RemoveAll(DpnMonofilamentGroup.Contains); } var activeEventTestOrderDetails = order.OrderDetails.Where(od => od.OrderItem.OrderItemType == OrderItemType.EventTestItem && od.IsCompleted).Select(od => od).ToArray(); if (!activeEventTestOrderDetails.IsNullOrEmpty()) { var activEventTestIds = activeEventTestOrderDetails.Select(od => od.OrderItem.ItemId).ToArray(); var activeTestAlreadyInOrders = eventTestInOrder.Where(x => activEventTestIds.Contains(x.Id)).Select(et => et.TestId).ToArray(); selectedTestIds.AddRange(activeTestAlreadyInOrders); } } if (!selectedTestIds.IsNullOrEmpty()) { var eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, selectedTestIds); if (AddMissingTestToEvent(eventId, selectedTestIds, eventTests)) { eventTests = _eventTestRepository.GetByEventAndTestIds(eventId, selectedTestIds); } if (packageId > 0) { foreach (var eventTest in eventTests) { eventTest.Price = eventTest.WithPackagePrice; } } orderables.AddRange(eventTests); bool indentedLineItemsAdded = false; foreach (var orderable in orderables) { if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem)) { _orderController.AddItem(orderable, 1, customerId, orgUserId, null, null, null, OrderStatusState.FinalSuccess, (long)OrderSource.Medicare); indentedLineItemsAdded = true; } else { _orderController.AddItem(orderable, 1, customerId, orgUserId, OrderStatusState.FinalSuccess, (long)OrderSource.Medicare); } } _orderController.PlaceOrder(order); } } }
public JsonResult CheckPackageAndTestHafTemplate(long eventId, long customerId, long packageId, IEnumerable <long> testIds) { string message = string.Empty; var currentOrder = _orderRepository.GetOrder(customerId, eventId); var packageOrderItem = currentOrder.OrderDetails.FirstOrDefault(od => od.DetailType == OrderItemType.EventPackageItem && od.IsCompleted); var testOrderItems = currentOrder.OrderDetails.Where(od => od.DetailType == OrderItemType.EventTestItem && od.IsCompleted); var currentEventPackageId = (packageOrderItem != null) ? packageOrderItem.OrderItem.ItemId : 0; long currentPackageId = 0; EventPackage currentEventPackage = null; EventPackage eventPackage = null; if (currentEventPackageId > 0) { currentEventPackage = _eventPackageRepository.GetById(currentEventPackageId); currentPackageId = currentEventPackage.PackageId; } eventPackage = packageId > 0 ? _eventPackageRepository.GetByEventAndPackageIds(eventId, packageId) : currentEventPackage; var eventTests = _eventTestRepository.GetTestsForEvent(eventId); var testPackageName = new List <string>(); if (packageId != currentPackageId) { if (eventPackage != null && eventPackage.HealthAssessmentTemplateId.HasValue) { testPackageName.Add(eventPackage.Package.Name); } } var currentTestIds = new List <long>(); if (currentEventPackage != null) { currentTestIds.AddRange(currentEventPackage.Tests.Select(x => x.TestId)); } if (!testOrderItems.IsNullOrEmpty()) { var orderIds = testOrderItems.Select(x => x.OrderItem.ItemId); var customerTests = eventTests.Where(x => orderIds.Contains(x.Id)); currentTestIds.AddRange(customerTests.Select(x => x.TestId)); } var missingTest = currentTestIds.Where(x => !testIds.Contains(x)); if (!missingTest.IsNullOrEmpty()) { var testNames = eventTests.Where(m => missingTest.Contains(m.TestId) && m.HealthAssessmentTemplateId.HasValue).Select(m => m.Test.Name); if (!testNames.IsNullOrEmpty()) { testPackageName.AddRange(testNames); } } var newTestIds = testIds.Where(x => !currentTestIds.Contains(x)); if (!newTestIds.IsNullOrEmpty()) { var testNames = eventTests.Where(m => newTestIds.Contains(m.TestId) && m.HealthAssessmentTemplateId.HasValue) .Select(m => m.Test.Name); if (!testNames.IsNullOrEmpty()) { testPackageName.AddRange(testNames); } } return(Json(testPackageName, JsonRequestBehavior.AllowGet)); }
public bool ChangePackage(long eventId, long customerId, IEnumerable <long> testIds) { var patientOrder = GetOrder(customerId, eventId); if (patientOrder != null && !patientOrder.OrderDetails.IsEmpty()) { var creatorOrganizationRoleUser = GetCreatorOrganizationRoleUser(); var forOrganizationRoleUser = GetForOrganizationRoleUser(customerId); var orderDetail = _orderController.GetActiveOrderDetail(patientOrder); var eventTestOrderDetails = patientOrder.OrderDetails.Where(od => od.OrderItem.OrderItemType == OrderItemType.EventTestItem && od.IsCompleted && (od.SourceId.HasValue && od.SourceId.Value != (long)OrderSource.Medicare)).Select(od => od).ToArray(); var packageId = 0L; if (orderDetail.OrderItem.OrderItemType == OrderItemType.EventPackageItem) { var eventPackage = _eventPackageRepository.GetById(orderDetail.OrderItem.ItemId); packageId = eventPackage.PackageId; } var orderables = new List <IOrderable>(); var selectedTestIds = testIds.ToList(); if (packageId > 0) { IEventPackageRepository eventPackageRepository = new EventPackageRepository(); var eventPackage = eventPackageRepository.GetByEventAndPackageIds(eventId, packageId); orderables.Add(eventPackage); RemoveTestsAlreadyInPackage(eventId, packageId, selectedTestIds); } IEventTestRepository eventTestRepository = new EventTestRepository(); if (!eventTestOrderDetails.IsNullOrEmpty()) { var eventTestIds = eventTestOrderDetails.Select(od => od.OrderItem.ItemId).ToArray(); var nonMedicareEventTests = eventTestRepository.GetbyIds(eventTestIds); orderables.AddRange(nonMedicareEventTests); var nonMedicareEventTestIds = nonMedicareEventTests.Select(et => et.TestId).ToArray(); selectedTestIds = selectedTestIds.Where(x => !nonMedicareEventTestIds.Contains(x)).ToList(); } if (!selectedTestIds.IsNullOrEmpty()) { var eventTests = eventTestRepository.GetByEventAndTestIds(eventId, selectedTestIds); if (packageId > 0) { foreach (var eventTest in eventTests) { eventTest.Price = eventTest.WithPackagePrice; } } orderables.AddRange(eventTests); } var eventCustomer = UpdateEventCustomer(orderDetail, false); if (eventCustomer == null) { return(false); } bool indentedLineItemsAdded = false; foreach (var orderable in orderables) { if (!indentedLineItemsAdded && (orderable.OrderItemType == OrderItemType.EventPackageItem || orderable.OrderItemType == OrderItemType.EventTestItem)) { _orderController.AddItem(orderable, 1, forOrganizationRoleUser.Id, creatorOrganizationRoleUser.Id, null, null, null, OrderStatusState.FinalSuccess, (long)OrderSource.Medicare); indentedLineItemsAdded = true; } else { _orderController.AddItem(orderable, 1, forOrganizationRoleUser.Id, creatorOrganizationRoleUser.Id, OrderStatusState.FinalSuccess, (long)OrderSource.Medicare); } } _orderController.PlaceOrder(patientOrder); } return(true); }
public OrderViewData Create(OrderDetail orderDetail) { var orderDetailOrganizationRoleUserCreator = GetOrganizationRoleUser(orderDetail, od => od.DataRecorderMetaData.DataRecorderCreator.Id); var orderDetailOrganizationRoleUserFor = GetOrganizationRoleUser(orderDetail, od => od.ForOrganizationRoleUserId); var description = orderDetail.Description; if (orderDetail.DetailType == OrderItemType.EventPackageItem) { var package = _eventPackageRepository.GetById(orderDetail.OrderItem.ItemId); description = package == null ? "" : package.Package.Name; } else if (orderDetail.DetailType == OrderItemType.EventTestItem) { var eventTest = _eventTestRepository.GetbyId(orderDetail.OrderItem.ItemId); description = eventTest == null ? "" : eventTest.Test.Name; } else if (orderDetail.DetailType == OrderItemType.ProductItem) { description = _electronicProductRepository.GetElectronicProductNameForOrder(orderDetail.OrderItemId); } var customer = _customerRepository.GetCustomerByUserId(orderDetailOrganizationRoleUserFor.FirstValue.UserId); //var creatorRoleName = // ((Roles)orderDetailOrganizationRoleUserCreator.FirstValue.RoleId).ToString(); var orderDetailDateCreated = orderDetail.DataRecorderMetaData != null ? orderDetail.DataRecorderMetaData.DateCreated.ToString("MMM dd yyyy") : null; var eventCustomerId = (orderDetail.DetailType == OrderItemType.EventPackageItem || orderDetail.DetailType == OrderItemType.EventTestItem) && orderDetail.EventCustomerOrderDetail != null ? orderDetail.EventCustomerOrderDetail.EventCustomerId : 0; var orderViewData = new OrderViewData { CreationMode = orderDetailOrganizationRoleUserCreator.SecondValue.SecondValue, CreatorName = orderDetailOrganizationRoleUserCreator.SecondValue.FirstValue, CreatorRole = orderDetailOrganizationRoleUserCreator.SecondValue.SecondValue, CustomerId = customer.CustomerId, CustomerName = customer.NameAsString, Description = description, EventCustomerId = eventCustomerId, OrderDetailDateCreated = orderDetailDateCreated, OrderDetailStatus = orderDetail.OrderItemStatus.Name, OrderDetailType = orderDetail.OrderItemStatus.ItemTypeName, Price = orderDetail.Price, Quantity = orderDetail.Quantity, ShippingDetails = GetShippingDetailUserPair(orderDetail.Id).ToList() }; if ((orderDetail.DetailType == OrderItemType.EventPackageItem || orderDetail.DetailType == OrderItemType.EventTestItem) && orderDetail.SourceCodeOrderDetail != null) { orderViewData.SourceCode = GetSourceCodeUserPair(orderDetail.SourceCodeOrderDetail); } return(orderViewData); }
public EventCustomerAggregate CreateEventCustomerAggregate(EventCustomer eventCustomer) { // Collect all the required data from different repositories. var eventData = _eventRepository.GetById(eventCustomer.EventId); var eventHost = _hostRepository.GetHostForEvent(eventCustomer.EventId); var appointment = _appointmentRepository.GetById(eventCustomer.AppointmentId.Value); var customer = _customerRepository.GetCustomer(eventCustomer.CustomerId); var order = _orderRepository.GetOrder(customer.CustomerId, eventData.Id); var activeOrderDetail = _orderController.GetActiveOrderDetail(order); if (eventHost == null || appointment == null || order == null || activeOrderDetail == null) { return(null); } var package = _packageRepository.GetById(activeOrderDetail.OrderItem.ItemId); string packageName = ""; if (package != null) { packageName = package.Package.Name; } var sourceCode = activeOrderDetail.SourceCodeOrderDetail != null?_sourceCodeRepository.GetSourceCodeById(activeOrderDetail.SourceCodeOrderDetail.SourceCodeId) : null; var paymentTypes = string.Join(",", order.PaymentsApplied.Select(pa => pa.PaymentType.Name).ToArray()); CustomerEventSignUpMode signUpMode = GetEventSignUpMode(eventCustomer); return(new EventCustomerAggregate { AppointmentId = eventCustomer.AppointmentId.Value, AppointmentTime = appointment.StartTime, CustomerAddress = customer.Address, CustomerId = customer.CustomerId, CustomerSignupDate = customer.DateCreated, EventAddress = eventHost.Address, EventCustomerId = eventCustomer.Id, EventDate = eventData.EventDate, EventId = eventData.Id, EventName = eventData.Name, EventSignupDate = eventCustomer.DataRecorderMetaData != null ? eventCustomer.DataRecorderMetaData.DateCreated : default(DateTime), EventStatus = eventData.Status, FirstName = customer.Name != null ? customer.Name.FirstName : string.Empty, IsPaid = order.TotalAmountPaid >= order.DiscountedTotal, LastName = customer.Name != null ? customer.Name.LastName : string.Empty, MarketingSource = eventCustomer.MarketingSource, MiddleName = customer.Name != null ? customer.Name.MiddleName : string.Empty, PackageName = packageName, PackageCost = activeOrderDetail.Price, PaidAmount = order.TotalAmountPaid, PaymentAmount = order.UndiscountedTotal, PaymentNet = order.DiscountedTotal, PaymentType = paymentTypes, SignUpMarketingSource = eventCustomer.MarketingSource, SignUpMode = signUpMode, SourceCode = sourceCode != null ? sourceCode.CouponCode : string.Empty, UnpaidAmount = order.TotalAmountPaid - order.DiscountedTotal }); }
public Order RegisterOnsiteCustomer(OnSiteRegistrationEditModel model) { var createdByOrgRoleUser = Mapper.Map <OrganizationRoleUserModel, OrganizationRoleUser>(_sessionContext.UserSession.CurrentOrganizationRole); var customer = _massRegistrationEditModelFactory.CreateCustomer(model, createdByOrgRoleUser); _customerService.SaveCustomer(customer, createdByOrgRoleUser.Id); var forOrgRoleUser = _orgRoleUserRepository.GetOrganizationRoleUser(customer.CustomerId); var orderables = new List <IOrderable>(); long packageId = 0; IEnumerable <long> testIds = null; if (model.SelectedPackageId > 0) { var eventPackage = _eventPackageRepository.GetById(model.SelectedPackageId); packageId = eventPackage.PackageId; orderables.Add(eventPackage); } if (model.SelectedTestIds != null && model.SelectedTestIds.Count() > 0) { var eventTests = _eventTestRepository.GetbyIds(model.SelectedTestIds); testIds = eventTests.Select(et => et.TestId).ToArray(); if (model.SelectedPackageId > 0) { foreach (var eventTest in eventTests) { eventTest.Price = eventTest.WithPackagePrice; } } orderables.AddRange(eventTests); } var screeningTime = _eventPackageSelectorService.GetScreeningTime(model.SelectedPackageId, model.SelectedTestIds); var slots = _eventSchedulingSlotService.BookSlotTemporarily(model.SelectedAppointmentId, screeningTime, packageId, testIds); if (slots.IsNullOrEmpty()) { throw new InvalidOperationException("Slot is booked by some other customer."); } var eventCustomer = SaveEventCustomer(createdByOrgRoleUser, model.SelectedAppointmentId, model.EventId, customer.CustomerId); //var shippingAddress = Mapper.Map<AddressEditModel, Address>(model.Address); //var shippingDetail = SaveShippingDetail(shippingAddress, createdByOrgRoleUser); var order = PlaceOrder(forOrgRoleUser, createdByOrgRoleUser, orderables, eventCustomer, null, null); var eventData = _eventRepository.GetById(model.EventId); SendNotification(customer, eventData, createdByOrgRoleUser, "/Scheduling/OnSiteRegistration/Create"); order.CustomerId = customer.CustomerId; try { _eventSchedulingSlotService.SendEventFillingNotification(model.EventId, createdByOrgRoleUser.Id); } catch (Exception) { } return(order); }