示例#1
0
        public async Task ModifyOrder(PendingOrderModel oldOrder, PendingOrderModel newOrder, long accountId, bool isLive)
        {
            VerifyConnection();

            var requestMessage = new ProtoOAAmendOrderReq
            {
                OrderId             = oldOrder.Id,
                CtidTraderAccountId = accountId,
                Volume = newOrder.Volume,
            };

            if (newOrder.IsStopLossEnabled)
            {
                requestMessage.StopLoss         = newOrder.StopLossInPrice;
                requestMessage.TrailingStopLoss = newOrder.IsTrailingStopLossEnabled;
            }

            if (newOrder.IsTakeProfitEnabled)
            {
                requestMessage.TakeProfit = newOrder.TakeProfitInPrice;
            }

            if (newOrder.IsExpiryEnabled)
            {
                requestMessage.ExpirationTimestamp = new DateTimeOffset(newOrder.ExpiryTime).ToUnixTimeMilliseconds();
            }

            if (newOrder.Type == PendingOrderType.Limit)
            {
                requestMessage.LimitPrice = newOrder.Price;
            }
            else
            {
                requestMessage.StopPrice = newOrder.Price;

                if (newOrder.Type == PendingOrderType.StopLimit)
                {
                    var slippageinPoint = newOrder.Symbol.Data.GetPointsFromPips(newOrder.LimitRangeInPips);

                    if (slippageinPoint < int.MaxValue)
                    {
                        requestMessage.SlippageInPoints = (int)slippageinPoint;
                    }
                }
            }

            var client = GetClient(isLive);

            await client.SendMessage(requestMessage, ProtoOAPayloadType.ProtoOaAmendOrderReq);
        }
        public ActionResult UserReviewsData(string Type)
        {
            Type = Type.ToLower();
            var customer = _workContext.CurrentCustomer;

            if (customer != null && customer.IsRegistered())
            {
                if (Type == "product")
                {
                    var productReviews = _productService.GetAllProductReviews(customer.Id, null);
                    productReviews = productReviews.OrderByDescending(pr => pr.CreatedOnUtc).ToList();
                    var model = new PublicProductReviewDisplayModel()
                    {
                        ProductReviews = productReviews.ToModel(_pictureService)
                    };

                    foreach (var pr in productReviews)
                    {
                        if (model.ProductImageUrl.ContainsKey(pr.ProductId))
                        {
                            continue;
                        }
                        var imageUrl = _pictureService.GetPictureUrl(pr.Product.ProductPictures.FirstOrDefault().Picture);
                        model.ProductImageUrl.Add(pr.ProductId, imageUrl);
                    }
                    return(View("ExtendedVendor/UserProductReviews", model));
                }
                if (Type == "vendor")
                {
                    var vendorReviews = _extendedVendorService.GetVendorReviews(null, customer.Id, null, 1, int.MaxValue).ToList();


                    var model = new PublicVendorReviewDisplayModel()
                    {
                        VendorReviews = vendorReviews.ToListModel(_pictureService, _productService, _vendorService, _customerService)
                    };
                    return(View("ExtendedVendor/UserVendorReviews", model));
                }
                if (Type == "pending")
                {
                    var customerOrders        = _orderService.SearchOrders(0, 0, customer.Id, 0, 0, 0, 0, null, null, null, OrderStatus.Complete, PaymentStatus.Paid, ShippingStatus.Delivered).ToList();
                    var pendingReviewProducts = _extendedVendorService.GetProductsWithPendingReviews(customerOrders, customer.Id);

                    var model      = new PublicPendingReviewDisplayModel();
                    var vendorList = new Dictionary <int, Vendor>(); //storing vendors for performance

                    foreach (var prp in pendingReviewProducts)
                    {
                        var order      = prp.Key;
                        var orderModel = new PendingOrderModel()
                        {
                            OrderId = order.Id,
                        };
                        var reviewModelList = new List <PendingReviewModel>();

                        foreach (var product in prp.Value)
                        {
                            Vendor v = null;
                            if (vendorList.ContainsKey(product.VendorId))
                            {
                                v = vendorList[product.VendorId];
                            }
                            else
                            {
                                v = _vendorService.GetVendorById(product.VendorId);
                                vendorList.Add(v.Id, v);//add it to a dictionary for avoiding next time database query for same vendor
                            }

                            var prModel = new PendingReviewModel()
                            {
                                OrderId         = order.Id,
                                ProductId       = product.Id,
                                ProductName     = product.Name,
                                ProductImageUrl = _pictureService.GetPictureUrl(product.ProductPictures.FirstOrDefault().Picture),
                                ProductSeName   = product.GetSeName(),
                                VendorName      = v.Name,
                                VendorSeName    = v.GetSeName()
                            };
                            reviewModelList.Add(prModel);
                        }
                        model.PendingReviews.Add(orderModel, reviewModelList);
                    }
                    return(View("ExtendedVendor/UserPendingReviews", model));
                }
                return(InvokeHttp404());
            }
            return(RedirectToRoute("Homepage"));
        }