コード例 #1
0
        public async Task <ApiResultModel <List <TransactionDTO> > > GetTransactions(Guid userId)
        {
            try
            {
                IEnumerable <Transaction> data = await _transactionServices.GetByUserIdAsync(userId);

                var pairs = await _pairServices.GetPairsAsync();

                var markets = await _transactionServices.GetMarkets();

                List <TransactionDTO> returnData = new List <TransactionDTO>();
                foreach (Transaction transaction in data)
                {
                    var _coin   = pairs.FirstOrDefault(x => x.Id == transaction.Coin);
                    var _market = markets.FirstOrDefault(x => x.Id == transaction.Market);
                    if (_coin == null || _market == null)
                    {
                        continue;
                    }

                    returnData.Add(new TransactionDTO()
                    {
                        Id          = transaction.Id,
                        BuyingPrice = transaction.BuyingPrice,
                        SellPrice   = transaction.SellPrice,
                        IsSold      = transaction.IsSold,
                        Unit        = transaction.Unit,
                        Coin        = _coin,
                        CoinId      = _coin.Id,
                        Market      = _market,
                        MarketId    = _market.Id,
                        UserId      = transaction.UserId,
                        Status      = transaction.Status,
                        CreateDt    = transaction.CreateDt
                    });
                }

                return(new ApiResultModel <List <TransactionDTO> >()
                {
                    Data = returnData,
                    Success = true,
                    Message = "Success",
                    Code = 200
                });
            }
            catch (Exception ex)
            {
                return(new ApiResultModel <List <TransactionDTO> >()
                {
                    Data = new List <TransactionDTO>(),
                    Success = false,
                    Message = ex.Message,
                    Code = ex.HResult
                });
            }
        }
コード例 #2
0
        public async Task <IActionResult> Get()
        {
            try
            {
                IEnumerable <Transaction> data = await _transactionServices.GetByUserIdAsync(User.GetLoggedInUserId <Guid>());

                ViewBag.Pairs = await _pairServices.GetPairsAsync();

                ViewBag.Markets = await _transactionServices.GetMarkets();

                return(View(data));
            }
            catch (System.Exception ex)
            {
                return(View(ex));
            }
        }