Beispiel #1
0
        public static void ContractSpec(string symbol)
        {
            var      contractLibraryApi = new ContractLibraryApi();
            Contract contract           = contractLibraryApi.FindContract(symbol);

            Log.Write(contract);
            ContractMaturity contractMaturity = contractLibraryApi.GetContractMaturity(contract.ContractMaturityId);

            Log.Write(contractMaturity);
            Product product = contractLibraryApi.GetProduct(contractMaturity.ProductId);

            Log.Write(product);
            Exchange exchange = contractLibraryApi.GetExchange(product.ExchangeId);

            Log.Write(exchange);
            ContractGroup contractGroup = contractLibraryApi.GetContractGroup(product.ContractGroupId);

            Log.Write(contractGroup);
            Currency currency = contractLibraryApi.GetCurrency(product.CurrencyId);

            Log.Write(currency);
            CurrencyRate currencyRate = contractLibraryApi.GetCurrencyRate(product.CurrencyId);

            Log.Write(currencyRate);
            ProductSession productSession = contractLibraryApi.GetProductSession(product.Id);

            Log.Write(productSession);
            ProductFeeParamsResponse productFees = contractLibraryApi.GetProductFeeParams(new GetProductFeeParams(new List <int?> {
                product.Id
            }));

            foreach (var fee in productFees._Params)
            {
                Log.Write(fee);
            }
            var           riskApi       = new RisksApi();
            ProductMargin productMargin = riskApi.GetProductMargin(product.Id);

            Log.Write(productMargin);
            try
            {
                ContractMargin contractMargin = riskApi.GetContractMargin(contract.Id);
                Log.Write(contractMargin);
            }
            catch
            {
                Log.Write("Per-contract margin is not specified");
            }
        }
Beispiel #2
0
        public static ProductSession ToEntity(this ProductSessionEditDto e)
        {
            if (e == null)
            {
                return(null);
            }

            var res = new ProductSession();

            res.Id          = e.Id;
            res.Description = e.Description;
            res.IdTeacher   = e.IdTeacher;
            res.IdProduct   = e.IdProduct;
            return(res);
        }
Beispiel #3
0
        public static ProductSessionDto ToDto(this ProductSession e)
        {
            if (e == null)
            {
                return(null);
            }

            var res = new ProductSessionDto();

            res.Id           = e.Id;
            res.IdProduct    = e.IdProduct;
            res.Description  = e.Description;
            res.CreationDate = e.XCreateDate;
            res.IdTeacher    = e.IdTeacher;
            res.ProductSessionAttendances = e.ProductSessionAttendances.OrderBy(x => x.CustomerFullName).Select(x => x.ToDto()).ToList();
            res.Teacher   = e.Teacher?.ToDto();
            res.IdTeacher = e.IdTeacher;
            return(res);
        }
Beispiel #4
0
        public async Task <IActionResult> AddToCart(int ProductId, int?Quantity)
        {
            var ProductObj = await _productService.GetProductById(ProductId);

            if (ProductObj == null)
            {
                return(Json(new
                {
                    success = false,
                    message = "Đặt hàng thất bại"
                }));
            }

            if (ProductObj.ProductQuantity < (Quantity ?? 1))
            {
                if (ProductObj == null)
                {
                    return(Json(new
                    {
                        success = false,
                        message = "Hết hàng"
                    }));
                }
            }

            var Session = _session.GetString("Cart");

            if (string.IsNullOrEmpty(Session))
            {
                var Product = new ProductSession {
                    ProductId = ProductId,
                    Quantity  = Quantity ?? 1
                };

                var ListObj = new List <ProductSession>();

                ListObj.Add(Product);

                _session.SetString("Cart", JsonConvert.SerializeObject(ListObj));

                return(Json(new {
                    success = true,
                    message = "Đặt hàng thành công",
                    data = Product
                }));
            }

            var List = JsonConvert.DeserializeObject <List <ProductSession> >(Session);

            var Index = List.FindIndex(x => x.ProductId == ProductId);

            if (Index == -1)
            {
                List.Add(new ProductSession
                {
                    ProductId = ProductId,
                    Quantity  = Quantity ?? 1
                });

                _session.SetString("Cart", JsonConvert.SerializeObject(List));
            }
            else
            {
                List[Index].Quantity = Quantity.Value;
                _session.SetString("Cart", JsonConvert.SerializeObject(List));
            }

            return(Json(new {
                success = true,
                message = "Đặt hàng thành công!",
                data = List
            }));
        }