コード例 #1
0
        public ActionResult RemoveProductFromBasket(int productId, string productType)
        {
            AccountOrder       currentAccountOrder = CurrentUser?.AccountOrders.LastOrDefault(ord => !ord.Completed);
            AccountOrderRecord accountOrderRecord  = currentAccountOrder?.AccountOrderRecords.FirstOrDefault(
                rec => rec.ProductId == productId && rec.ProductType == productType);

            if (accountOrderRecord != null)
            {
                DataContext.AccountOrderRecords.DeleteOnSubmit(accountOrderRecord);
                DataContext.SubmitChanges();
                CalcAccountOrderSum(currentAccountOrder, accountOrderRecord.Count);
            }

            VisitorOrder       currentVisitorOrder = CurrentVisitor?.VisitorOrders.LastOrDefault(ord => !ord.Completed);
            VisitorOrderRecord visitorOrderRecord  =
                currentVisitorOrder?.VisitorOrderRecords.FirstOrDefault(
                    rec => rec.ProductId == productId && rec.ProductType == productType);

            if (visitorOrderRecord != null)
            {
                DataContext.VisitorOrderRecords.DeleteOnSubmit(visitorOrderRecord);
                DataContext.SubmitChanges();
                CalcVisitorOrderSum(currentVisitorOrder, visitorOrderRecord.Count);
            }

            return(RedirectToAction("Basket"));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: leonkouz/BittrexAPI
        static void Main(string[] args)
        {
            Constants.ApiKey    = "";
            Constants.SecretKey = "";


            #region PublicAPI

            //Get Markets test
            List <Market> listOfMarkets = APIMethods.GetMarkets();

            //Get all supported currencies
            List <MarketCurrency> listOfCurrencies = APIMethods.GetCurrencies();

            //Get the current tick value for the specified market
            Ticker tick = APIMethods.GetTicker("BTC-LTC");

            //Gets the summary of all markets
            List <MarketSummary> listOfMarketSummaries = APIMethods.GetMarketSummaries();

            //Gets the summary of a specificed market
            MarketSummary marketSummary = APIMethods.GetMarketSummary("BTC-LTC");

            //Gets the Order book for the specified market
            OrderBook book = APIMethods.GetOrderBook("BTC-LTC", Order.Type.both);

            List <MarketHistory> marketHistory = APIMethods.GetMarketHistory("BTC-LTC");

            #endregion


            #region MarketAPI

            //APIMethods.PlaceBuyLimitOrder("BTC-LTC", 5, 0.17);

            // APIMethods.PlaceSellLimitOrder("BTC-LTC", 5, 0.17);

            APIMethods.CancelOrder("328bd88e-537e-4979-9d8b-d2e827d1a49e");

            // List<OpenOrder> orders = APIMethods.GetOpenOrders("BTC-GRS");

            #endregion

            #region AccountAPI

            //  List<Balance> balanceList = APIMethods.GetBalances();

            Balance balance = APIMethods.GetBalance("GRS");

            //APIMethods.Withdraw("GRS", 20.23222, "Address to withdraw GRS to");

            AccountOrder accountOrder = APIMethods.GetOrder("uuid here");

            List <HistoryOrder> listOfOrderHistory = APIMethods.GetOrderHistory();

            List <HistoryOrder> listOfSpecificOrderHistory = APIMethods.GetOrderHistory("BTC-LTC");


            #endregion
        }
コード例 #3
0
        private void CalcAccountOrderSum(AccountOrder order, int count)
        {
            if (order == null)
            {
                return;
            }
            order.Sum = 0;

            foreach (AccountOrderRecord record in order.AccountOrderRecords)
            {
                if (record.ProductType == typeof(Book).Name)
                {
                    order.Sum += (float)DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId)
                                 .Price *count;
                }

                if (record.ProductType == typeof(Journal).Name)
                {
                    order.Sum += (float)DataContext.Journals
                                 .FirstOrDefault(journal => journal.Id == record.ProductId)
                                 .Price *count;
                }

                if (record.ProductType == typeof(Newspaper).Name)
                {
                    order.Sum += (float)DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId)
                                 .Price *count;
                }
            }
            DataContext.SubmitChanges();
        }
コード例 #4
0
        public IHttpActionResult RemoveProductFromBasket(RemoveProductFromBasketModel model)
        {
            try
            {
                AccountOrder       currentAccountOrder = CurrentUser?.AccountOrders.LastOrDefault(ord => !ord.Completed);
                AccountOrderRecord accountOrderRecord  = currentAccountOrder?.AccountOrderRecords.FirstOrDefault(
                    rec => rec.ProductId == model.ProductId && rec.ProductType == model.ProductType);
                if (accountOrderRecord != null)
                {
                    DataContext.AccountOrderRecords.DeleteOnSubmit(accountOrderRecord);
                    DataContext.SubmitChanges();
                    CalcAccountOrderSum(currentAccountOrder, accountOrderRecord.Count);
                    return(Ok());
                }

                VisitorOrder       currentVisitorOrder = CurrentVisitor?.VisitorOrders.LastOrDefault(ord => !ord.Completed);
                VisitorOrderRecord visitorOrderRecord  =
                    currentVisitorOrder?.VisitorOrderRecords.FirstOrDefault(
                        rec => rec.ProductId == model.ProductId && rec.ProductType == model.ProductType);
                if (visitorOrderRecord != null)
                {
                    DataContext.VisitorOrderRecords.DeleteOnSubmit(visitorOrderRecord);
                    DataContext.SubmitChanges();
                    CalcVisitorOrderSum(currentVisitorOrder, visitorOrderRecord.Count);
                    return(Ok());
                }
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
            return(Ok());
        }
コード例 #5
0
        public void Order(AccountOrder accountOrder)
        {
            var createOrderingCommand = new CreateOrderingCommand(
                accountOrder.AccountId,
                accountOrder.CourseId,
                accountOrder.Amount
                );

            _bus.SendCommand(createOrderingCommand);
        }
コード例 #6
0
        public IActionResult GetListBoughtProducts()
        {
            AccountOrder accountOrder = new AccountOrder();
            var          apiRep       = new APIResponse();
            var          userId       = string.Empty;

            if (HttpContext.User.Identity is ClaimsIdentity identity)
            {
                userId = identity.FindFirst(ClaimTypes.Name).Value;
            }
            accountOrder.AccountId = userId;
            List <Order> Orders = _orderService.Get();

            if (Orders == null)
            {
                apiRep.Error   = true;
                apiRep.Message = "Can't not find list order";
                return(BadRequest(apiRep));
            }
            foreach (Order item in Orders)
            {
                if (item.AccountId == accountOrder.AccountId)
                {
                    for (var i = 0; i < item.orderinfo.carts.Length; i++)
                    {
                        var flag  = 0;
                        var index = 0;
                        for (var j = 0; j < accountOrder.carts.Count; j++)
                        {
                            for (var k = 0; k < accountOrder.carts.Count; k++)
                            {
                                if (accountOrder.carts[j].ProductId.ToString() == item.orderinfo.carts[i].ProductId)
                                {
                                    flag  = 1;
                                    index = j;
                                    break;
                                }
                            }
                        }
                        if (flag == 0)
                        {
                            Pro pro = new Pro();
                            pro = item.orderinfo.carts[i];
                            accountOrder.carts.Add(pro);
                        }
                        else
                        {
                            accountOrder.carts[index].Amount += item.orderinfo.carts[i].Amount;
                        }
                    }
                    apiRep.Data = accountOrder;
                }
            }
            return(Ok(apiRep));
        }
コード例 #7
0
        public AccountOrder Create(int accountId, int orderId)
        {
            var accountOrder = new AccountOrder
            {
                Id        = 0,
                AccountId = accountId,
                OrderId   = orderId,
                BeginDate = DateTime.Now
            };

            return(accountOrder);
        }
コード例 #8
0
        public IActionResult GetAccountOrder(String userId)
        {
            AccountOrder accountOrder = new AccountOrder();
            var          apiRep       = new APIResponse();

            accountOrder.AccountId = userId;
            List <Order> Orders = _orderService.Get();

            if (Orders == null)
            {
                apiRep.Error   = true;
                apiRep.Message = "Can't not find list order";
                return(BadRequest(apiRep));
            }
            foreach (Order item in Orders)
            {
                if (item.AccountId == accountOrder.AccountId)
                {
                    for (var i = 0; i < item.orderinfo.carts.Length; i++)
                    {
                        var flag  = 0;
                        var index = 0;
                        for (var j = 0; j < accountOrder.carts.Count; j++)
                        {
                            for (var k = 0; k < accountOrder.carts.Count; k++)
                            {
                                if (accountOrder.carts[j].ProductId.ToString() == item.orderinfo.carts[i].ProductId)
                                {
                                    flag  = 1;
                                    index = j;
                                    break;
                                }
                            }
                        }
                        if (flag == 0)
                        {
                            Pro pro = new Pro();
                            pro = item.orderinfo.carts[i];
                            accountOrder.carts.Add(pro);
                        }
                        else
                        {
                            accountOrder.carts[index].Amount += item.orderinfo.carts[i].Amount;
                        }
                    }
                    apiRep.Data = accountOrder;
                }
            }
            return(Ok(apiRep));
        }
コード例 #9
0
        /// <summary>
        /// Used to retrieve a single order by uuid.
        /// </summary>
        /// <param name="uuid">The uuid of the buy or sell order</param>
        /// <returns>The details of an specific order</returns>
        public static AccountOrder GetOrder(string uuid)
        {
            string url = Constants.baseUrl + "account/getorder&uuid=" + uuid + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    Console.WriteLine("*Unable to get balances" + "\n" +
                                      "Error: " + response.message + "\n"
                                      );
                    throw new Exception("Unable to get data from API: " + response.message.ToString());
                }
            }

            string accountId                   = response.result.AccountId.ToString();
            string orderUuid                   = response.result.OrderUuid.ToString();
            string exchange                    = response.result.Exchange.ToString();
            string type                        = response.result.Type.ToString();
            string quantity                    = response.result.Quantity.ToString();
            string quantityRemaing             = response.result.QuantityRemaining.ToString();
            string limit                       = response.result.Limit.ToString();
            string reserved                    = response.result.Reserved.ToString();
            string reservedRemaining           = response.result.ReservedRemaining.ToString();
            string commissionReserved          = response.result.ReserveRemaining.ToString();
            string commissionReservedRemaining = response.result.CommissionReserveRemaining.ToString();
            string commissionPaid              = response.result.CommissionPaid.ToString();
            string price                       = response.result.Price.ToString();
            string pricePerUnit                = response.result.PricePerUnit.ToString();
            string opened                      = response.result.Opened.ToString();
            string closed                      = response.result.Closed.ToString();
            string isOpen                      = response.result.IsOpen.ToString();
            string sentinel                    = response.result.Sentinel.ToString();
            string cancelInitiated             = response.result.CancelInitiated.ToString();
            string immediateOrCancel           = response.result.ImmediateOrCancel.ToString();
            string isConditional               = response.result.IsConditional.ToString();
            string condiition                  = response.result.Condition.ToString();
            string conditionTarget             = response.result.ConditionTarget.ToString();

            AccountOrder order = new AccountOrder(accountId, orderUuid, exchange, type, quantity, quantityRemaing, limit, reserved, reservedRemaining, commissionReserved,
                                                  commissionReservedRemaining, commissionPaid, price, pricePerUnit, opened, closed, isOpen, sentinel, cancelInitiated, immediateOrCancel, isConditional, condiition, conditionTarget);

            return(order);
        }
コード例 #10
0
        public AccountOrder SetAccountOrder(AccountOrder accountOrder, bool isActual, DbTransaction dbTran)
        {
            var accountOrderId = accountOrder.Id;
            var lastEditDate   = accountOrder.BeginDate;

            SetAccountOrder(
                dbTran: dbTran,
                id: ref accountOrderId,
                accountId: accountOrder.AccountId,
                orderId: accountOrder.OrderId,
                isActual: isActual,
                lastEditDate: ref lastEditDate,
                editUserId: _editUserId);

            accountOrder.Id        = accountOrderId;
            accountOrder.BeginDate = lastEditDate;

            return(accountOrder);
        }
コード例 #11
0
        public static bool CheckBalance()
        {
            i++;
            if (usdt == null)
            {
                var accountId   = AccountConfig.mainAccountId;
                var accountInfo = new AccountOrder().AccountBalance(accountId);
                usdt = accountInfo.data.list.Find(it => it.currency == "usdt");
            }

            if (usdt.balance < 10 && i % 100 == 0)
            {
                Console.WriteLine($"--------------------- 余额{usdt.balance}----------------------------");
            }

            if (usdt.balance < 6)
            {
                Console.WriteLine("---------------------余额小于6,无法交易----------------------------");
                return(false);
            }
            return(true);
        }
コード例 #12
0
        public static decimal GetRecommendBuyAmount()
        {
            if (noSellCount < 0)
            {
                noSellCount = new CoinDao().GetAllNoSellRecordCount();
            }

            if (usdt == null)
            {
                var accountId   = AccountConfig.mainAccountId;
                var accountInfo = new AccountOrder().AccountBalance(accountId);
                usdt = accountInfo.data.list.Find(it => it.currency == "usdt");
            }

            if (noSellCount > 180)
            {
                return(usdt.balance / 60);
            }

            // 让每个承受8轮
            return(usdt.balance / (240 - noSellCount));
        }
コード例 #13
0
        private void SellIsAccount(int code, string type, int count)
        {
            if (CurrentUser != null)
            {
                AccountOrderRecord record = new AccountOrderRecord()
                {
                    Count       = count,
                    ProductId   = code,
                    ProductType = type,
                };

                AccountOrder order = CurrentUser.AccountOrders.LastOrDefault(ord => !ord.Completed);
                if (order != null)
                {
                    record.AccountOrder = order;
                    order.AccountOrderRecords.Add(record);
                }
                else
                {
                    order = new AccountOrder()
                    {
                        Account   = CurrentUser,
                        AccountId = CurrentUser.Id,
                        Completed = false
                    };

                    record.AccountOrder = order;
                    order.AccountOrderRecords.Add(record);
                    DataContext.AccountOrders.InsertOnSubmit(order);

                    CurrentUser.AccountOrders.Add(order);
                }

                CalcAccountOrderSum(order, count);

                DataContext.SubmitChanges();
            }
        }
コード例 #14
0
        public string GetCurrentAccountContractBefore(long docId)
        {
            string             result             = null;
            AccountOrder       order              = new AccountOrder();
            AuthorizedCustomer authorizedCustomer = _cacheHelper.GetAuthorizedCustomer();
            int fillialCode = _cacheHelper.GetAuthorizedCustomer().BranchCode;

            order = _xBService.GetAccountOrder(docId);
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add(key: "customerNumber", value: authorizedCustomer.CustomerNumber.ToString());
            parameters.Add(key: "HbDocID", value: docId.ToString());
            parameters.Add(key: "currencyHB", value: order.Currency);
            parameters.Add(key: "reopen", value: "0");
            parameters.Add(key: "armNumber", value: "0");
            parameters.Add(key: "armNumberStr", value: "0");
            parameters.Add(key: "accountTypeHB", value: (order.AccountType - 1).ToString());
            parameters.Add(key: "thirdPersonCustomerNumberHB", value: "0");
            parameters.Add(key: "filialCode", value: fillialCode.ToString());
            parameters.Add(key: "receiveTypeHB", value: order.StatementDeliveryType.ToString());
            result = _contractService.RenderContract("CurrentAccContract", parameters, "CurrentAccContract.pdf");
            return(result);
        }
コード例 #15
0
        public IActionResult CreateOrder(MasterAccount model)
        {
            var account = _dbContext.master_account.Where(x => (x.username.Equals(model.username) && x.password.Equals(model.password) && x.acc_type.Equals(true))).ToList();

            if (account.Count() < 1 || HttpContext.Session.GetInt32("user_id") != account.ElementAt(0).acc_id)
            {
                ModelState.AddModelError(string.Empty, "Invalid validation attempt.");
                return(View());
            }
            else
            {
                AccountOrder model1 = new AccountOrder();
                model1.order_num = _dbContext.order_full.Count() + 1;
                model1.acc_id    = (int)(HttpContext.Session.GetInt32("user_id"));
                model1.urgency   = 10;
                model1.active    = true;
                _dbContext.order_full.Add(model1);

                List <OrderItem> cart = SessionHelper.GetObjectFromJson <List <OrderItem> >(HttpContext.Session, "cart");
                for (int i = 0; i < cart.Count(); i++)
                {
                    OrderItem model2 = new OrderItem();
                    model2.order_num = model1.order_num;
                    model2.prod_id   = cart.ElementAt(i).prod_id;
                    model2.quantity  = cart.ElementAt(i).quantity;
                    _dbContext.order_item.Add(model2);
                }

                _dbContext.SaveChanges();

                List <OrderItem> ResetCart = new List <OrderItem>();
                SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", ResetCart);
                ViewBag.cart = ResetCart;

                return(RedirectToAction("IndexAsync"));
            }
        }
コード例 #16
0
        public IActionResult ApproveAccountOrder(ApproveIdRequest request)
        {
            if (ModelState.IsValid)
            {
                var response = new SingleResponse <long>()
                {
                    ResultCode = ResultCodes.normal
                };

                AccountOrder order = _cacheHelper.GetApprovalOrder <AccountOrder>(request.Id);

                ActionResult saveResult = _xbService.ApproveAccountOrder(order);

                response.ResultCode  = ResultCodeFormatter.FromPersonalAccountSecurityService(saveResult.ResultCode);
                response.Result      = saveResult.Id;
                response.Description = utils.GetActionResultErrors(saveResult.Errors);

                return(ResponseExtensions.ToHttpResponse(response));
            }
            else
            {
                return(ValidationError.GetValidationErrorResponse(ModelState));
            }
        }
コード例 #17
0
        public static void BusinessRun(string coin)
        {
            var accountId = AccountConfig.mainAccountId;
            // 获取最近行情
            decimal lastLow;
            decimal nowOpen;
            var     flexPointList = new CoinAnalyze().Analyze(coin, "usdt", out lastLow, out nowOpen);

            if (flexPointList.Count == 0)
            {
                logger.Error($"--------------> 分析结果数量为0 {coin}");
                return;
            }

            // 分析是否下跌, 下跌超过一定数据,可以考虑
            var list = new CoinDao().ListNoSellRecord(coin);

            Console.WriteLine($"未售出{list.Count}");

            decimal recommendAmount = GetRecommendBuyAmount();

            Console.Write($"------------>{recommendAmount}");
            if (false && !flexPointList[0].isHigh && CheckBalance() && recommendAmount > 2)
            {
                // 最后一次是高位
                if (list.Count <= 0 && CheckCanBuy(nowOpen, flexPointList[0].open))
                {
                    // 可以考虑
                    decimal buyQuantity = recommendAmount / nowOpen;
                    buyQuantity = decimal.Round(buyQuantity, GetBuyQuantityPrecisionNumber(coin));
                    decimal       buyPrice = decimal.Round(nowOpen * (decimal)1.005, getPrecisionNumber(coin));
                    ResponseOrder order    = new AccountOrder().NewOrderBuy(accountId, buyQuantity, buyPrice, null, coin, "usdt");
                    if (order.status != "error")
                    {
                        new CoinDao().InsertLog(new BuyRecord()
                        {
                            BuyCoin        = coin,
                            BuyPrice       = buyPrice,
                            BuyDate        = DateTime.Now,
                            HasSell        = false,
                            BuyOrderResult = JsonConvert.SerializeObject(order),
                            BuyAnalyze     = JsonConvert.SerializeObject(flexPointList),
                            BuyAmount      = buyQuantity,
                            UserName       = AccountConfig.userName
                        });
                        ClearData();
                    }
                    else
                    {
                        logger.Error($"下单结果 coin{coin} accountId:{accountId}  购买数量{buyQuantity} nowOpen{nowOpen} {JsonConvert.SerializeObject(order)}");
                        logger.Error($"下单结果 分析 {JsonConvert.SerializeObject(flexPointList)}");
                    }
                }

                if (list.Count > 0)
                {
                    // 获取最小的那个, 如果有,
                    decimal minBuyPrice = 9999;
                    foreach (var item in list)
                    {
                        if (item.BuyPrice < minBuyPrice)
                        {
                            minBuyPrice = item.BuyPrice;
                        }
                    }

                    // 再少于5%,
                    decimal pecent = list.Count >= 15 ? (decimal)1.03 : (decimal)1.025;
                    if (nowOpen * pecent < minBuyPrice)
                    {
                        decimal buyQuantity = recommendAmount / nowOpen;
                        buyQuantity = decimal.Round(buyQuantity, GetBuyQuantityPrecisionNumber(coin));
                        decimal       buyPrice = decimal.Round(nowOpen * (decimal)1.005, getPrecisionNumber(coin));
                        ResponseOrder order    = new AccountOrder().NewOrderBuy(accountId, buyQuantity, buyPrice, null, coin, "usdt");
                        if (order.status != "error")
                        {
                            new CoinDao().InsertLog(new BuyRecord()
                            {
                                BuyCoin        = coin,
                                BuyPrice       = buyPrice,
                                BuyDate        = DateTime.Now,
                                HasSell        = false,
                                BuyOrderResult = JsonConvert.SerializeObject(order),
                                BuyAnalyze     = JsonConvert.SerializeObject(flexPointList),
                                UserName       = AccountConfig.userName,
                                BuyAmount      = buyQuantity
                            });
                            usdt        = null;
                            noSellCount = -1;
                        }
                        else
                        {
                            logger.Error($"下单结果 coin{coin} accountId:{accountId}  购买数量{buyQuantity} nowOpen{nowOpen} {JsonConvert.SerializeObject(order)}");
                            logger.Error($"下单结果 分析 {JsonConvert.SerializeObject(flexPointList)}");
                        }
                    }
                }
            }

            // 查询数据库中已经下单数据,如果有,则比较之后的最高值,如果有,则出售
            if (list.Count > 0)
            {
                foreach (var item in list)
                {
                    // 分析是否 大于
                    decimal itemNowOpen = 0;
                    decimal higher      = new CoinAnalyze().AnalyzeNeedSell(item.BuyPrice, item.BuyDate, coin, "usdt", out itemNowOpen);

                    if (CheckCanSell(item.BuyPrice, higher, itemNowOpen))
                    {
                        decimal sellAmount = item.BuyAmount * (decimal)0.99;
                        sellAmount = decimal.Round(sellAmount, getSellPrecisionNumber(coin));
                        // 出售
                        decimal       sellPrice = decimal.Round(itemNowOpen * (decimal)0.985, getPrecisionNumber(coin));
                        ResponseOrder order     = new AccountOrder().NewOrderSell(accountId, sellAmount, sellPrice, null, coin, "usdt");
                        if (order.status != "error")
                        {
                            new CoinDao().SetHasSell(item.Id, sellAmount, JsonConvert.SerializeObject(order), JsonConvert.SerializeObject(flexPointList));
                        }
                        else
                        {
                            logger.Error($"出售结果 coin{coin} accountId:{accountId}  出售数量{sellAmount} itemNowOpen{itemNowOpen} higher{higher} {JsonConvert.SerializeObject(order)}");
                            logger.Error($"出售结果 分析 {JsonConvert.SerializeObject(flexPointList)}");
                        }
                        usdt        = null;
                        noSellCount = -1;
                    }
                }
            }
        }
コード例 #18
0
        public IHttpActionResult AcceptSellOrder(AcceptSellOrderModel orderId)
        {
            if (CurrentUser != null)
            {
                try
                {
                    AccountOrder order = DataContext.AccountOrders.FirstOrDefault(ord => ord.Id == orderId.OrderId);
                    if (order != null)
                    {
                        foreach (AccountOrderRecord record in order.AccountOrderRecords)
                        {
                            if (record.ProductType == typeof(Book).Name)
                            {
                                DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId).Amount -=
                                    record.Count;
                            }
                            if (record.ProductType == typeof(Journal).Name)
                            {
                                DataContext.Journals.FirstOrDefault(jor => jor.Id == record.ProductId).Amount -=
                                    record.Count;
                            }
                            if (record.ProductType == typeof(Newspaper).Name)
                            {
                                DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId).Amount -=
                                    record.Count;
                            }
                        }

                        order.Completed = true;

                        DataContext.SubmitChanges();
                    }
                }
                catch (Exception e)
                {
                    return(InternalServerError(e));
                }
            }

            if (CurrentVisitor != null)
            {
                try
                {
                    VisitorOrder order = DataContext.VisitorOrders.FirstOrDefault(ord => ord.Id == orderId.OrderId);
                    if (order != null)
                    {
                        foreach (VisitorOrderRecord record in order.VisitorOrderRecords)
                        {
                            if (record.ProductType == typeof(Book).Name)
                            {
                                DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId).Amount -=
                                    record.Count;
                            }
                            if (record.ProductType == typeof(Journal).Name)
                            {
                                DataContext.Journals.FirstOrDefault(jor => jor.Id == record.ProductId).Amount -=
                                    record.Count;
                            }
                            if (record.ProductType == typeof(Newspaper).Name)
                            {
                                DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId).Amount -=
                                    record.Count;
                            }
                        }

                        order.Completed = true;

                        DataContext.SubmitChanges();
                    }
                }
                catch (Exception e)
                {
                    return(InternalServerError(e));
                }
            }

            return(Ok());
        }
コード例 #19
0
 public IActionResult Post([FromBody] AccountOrder accountTransfer)
 {
     _accountService.Order(accountTransfer);
     return(Ok(accountTransfer));
 }
コード例 #20
0
        public IHttpActionResult Basket()
        {
            BasketModel model = new BasketModel();

            if (CurrentUser != null)
            {
                try
                {
                    AccountOrder order = CurrentUser.AccountOrders.LastOrDefault(ord => !ord.Completed);

                    if (order != null)
                    {
                        model.SumPrice = order.Sum;
                        model.OrderId  = order.Id;
                        foreach (AccountOrderRecord record in order.AccountOrderRecords)
                        {
                            if (record.ProductType == typeof(Book).Name)
                            {
                                model.BookProducts.Add(
                                    new BookModel(
                                        DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId)));
                            }
                            if (record.ProductType == typeof(Journal).Name)
                            {
                                model.JournalProducts.Add(
                                    new JournalModel(
                                        DataContext.Journals.FirstOrDefault(
                                            journal => journal.Id == record.ProductId)));
                            }
                            if (record.ProductType == typeof(Newspaper).Name)
                            {
                                model.NewspaperProducts.Add(
                                    new NewspaperModel(
                                        DataContext.Newspapers.FirstOrDefault(
                                            newspaper => newspaper.Id == record.ProductId)));
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    return(InternalServerError(e));
                }
            }

            if (CurrentVisitor != null)
            {
                try
                {
                    VisitorOrder order = CurrentVisitor.VisitorOrders.LastOrDefault(ord => !ord.Completed);

                    if (order != null)
                    {
                        model.SumPrice = order.Sum;
                        model.OrderId  = order.Id;
                        foreach (VisitorOrderRecord record in order.VisitorOrderRecords)
                        {
                            if (record.ProductType == typeof(Book).Name)
                            {
                                model.BookProducts.Add(
                                    new BookModel(
                                        DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId)));
                            }
                            if (record.ProductType == typeof(Journal).Name)
                            {
                                model.JournalProducts.Add(
                                    new JournalModel(
                                        DataContext.Journals.FirstOrDefault(
                                            journal => journal.Id == record.ProductId)));
                            }
                            if (record.ProductType == typeof(Newspaper).Name)
                            {
                                model.NewspaperProducts.Add(
                                    new NewspaperModel(
                                        DataContext.Newspapers.FirstOrDefault(
                                            newspaper => newspaper.Id == record.ProductId)));
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    return(InternalServerError(e));
                }
            }
            return(Ok(model));
        }
コード例 #21
0
        public ActionResult Basket()
        {
            BasketModel model = new BasketModel();

            if (CurrentUser != null)
            {
                AccountOrder order = CurrentUser.AccountOrders.LastOrDefault(ord => !ord.Completed);

                if (order != null)
                {
                    model.SumPrice = order.Sum;
                    model.OrderId  = order.Id;
                    foreach (AccountOrderRecord record in order.AccountOrderRecords)
                    {
                        if (record.ProductType == typeof(Book).Name)
                        {
                            model.BookProducts.Add(
                                new BookModel(
                                    DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId)));
                        }
                        if (record.ProductType == typeof(Journal).Name)
                        {
                            model.JournalProducts.Add(
                                new JournalModel(
                                    DataContext.Journals.FirstOrDefault(
                                        journal => journal.Id == record.ProductId)));
                        }
                        if (record.ProductType == typeof(Newspaper).Name)
                        {
                            model.NewspaperProducts.Add(
                                new NewspaperModel(
                                    DataContext.Newspapers.FirstOrDefault(
                                        newspaper => newspaper.Id == record.ProductId)));
                        }
                    }
                }
            }


            if (CurrentVisitor != null)
            {
                VisitorOrder order = CurrentVisitor.VisitorOrders.LastOrDefault(ord => !ord.Completed);

                if (order != null)
                {
                    model.SumPrice = order.Sum;
                    model.OrderId  = order.Id;
                    foreach (VisitorOrderRecord record in order.VisitorOrderRecords)
                    {
                        if (record.ProductType == typeof(Book).Name)
                        {
                            model.BookProducts.Add(
                                new BookModel(
                                    DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId)));
                        }
                        if (record.ProductType == typeof(Journal).Name)
                        {
                            model.JournalProducts.Add(
                                new JournalModel(
                                    DataContext.Journals.FirstOrDefault(
                                        journal => journal.Id == record.ProductId)));
                        }
                        if (record.ProductType == typeof(Newspaper).Name)
                        {
                            model.NewspaperProducts.Add(
                                new NewspaperModel(
                                    DataContext.Newspapers.FirstOrDefault(
                                        newspaper => newspaper.Id == record.ProductId)));
                        }
                    }
                }
            }

            model.BreadcrumbModel   = new BreadcrumbModel(Url.Action("Basket", "Sell", null, Request.Url.Scheme));
            model.CurrentUser       = CurrentUser;
            model.CurrentNavSection = NavSection.Basket;
            return(View("Basket", model));
        }
コード例 #22
0
        public ActionResult AcceptSellOrder(int orderId)
        {
            if (CurrentUser != null)
            {
                AccountOrder order = DataContext.AccountOrders.FirstOrDefault(ord => ord.Id == orderId);
                if (order != null)
                {
                    foreach (AccountOrderRecord record in order.AccountOrderRecords)
                    {
                        if (record.ProductType == typeof(Book).Name)
                        {
                            DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId).Amount -=
                                record.Count;
                        }
                        if (record.ProductType == typeof(Journal).Name)
                        {
                            DataContext.Journals.FirstOrDefault(jor => jor.Id == record.ProductId).Amount -=
                                record.Count;
                        }
                        if (record.ProductType == typeof(Newspaper).Name)
                        {
                            DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId).Amount -= record.Count;
                        }
                    }

                    order.Completed = true;

                    DataContext.SubmitChanges();
                }
            }

            if (CurrentVisitor != null)
            {
                VisitorOrder order = DataContext.VisitorOrders.FirstOrDefault(ord => ord.Id == orderId);
                if (order != null)
                {
                    foreach (VisitorOrderRecord record in order.VisitorOrderRecords)
                    {
                        if (record.ProductType == typeof(Book).Name)
                        {
                            DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId).Amount -=
                                record.Count;
                        }
                        if (record.ProductType == typeof(Journal).Name)
                        {
                            DataContext.Journals.FirstOrDefault(jor => jor.Id == record.ProductId).Amount -=
                                record.Count;
                        }
                        if (record.ProductType == typeof(Newspaper).Name)
                        {
                            DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId).Amount -= record.Count;
                        }
                    }

                    order.Completed = true;

                    DataContext.SubmitChanges();
                }
            }

            return(RedirectToAction("Basket"));
        }
コード例 #23
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            ApproveIdRequest                     request          = null;
            ProductIdApproveRequest              productIdRequest = null;
            ApproveLoanProductOrderRequest       approveLoan      = null;
            ListDocIdRequest                     listRequest      = null;
            Dictionary <long, ApprovalOrderType> Types            = new Dictionary <long, ApprovalOrderType>();
            string sessionId = "";
            string otp       = "";
            byte   language  = 0;
            bool   isSigned  = false;
            string ipAddress = "";
            Dictionary <string, string> signData = null;
            SourceType sourceType = SourceType.NotSpecified;

            // հայտի մուտքագրման աղբյուրի ստացում Header-ից
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["SourceType"]))
            {
                Enum.TryParse(context.HttpContext.Request.Headers["SourceType"], out sourceType);
            }


            // Սեսիայի ստացում Header-ից
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["SessionId"]))
            {
                sessionId = context.HttpContext.Request.Headers["SessionId"];
            }


            // Լեզվի ստացում Header-ից
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["language"]))
            {
                byte.TryParse(context.HttpContext.Request.Headers["language"], out language);
            }

            // IP հասցեի ստացում
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["LocalIPAddress"]))
            {
                ipAddress = context.HttpContext.Request.Headers["LocalIPAddress"];
            }

            // Փոխանցված պարամետրի ստացում
            var argument = context.ActionArguments.Values.First();

            //Approve մեթոդների համար
            if (argument is ApproveIdRequest)
            {
                request = argument as ApproveIdRequest;
                Types.Add(request.Id, _type);
                otp = request.OTP;
            }
            //ApproveOrders մեթոդի համար
            else if (argument is ListDocIdRequest)
            {
                listRequest = argument as ListDocIdRequest;
                foreach (var item in listRequest.ListDocId)
                {
                    Types.Add(item, GetOrderType(_xbService.GetDocumentType(item)));
                }
                otp = listRequest.OTP;
            }
            else if (argument is ProductIdApproveRequest)
            {
                productIdRequest = argument as ProductIdApproveRequest;
                Types.Add((long)productIdRequest.ProductId, _type);
                otp = productIdRequest.OTP;
            }
            else if (argument is ApproveLoanProductOrderRequest)
            {
                approveLoan = argument as ApproveLoanProductOrderRequest;
                Types.Add(approveLoan.Id, _type);
                otp = approveLoan.OTP;
            }

            //Հայտի ստեղծում, քեշավորում, և Sign լինող պարամետրերի փոխանցում
            foreach (var x in Types)
            {
                switch (x.Value)
                {
                case ApprovalOrderType.PaymentOrder:
                {
                    PaymentOrder order = (PaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), order.ReceiverAccount.AccountNumber.ToString(),
                                      Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.PlasticCardOrder:
                {
                    PlasticCardOrder order = (PlasticCardOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPlasticCardOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.PlasticCard.Currency, ipAddress);
                }
                break;

                case ApprovalOrderType.UtilityPaymentOrder:
                {
                    UtilityPaymentOrder order = (UtilityPaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetUtilityPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.MatureOrder:
                {
                    MatureOrder order = (MatureOrder)_cacheHelper.SetApprovalOrder(_xbService.GetMatureOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.Account.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.ReferenceOrder:
                {
                    ReferenceOrder order = (ReferenceOrder)_cacheHelper.SetApprovalOrder(_xbService.GetReferenceOrder(x.Key));
                    if (order.FeeAccount != null)
                    {
                        CollectParameters(order.Id.ToString(), order.FeeAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                    else
                    {
                        CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                }
                break;

                case ApprovalOrderType.LoanProductOrder:
                {
                    LoanProductOrder order = null;
                    var type = _xbService.GetDocumentType((int)x.Key);
                    switch (type)
                    {
                    case OrderType.CreditSecureDeposit:
                        order = (LoanProductOrder)_cacheHelper.SetApprovalOrder(_xbService.GetLoanOrder(x.Key));
                        break;

                    default:
                        order = (LoanProductOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCreditLineOrder(x.Key));
                        break;
                    }
                    CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.ReceivedFastTransferPaymentOrder:
                {
                    ReceivedFastTransferPaymentOrder order = (ReceivedFastTransferPaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetReceivedFastTransferPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", order.ReceiverAccount.AccountNumber.ToString(), Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.AccountClosingOrder:
                {
                    AccountClosingOrder order = (AccountClosingOrder)_cacheHelper.SetApprovalOrder(_xbService.GetAccountClosingOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", "0", ipAddress);
                }
                break;

                case ApprovalOrderType.SwiftCopyOrder:
                {
                    SwiftCopyOrder order = (SwiftCopyOrder)_cacheHelper.SetApprovalOrder(_xbService.GetSwiftCopyOrder(x.Key));
                    if (order.FeeAccount != null)
                    {
                        CollectParameters(order.Id.ToString(), order.FeeAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                    else
                    {
                        CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                }
                break;

                case ApprovalOrderType.CredentialOrder:
                {
                    CredentialOrder order = (CredentialOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCredentialOrder(x.Key));
                    if (order.Fees != null && order.Fees[0] != null && order.Fees[0].Account != null)
                    {
                        CollectParameters(order.Id.ToString(), order.Fees[0].Account.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                    else
                    {
                        CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                }
                break;

                case ApprovalOrderType.DepositOrder:
                {
                    DepositOrder order = (DepositOrder)_cacheHelper.SetApprovalOrder(_xbService.GetDepositorder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.AccountOrder:
                {
                    AccountOrder order = (AccountOrder)_cacheHelper.SetApprovalOrder(_xbService.GetAccountOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.Currency, ipAddress);
                }
                break;

                case ApprovalOrderType.CashOrder:
                {
                    CashOrder order = (CashOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCashOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.CreditLineTerminationOrder:
                {
                    CreditLineTerminationOrder order = (CreditLineTerminationOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCreditLineTerminationOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.Currency, ipAddress);
                }
                break;

                case ApprovalOrderType.CardClosingOrder:
                {
                    CardClosingOrder order = (CardClosingOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCardClosingOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductId.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.CustomerDataOrder:
                {
                    CustomerDataOrder order = (CustomerDataOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCustomerDataOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.Password, ipAddress);
                }
                break;

                case ApprovalOrderType.StatmentByEmailOrder:
                {
                    StatmentByEmailOrder order = (StatmentByEmailOrder)_cacheHelper.SetApprovalOrder(_xbService.GetStatmentByEmailOrder(x.Key));
                }
                break;

                case ApprovalOrderType.DepositTerminationOrder:
                {
                    DepositTerminationOrder order = (DepositTerminationOrder)_cacheHelper.SetApprovalOrder(_xbService.GetDepositTerminationOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductId.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.ReestrTransferOrder:
                {
                    ReestrTransferOrder order = (ReestrTransferOrder)_cacheHelper.SetApprovalOrder(_xbService.GetReestrTransferOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.ArcaCardsTransactionOrder:
                {
                    ArcaCardsTransactionOrder order = (ArcaCardsTransactionOrder)_cacheHelper.SetApprovalOrder(_xbService.GetArcaCardsTransactionOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.CardNumber.Substring(0, 10), "0", "0", ipAddress);
                }
                break;

                case ApprovalOrderType.CardToCardOrder:
                {
                    CardToCardOrder order = (CardToCardOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCardToCardOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitCardNumber.Substring(0, 10), order.CreditCardNumber, Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.CardLimitChangeOrder:
                {
                    CardLimitChangeOrder order = (CardLimitChangeOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCardLimitChangeOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Limits[0].LimitValue).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.PeriodicPaymentOrder:
                {
                    PaymentOrder order = (PaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.InternationalPaymentOrder:
                {
                    InternationalPaymentOrder order = (InternationalPaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetInternationalPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), order.ReceiverAccount.AccountNumber.ToString(),
                                      Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.AccountReOpenOrder:
                {
                    AccountReOpenOrder order = (AccountReOpenOrder)_cacheHelper.SetApprovalOrder(_xbService.GetAccountReOpenOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", "0", ipAddress);
                }
                break;

                case ApprovalOrderType.PlasticCardSmsServiceOrder:
                {
                    PlasticCardSMSServiceOrder order = (PlasticCardSMSServiceOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPlasticCardSMSServiceOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductID.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.RemovalOrder:
                {
                    RemovalOrder order = context.ActionArguments.Values.First() as RemovalOrder;
                    CollectParameters("0", order.RemovingOrderId.ToString(), "0", "0", ipAddress);
                }
                break;

                case ApprovalOrderType.PeriodicTerminationOrder:
                {
                    PeriodicTerminationOrder order = (PeriodicTerminationOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPeriodicTerminationOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductId.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.PeriodicDataChangeOrder:
                {
                    PeriodicTransferDataChangeOrder order = (PeriodicTransferDataChangeOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPeriodicDataChangeOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductId.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.CardActivationOrder:
                {
                    CollectParameters(x.Key.ToString(), "0", "0", "0", ipAddress);
                }
                break;

                default:
                    break;
                }
            }
            ;

            //CheckSign Filter-ն անհրաժեշտ է աշխատի միայն sourceType-ը 5-ի՝ MobileBanking-ի դեպքում
            if (sourceType != SourceType.MobileBanking)
            {
                return;
            }
            else
            {
                signData = this.GenerateSignData(TransactionID, SenderAccount, RecepientAccount, Amount, IpAddress);
            }

            isSigned = _xbSecurityService.SingData(sessionId, otp, signData, language);

            //թեստային միջավայրի համար
            if ((sessionId == "ba0f312d-8487-445e-aee2-d5877ac1d4de" || otp == "0123456") && Convert.ToBoolean(_config["TestVersion"]))
            {
                return;
            }
            if (!isSigned)
            {
                Response response = new Response();
                response.ResultCode  = ResultCodes.validationError;
                response.Description = (Languages)language == Languages.hy ? "Սխալ PIN կոդ։" : "Incorrect PIN code.";
                context.Result       = ResponseExtensions.ToHttpResponse(response);
            }
        }