Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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 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);
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        private bool PaymentViaSourceCode()
        {
            var organizationRoleUser = GetOrganizationRoleUser();

            var orderables     = new List <IOrderable>();
            var packageTestIds = new List <long>();

            if (PackageId > 0)
            {
                var packageRepository = IoC.Resolve <IEventPackageRepository>();
                var package           = packageRepository.GetByEventAndPackageIds(EventId.Value, PackageId);
                if (package != null)
                {
                    packageTestIds = package.Tests.Select(t => t.Test.Id).ToList();
                }

                orderables.Add(package);
            }

            var independentTestIds = !packageTestIds.IsNullOrEmpty() ? TestIds.Where(t => !packageTestIds.Contains(t)).Select(t => t).ToList() : TestIds;

            if (!independentTestIds.IsNullOrEmpty())
            {
                var eventTestRepository = IoC.Resolve <IEventTestRepository>();
                orderables.AddRange(eventTestRepository.GetByEventAndTestIds(EventId.Value, independentTestIds));
            }

            if (ProductId.HasValue && ProductId.Value > 0)
            {
                IUniqueItemRepository <ElectronicProduct> itemRepository = new ElectronicProductRepository();
                orderables.Add(itemRepository.GetById(ProductId.Value));
            }

            if (orderables.IsNullOrEmpty())
            {
                return(false);
            }

            Core.Finance.Domain.Order order = null;
            EventCustomer             eventCustomer;

            try
            {
                order = GetOrder();
                if (order == null)
                {
                    eventCustomer = SaveEventCustomer(organizationRoleUser);
                }
                else
                {
                    eventCustomer = UpdateEventCustomer(organizationRoleUser);
                }
            }
            catch
            {
                eventCustomer = SaveEventCustomer(organizationRoleUser);
            }

            SourceCode sourceCode;

            if (SourceCodeId > 0)
            {
                sourceCode = new SourceCode
                {
                    Id          = SourceCodeId,
                    CouponCode  = SourceCode,
                    CouponValue = SourceCodeAmount
                }
            }
            ;
            else
            {
                sourceCode = null;
            }

            if (ShippingDetail != null)
            {
                IShippingController shippingController = new ShippingController();
                ShippingDetail = shippingController.OrderShipping(ShippingDetail);
            }

            IOrderController orderController        = new OrderController();
            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)
                {
                    orderController.AddItem(orderable, 1, organizationRoleUser.Id, organizationRoleUser.Id,
                                            sourceCode,
                                            eventCustomer, ShippingDetail, OrderStatusState.FinalSuccess);
                    indentedLineItemsAdded = true;
                }
                else
                {
                    orderController.AddItem(orderable, 1, organizationRoleUser.Id, organizationRoleUser.Id,
                                            OrderStatusState.FinalSuccess);
                }
            }

            if (order == null)
            {
                order = orderController.PlaceOrder(OrderType.Retail, organizationRoleUser.Id);
            }
            else
            {
                order = orderController.ActivateOrder(order);
            }

            SaveProductShippingDetail(order);
            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);
                }
            }
        }