public void PlaceOrderSavesTwoEntitiesWhenOneItemOrdered() { const int quantity = 1; const int forOrganizationRoleUserId = 3; const int dataRecorderCreatorId = 4; const OrderType typeOfOrderToPlace = OrderType.Retail; var fakeOrderable = new FakeOrderable(); Expect.Call(_orderFactory.CreateNewOrder(typeOfOrderToPlace, dataRecorderCreatorId)). Return(new Order { OrderDetails = new List <OrderDetail>() }); Expect.Call(_orderDetailFactory.CreateNewOrderDetail(fakeOrderable, quantity, forOrganizationRoleUserId, dataRecorderCreatorId, null, null, null)). Return(new OrderDetail()); Expect.Call(_orderItemStatusFactory.CreateOrderItemStatus(0, 0)).IgnoreArguments(). Return(FakeOrderItemStatus.IncompleteFakeStatus); // Expecting persistence of two entities. Expect.Call(_orderRepository.SaveOrder(null)).IgnoreArguments(). Return(new Order()); Expect.Call(_orderItemRepository.SaveOrderItem(fakeOrderable.Id, fakeOrderable.OrderItemType)) .Return(new FakeOrderItem()); _mocks.ReplayAll(); _orderController.AddItem(fakeOrderable, quantity, forOrganizationRoleUserId, dataRecorderCreatorId); _orderController.PlaceOrder(typeOfOrderToPlace, dataRecorderCreatorId); _mocks.VerifyAll(); }
private Order PlaceOrder(DomainObjectBase forOrganizationRoleUser, DomainObjectBase creatorOrganizationRoleUser, IEnumerable <IOrderable> orderables, EventCustomer eventCustomer, SourceCode sourceCode, ShippingDetail shippingDetail) { 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, sourceCode, eventCustomer, shippingDetail, OrderStatusState.FinalSuccess); indentedLineItemsAdded = true; } else { _orderController.AddItem(orderable, 1, forOrganizationRoleUser.Id, creatorOrganizationRoleUser.Id, OrderStatusState.FinalSuccess); } } return(_orderController.PlaceOrder(OrderType.Retail, creatorOrganizationRoleUser.Id)); }
private void AddProduct(long customerId, Order order, OrganizationRoleUser organizationRoleUser) { var product = _electronicProductRepository.GetById((long)Product.UltraSoundImages); product.Price = 0; var orderables = new List <IOrderable> { product }; foreach (var orderable in orderables) { _orderController.AddItem(orderable, 1, customerId, organizationRoleUser.Id, OrderStatusState.FinalSuccess); } _orderController.PlaceProductOrder(order); }
public void UndoCdRemoveRequest(RefundRequest refundRequest) { var order = _orderRepository.GetOrder(refundRequest.OrderId); var activeOrderDetail = _orderController.GetActiveOrderDetail(order); var cancelledProductDetail = order.OrderDetails.Where(od => od.DetailType == OrderItemType.ProductItem && !od.IsCompleted) .Select(od => od).OrderByDescending(od => od.Id).FirstOrDefault(); if (cancelledProductDetail == null) { throw new Exception("No CD Removal item found in the order."); } var eventCustomer = _eventCustomerRepository.GetById(activeOrderDetail.EventCustomerOrderDetail.EventCustomerId); var isExclusivelyRequested = _shippingDetailService.CheckShippingIsExclusivelyRequested(eventCustomer.EventId, eventCustomer.CustomerId); var product = _productRepository.GetById(cancelledProductDetail.OrderItem.ItemId); product.Price = refundRequest.RequestedRefundAmount; var forOrganizationRoleUser = new OrganizationRoleUser(cancelledProductDetail.ForOrganizationRoleUserId); var creatorOrganizationRoleUser = new OrganizationRoleUser(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId); _orderController.AddItem(product, 1, forOrganizationRoleUser.Id, creatorOrganizationRoleUser.Id, OrderStatusState.FinalSuccess); _orderController.PlaceProductOrder(order); SaveProductShipping(cancelledProductDetail, activeOrderDetail, isExclusivelyRequested); var repository = ((IRepository <RefundRequest>)_refundRequestRepository); refundRequest.RequestStatus = (long)RequestStatus.Reverted; refundRequest.RefundRequestResult = new RefundRequestResult { ProcessedOn = DateTime.Now, ProcessedByOrgRoleUserId = _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId }; repository.Save(refundRequest); }
public void CreateOrder(TempCart tempCart, PaymentEditModel paymentEditModel = null) { if (tempCart.EventId == null || tempCart.CustomerId == null || tempCart.AppointmentId == null || (tempCart.EventPackageId == null && string.IsNullOrEmpty(tempCart.TestId))) { return; } var customer = _customerRepository.GetCustomer(tempCart.CustomerId.Value); var inDb = _eventCustomerRepository.Get(tempCart.EventId.Value, tempCart.CustomerId.Value); var eventCustomer = new EventCustomer { Id = inDb != null ? inDb.Id : 0, EventId = tempCart.EventId.Value, CustomerId = tempCart.CustomerId.Value, DataRecorderMetaData = new DataRecorderMetaData { DataRecorderCreator = new OrganizationRoleUser(tempCart.CustomerId.Value), DateCreated = DateTime.Now }, OnlinePayment = true, MarketingSource = tempCart.MarketingSource, NoShow = false, TestConducted = false, HIPAAStatus = RegulatoryState.Unknown, EnableTexting = customer.EnableTexting }; using (var scope = new TransactionScope()) { var appointment = _eventAppointmentService.CreateAppointment(tempCart.InChainAppointmentSlotIds, tempCart.CustomerId.Value); eventCustomer.AppointmentId = appointment.Id; eventCustomer = _eventCustomerRepository.Save(eventCustomer); //Moved code into ProcessPayment to Extract Common Code for API and Service ProcessPayment(paymentEditModel, eventCustomer.Id, customer.CustomerId, false); var orderables = new List <IOrderable>(); if (tempCart.EventPackageId.HasValue) { orderables.Add(_eventPackageRepository.GetById(tempCart.EventPackageId.Value)); } 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) { var eventTests = _eventTestRepository.GetbyIds(testIds); if (tempCart.EventPackageId.HasValue) { foreach (var eventTest in eventTests) { eventTest.Price = eventTest.WithPackagePrice; } } orderables.AddRange(eventTests); } 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); orderables.AddRange(products); } if (orderables.IsNullOrEmpty()) { return; } SourceCode sourceCode = null; if (tempCart.SourceCodeId.HasValue && tempCart.SourceCodeId.Value > 0) { var sourceCodeModel = GetSourceCodeApplied(tempCart); sourceCode = new SourceCode { Id = sourceCodeModel.SourceCodeId, CouponCode = sourceCodeModel.SourceCode, CouponValue = sourceCodeModel.DiscountApplied }; } var shippingAddress = tempCart.ShippingAddressId.HasValue ? _addressRepository.GetAddress(tempCart.ShippingAddressId.Value) : null; ShippingDetail shippingDetail = null; if (tempCart.ShippingId != null && tempCart.ShippingId.Value > 0) { var shippingOption = _shippingOptionRepository.GetById(tempCart.ShippingId.Value); shippingDetail = new ShippingDetail { ShippingOption = shippingOption, ShippingAddress = shippingAddress, Status = ShipmentStatus.Processing, ActualPrice = shippingOption.Price, DataRecorderMetaData = new DataRecorderMetaData(tempCart.CustomerId.Value, DateTime.Now, null) }; shippingDetail = _shippingController.OrderShipping(shippingDetail); } bool 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, tempCart.CustomerId.Value, tempCart.CustomerId.Value, sourceCode, eventCustomer, shippingDetail, OrderStatusState.FinalSuccess); indentedLineItemsAdded = true; } else { _orderController.AddItem(orderable, 1, tempCart.CustomerId.Value, tempCart.CustomerId.Value, OrderStatusState.FinalSuccess); } } var order = _orderRepository.GetOrder(tempCart.CustomerId.Value, tempCart.EventId.Value); order = order == null?_orderController.PlaceOrder(OrderType.Retail, tempCart.CustomerId.Value) : _orderController.ActivateOrder(order); if (products != null && products.Count() > 0 && shippingDetail != null) { foreach (var electronicProduct in products) { SaveProductShippingDetail(electronicProduct.Id, order, shippingAddress, customer.CustomerId); } } if (paymentEditModel != null && paymentEditModel.Payments != null && paymentEditModel.Payments.Any(p => p.ChargeCard != null || p.ECheck != null || p.GiftCertificate != null)) { var paymentId = _paymentController.SavePayment(paymentEditModel, tempCart.CustomerId.Value); _orderRepository.ApplyPaymentToOrder(order.Id, paymentId); } scope.Complete(); } }
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 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 void ChangePackage(CustomerOrderDetail customerOrderDetail) { using (var scope = new TransactionScope()) { if (customerOrderDetail.PaymentModel != null) { try { _customerPaymentService.ProcessPayment(customerOrderDetail.PaymentModel); } catch (Exception exception) { throw new Exception(exception.Message, exception); } } try { var eventid = customerOrderDetail.EventId; var customerid = customerOrderDetail.CustomerId; //var eventCustomer = _eventCustomerRepository.Get(eventid, customerid); var order = GetOrder(customerid, eventid); SourceCode sourceCode = null; if (customerOrderDetail.SourceCode != null) { sourceCode = new SourceCode { Id = customerOrderDetail.SourceCode.SourceCodeId, CouponCode = customerOrderDetail.SourceCode.SourceCode, CouponValue = customerOrderDetail.SourceCode.DiscountApplied } } ; IOrderController orderController = new OrderController(); var orderDetail = orderController.GetActiveOrderDetail(order); if (order == null || order.OrderDetails.IsEmpty()) { return; } ShippingDetail shippingDetails = null; if (customerOrderDetail.IsShippingPurchased && customerOrderDetail.ShippingOptions != null && customerOrderDetail.ShippingOptions.Any()) { shippingDetails = _patientShippingDetailFactory.GetShippingDetailData(customerOrderDetail); } var orderables = new List <IOrderable>(); var selectedTestIds = new List <long>(); if (customerOrderDetail.AlaCarteTests != null && customerOrderDetail.AlaCarteTests.Any()) { selectedTestIds = customerOrderDetail.AlaCarteTests.Select(x => x.TestId).ToList(); } long packageId = 0; if (customerOrderDetail.PackageModel != null && customerOrderDetail.PackageModel.PackageId > 0) { packageId = customerOrderDetail.PackageModel.PackageId; 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); } ElectronicProduct product = null; if (customerOrderDetail.ProductId.HasValue && customerOrderDetail.ProductId.Value > 0) { var productIsAlreadyPurchased = order.OrderDetails.Any( x => x.DetailType == OrderItemType.ProductItem && x.OrderItem.ItemId == customerOrderDetail.ProductId.Value); if (!productIsAlreadyPurchased) { product = _electronicProductRepository.GetById(customerOrderDetail.ProductId.Value); orderables.Add(product); } } if (customerOrderDetail.IsShippingPurchased && shippingDetails != null) { IShippingController shippingController = new ShippingController(); var shippingDetail = shippingController.OrderShipping(shippingDetails); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = shippingDetail.ActualPrice, IsActive = true, OrderDetailId = orderDetail.Id, ShippingDetailId = shippingDetail.Id }; _shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); } 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, _creatorOrganizationRoleUser, sourceCode, null, null, OrderStatusState.FinalSuccess); indentedLineItemsAdded = true; } else { _orderController.AddItem(orderable, 1, customerid, _creatorOrganizationRoleUser, OrderStatusState.FinalSuccess); } } _orderController.PlaceOrder(order); if (shippingDetails != null) { SaveProductShippingDetail(product, orderDetail, shippingDetails); } scope.Complete(); } catch (Exception exception) { if (customerOrderDetail.PaymentModel == null) { throw new Exception("An Exception caused while saving the Order.", exception); } var paymentInstruments = customerOrderDetail.PaymentModel.Payments; var chargeCardPayment = paymentInstruments.ChargeCard ?? null; if (chargeCardPayment == null || paymentInstruments.Amount <= 0) { throw new Exception("An Exception caused while saving the Order.", exception); } var paymentGateway = IoC.Resolve <IPaymentProcessor>(); paymentGateway.VoidRequestforaPreviousResponse(chargeCardPayment.ChargeCardPayment.ProcessorResponse); throw new Exception("An Exception caused while saving the Order.", exception); } } }