private void SaveProductShippingDetail(long productId, Order order, Address shippingAddress, long customerId) { var shippingOption = _shippingOptionRepository.GetShippingOptionByProductId(productId); if (shippingOption == null) { return; } OrderDetail orderDetail = _orderController.GetActiveOrderDetail(order); var productShippingDetail = new ShippingDetail { ShippingOption = shippingOption, ActualPrice = shippingOption.Price, Status = ShipmentStatus.Processing, ShippingAddress = shippingAddress, DataRecorderMetaData = new DataRecorderMetaData(customerId, DateTime.Now, null) }; if (orderDetail != null) { productShippingDetail = _shippingController.OrderShipping(productShippingDetail); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = productShippingDetail.ActualPrice, IsActive = true, OrderDetailId = orderDetail.Id, ShippingDetailId = productShippingDetail.Id }; _shipingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); } }
public void UndoCancelShippingRequest(RefundRequest refundRequest) { var order = _orderRepository.GetOrder(refundRequest.OrderId); var activeOrderDetail = _orderController.GetActiveOrderDetail(order); var cancelledShippingDetails = _shippingDetailRepository.GetAllCancelledShippingForOrder(order.Id).OrderByDescending(sd => sd.Id).ToArray(); var shippingDetail = cancelledShippingDetails.FirstOrDefault(cd => cd.ActualPrice == refundRequest.RequestedRefundAmount); if (shippingDetail == null) { throw new Exception("No cancelled shipping item found in the order for requested amount."); } var eventCustomer = _eventCustomerRepository.GetById(activeOrderDetail.EventCustomerOrderDetail.EventCustomerId); var isExclusivelyRequested = _shippingDetailService.CheckShippingIsExclusivelyRequested(eventCustomer.EventId, eventCustomer.CustomerId); var address = _addressRepository.GetAddress(shippingDetail.ShippingAddress.Id); address.Id = 0; shippingDetail.Id = 0; shippingDetail.ShippingAddress = address; shippingDetail.Status = ShipmentStatus.Processing; shippingDetail.IsExclusivelyRequested = isExclusivelyRequested; shippingDetail.DataRecorderMetaData = new DataRecorderMetaData { DataRecorderCreator = _organizationRoleUserRepository.GetOrganizationRoleUser(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId), DateCreated = DateTime.Now, DateModified = DateTime.Now }; IShippingController shippingController = new ShippingController(); shippingDetail = shippingController.OrderShipping(shippingDetail); IRepository <ShippingDetailOrderDetail> shippingDetailOrderDetailRepository = new ShippingDetailOrderDetailRepository(); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = shippingDetail.ActualPrice, IsActive = true, OrderDetailId = activeOrderDetail.Id, ShippingDetailId = shippingDetail.Id }; shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); var productDetail = order.OrderDetails.Where(od => od.DetailType == OrderItemType.ProductItem && od.IsCompleted).Select(od => od).OrderByDescending(od => od.Id).FirstOrDefault(); SaveProductShipping(productDetail, 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); }
private void GetShippingDetailInfo(LinqMetaData linqMetaData, IEnumerable <OrderDetail> orderDetails) { IEnumerable <long> orderDetailIds = orderDetails.Select(ode => ode.Id); foreach (var orderDetailId in orderDetailIds) { long id = orderDetailId; OrderDetail orderDetail = orderDetails.Where(od => od.Id == id).Single(); IEnumerable <ShippingDetailOrderDetailEntity> shippingDetailsInOrder = linqMetaData.ShippingDetailOrderDetail.WithPath( prefetchPath => prefetchPath.Prefetch(sdod => sdod.ShippingDetail)).Where( sdod => id == sdod.OrderDetailId && sdod.IsActive); foreach (var shippingDetailInOrder in shippingDetailsInOrder) { ShippingDetailOrderDetail shippingDetailOrderDetail = _shippingDetailOrderDetailMapper. Map(shippingDetailInOrder); if (orderDetail.ShippingDetailOrderDetails == null) { orderDetail.ShippingDetailOrderDetails = new List <ShippingDetailOrderDetail>(); } orderDetail.ShippingDetailOrderDetails.Add(shippingDetailOrderDetail); } } }
private void SaveProductShipping(OrderDetail productDetail, OrderDetail activeOrderDetail, bool isExclusivelyRequested) { if (productDetail == null || activeOrderDetail == null) { return; } var shippingOption = _shippingOptionRepository.GetShippingOptionByProductId(productDetail.OrderItem.ItemId); if (shippingOption != null) { var resultShippingDetails = _shippingDetailRepository.GetShippingDetailsForCancellation(activeOrderDetail.Id); var cdShippingDetails = _shippingDetailRepository.GetProductShippingDetailsForCancellation(activeOrderDetail.Id); if (!resultShippingDetails.IsNullOrEmpty() && (cdShippingDetails == null || (cdShippingDetails.Count() < resultShippingDetails.Count()))) { var address = _addressRepository.GetAddress(resultShippingDetails.First().ShippingAddress.Id); address.Id = 0; var productShippingDetail = new ShippingDetail { ShippingAddress = address, Status = ShipmentStatus.Processing, ActualPrice = shippingOption.Price, ShippingOption = new ShippingOption { Id = shippingOption.Id }, IsExclusivelyRequested = isExclusivelyRequested, DataRecorderMetaData = new DataRecorderMetaData { DataRecorderCreator = _organizationRoleUserRepository.GetOrganizationRoleUser(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId), DateCreated = DateTime.Now, DateModified = DateTime.Now } }; IShippingController shippingController = new ShippingController(); productShippingDetail = shippingController.OrderShipping(productShippingDetail); IRepository <ShippingDetailOrderDetail> shippingDetailOrderDetailRepository = new ShippingDetailOrderDetailRepository(); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = productShippingDetail.ActualPrice, IsActive = true, OrderDetailId = activeOrderDetail.Id, ShippingDetailId = productShippingDetail.Id }; shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); } } }
private void AddFreeShippingForCustomer(Order order, ShippingDetail shippingDetail) { var orderDetail = _orderController.GetActiveOrderDetail(order); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = shippingDetail.ActualPrice, IsActive = true, OrderDetailId = orderDetail.Id, ShippingDetailId = shippingDetail.Id }; _shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); }
private void SaveProductShippingDetail(ElectronicProduct product, OrderDetail orderDetail, ShippingDetail shippingDetail) { var shippingOptionRepository = IoC.Resolve <IShippingOptionRepository>(); if (product == null) { return; } var shippingOption = shippingOptionRepository.GetShippingOptionByProductId(product.Id); if (shippingOption == null) { return; } var productShippingDetail = new ShippingDetail(); if (shippingDetail != null) { if (shippingOption.Id == shippingDetail.ShippingOption.Id) { return; } productShippingDetail = shippingDetail; } productShippingDetail.Id = 0; productShippingDetail.ShippingAddress.Id = 0; productShippingDetail.ShippingOption.Id = shippingOption.Id; productShippingDetail.ActualPrice = shippingOption.Price; productShippingDetail.IsExclusivelyRequested = false; if (orderDetail != null) { IShippingController shippingController = new ShippingController(); productShippingDetail = shippingController.OrderShipping(productShippingDetail); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = productShippingDetail.ActualPrice, IsActive = true, OrderDetailId = orderDetail.Id, ShippingDetailId = productShippingDetail.Id }; _shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); } }
private void AddPcpShipping(Order order, ShippingOption shippingOption, PrimaryCarePhysician pcp, OrganizationRoleUser organizationRoleUser) { var orderDetail = _orderController.GetActiveOrderDetail(order); var shippingDetails = SavePcpShippingDetail(pcp.Address, organizationRoleUser, shippingOption); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = shippingDetails.ActualPrice, IsActive = true, OrderDetailId = orderDetail.Id, ShippingDetailId = shippingDetails.Id }; _shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); }
private void SaveProductShippingDetail(Core.Finance.Domain.Order order) { if (ProductId.HasValue && ProductId.Value > 0) { var shippingOptionRepository = IoC.Resolve <IShippingOptionRepository>(); var shippingOption = shippingOptionRepository.GetShippingOptionByProductId(ProductId.Value); if (shippingOption == null || ShippingDetail == null) { return; } IOrderController orderController = new OrderController(); OrderDetail orderDetail = orderController.GetActiveOrderDetail(order); if (shippingOption.Id == ShippingDetail.ShippingOption.Id) { return; } var productShippingDetail = ShippingDetail; productShippingDetail.Id = 0; productShippingDetail.ShippingAddress.Id = 0; productShippingDetail.ShippingOption.Id = shippingOption.Id; productShippingDetail.ActualPrice = shippingOption.Price; if (orderDetail != null) { IShippingController shippingController = new ShippingController(); productShippingDetail = shippingController.OrderShipping(productShippingDetail); IRepository <ShippingDetailOrderDetail> shippingDetailOrderDetailRepository = new ShippingDetailOrderDetailRepository(); var shippingDetailOrderDetail = new ShippingDetailOrderDetail { Amount = productShippingDetail.ActualPrice, IsActive = true, OrderDetailId = orderDetail.Id, ShippingDetailId = productShippingDetail.Id }; shippingDetailOrderDetailRepository.Save(shippingDetailOrderDetail); } } }
public OrderDetail CreateNewOrderDetail(IOrderable orderable, int quantity, long forOrganizationRoleUserId, long dataRecorderCreatorId, SourceCode sourceCode, EventCustomer eventCustomer, ShippingDetail shippingDetail, long?sourceId = null) { if (orderable == null) { throw new ArgumentNullException("orderable"); } if (orderable.Id == 0) { throw new InvalidOperationException("itemToOrder must already exist in the database."); } if (quantity < 1) { throw new ArgumentOutOfRangeException("quantity", "The quantity must be at least 1."); } DataRecorderMetaData dataRecorderMetaData = _dataRecorderMetaDataFactory. CreateDataRecorderMetaData(dataRecorderCreatorId); OrderItemStatus orderItemStatus = _orderItemStatusFactory.CreateOrderItemStatus(orderable. OrderItemType, (int)OrderStatusState.Initial); decimal price = orderable.Price; // TODO: Test source code logic. SourceCodeOrderDetail sourceCodeOrderDetail = null; if (sourceCode != null) { sourceCodeOrderDetail = new SourceCodeOrderDetail { Amount = sourceCode.CouponValue, SourceCodeId = sourceCode.Id, IsActive = true, OrganizationRoleUserCreatorId = dataRecorderMetaData.DataRecorderCreator.Id }; } EventCustomerOrderDetail eventCustomerOrderDetail = null; if (eventCustomer != null) { eventCustomerOrderDetail = new EventCustomerOrderDetail { EventCustomerId = eventCustomer.Id, IsActive = true }; } ShippingDetailOrderDetail shippingDetailOrderDetail = null; if (shippingDetail != null) { shippingDetailOrderDetail = new ShippingDetailOrderDetail { ShippingDetailId = shippingDetail.Id, IsActive = true }; } return(new OrderDetail { Description = orderable.Description, Price = price, Quantity = quantity, DetailType = orderable.OrderItemType, DataRecorderMetaData = dataRecorderMetaData, ForOrganizationRoleUserId = forOrganizationRoleUserId, OrderItemStatus = orderItemStatus, SourceCodeOrderDetail = sourceCodeOrderDetail, EventCustomerOrderDetail = eventCustomerOrderDetail, ShippingDetailOrderDetails = new List <ShippingDetailOrderDetail> { shippingDetailOrderDetail }, SourceId = sourceId }); }
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); } } }