public JsonResult GetData(int sellCurrencyID, int buyCurrencyID)
        {
            try
            {
                var entityID = SessionHelper.CurrentEntity.EntityID;

                var history = monetaryTransactionRepository
                              .Where(t => t.BuyerCurrencyID == buyCurrencyID && t.SellerCurrencyID == sellCurrencyID && (t.Day == GameHelper.CurrentDay || t.Day == (GameHelper.CurrentDay - 1)))
                              .OrderBy(t => t.ID)
                              .Select(t => new
                {
                    Time  = t.Date,
                    Day   = t.Day,
                    Value = t.Rate
                })
                              .ToList()
                              .Select(t => new
                {
                    Time  = t.Time.ToString("HH:mm"),
                    Day   = t.Day,
                    Value = t.Value
                });

                var bestOffer = monetaryOfferRepository.GetActualBuySellOffer(sellCurrencyID, buyCurrencyID);

                var myOffers = monetaryOfferRepository.Where(b => b.SellerID == entityID && b.BuyCurrencyID == buyCurrencyID && b.SellCurrencyID == sellCurrencyID)
                               .OrderBy(o => o.Rate)
                               .Select(o =>
                                       new
                {
                    ID     = o.ID,
                    Amount = o.Amount,
                    Rate   = o.Rate,
                    Type   = o.OfferTypeID
                })
                               .ToList();

                return(Json(new
                {
                    Plot = history,
                    Best = bestOffer,
                    My = myOffers,
                    SellSymbol = Persistent.Currencies.GetById(sellCurrencyID).Symbol,
                    BuySymbol = Persistent.Currencies.GetById(buyCurrencyID).Symbol
                }));
            }
            catch (Exception e)
            {
                return(JsonDebugOnlyError(e));
            }
        }
        private void tryToBuySell(MonetaryOffer offer)
        {
            var entity = entityRepository.GetById(offer.SellerID);

            MonetaryTransaction lastTransaction = null;

            if (offer.OfferTypeID == (int)MonetaryOfferTypeEnum.Buy)
            {
                var suitableSellOffers = monetaryOfferRepository.
                                         Where(o => o.Rate <= offer.Rate &&
                                               o.OfferTypeID == (int)MonetaryOfferTypeEnum.Sell &&
                                               o.SellCurrencyID == offer.SellCurrencyID &&
                                               o.BuyCurrencyID == offer.BuyCurrencyID
                                               );

                if (suitableSellOffers.Any())
                {
                    var offers = suitableSellOffers.OrderBy(o => o.Rate).ToList();
                    foreach (var sellOffer in offers)
                    {
                        int boughtAmount = makeTransaction(offer, entity, sellOffer);

                        MonetaryTransaction transaction = new MonetaryTransaction()
                        {
                            Date             = DateTime.Now,
                            Day              = GameHelper.CurrentDay,
                            Amount           = boughtAmount,
                            Rate             = sellOffer.Rate,
                            BuyerCurrencyID  = offer.BuyCurrencyID,
                            SellerCurrencyID = offer.SellCurrencyID,
                            SellerID         = sellOffer.SellerID,
                            BuyerID          = offer.SellerID,
                            SellerTax        = 0,
                            BuyerTax         = 0
                        };

                        lastTransaction = transaction;


                        if (sellOffer.Amount == 0)
                        {
                            RemoveOffer(sellOffer, ref transaction);
                        }
                        else
                        {
                            transaction.MonetaryOffers.Add(sellOffer);
                        }

                        if (offer.Amount == 0)
                        {
                            RemoveOffer(offer, ref transaction);
                            monetaryTransactionRepository.Add(transaction);
                            offer = null;
                            break;
                        }
                        monetaryTransactionRepository.Add(transaction);
                    }
                }
            }
            else
            {
                var suitableSellOffers = monetaryOfferRepository.
                                         Where(o => o.Rate >= offer.Rate &&
                                               o.OfferTypeID == (int)MonetaryOfferTypeEnum.Buy &&
                                               o.SellCurrencyID == offer.SellCurrencyID &&
                                               o.BuyCurrencyID == offer.BuyCurrencyID
                                               );

                if (suitableSellOffers.Any())
                {
                    var offers = suitableSellOffers.OrderBy(o => o.Rate).ToList();
                    foreach (var buyOffer in offers)
                    {
                        int boughtAmount = makeTransaction(buyOffer, buyOffer.Entity, offer);

                        MonetaryTransaction transaction = new MonetaryTransaction()
                        {
                            Date             = DateTime.Now,
                            Day              = GameHelper.CurrentDay,
                            Amount           = boughtAmount,
                            BuyerID          = buyOffer.SellerID,
                            Rate             = offer.Rate,
                            BuyerCurrencyID  = offer.BuyCurrencyID,
                            SellerCurrencyID = offer.SellCurrencyID,
                            SellerID         = offer.SellerID,
                            SellerTax        = 0,
                            BuyerTax         = 0
                        };

                        lastTransaction = transaction;

                        if (buyOffer.Amount == 0)
                        {
                            RemoveOffer(buyOffer, ref transaction);
                        }
                        else
                        {
                            transaction.MonetaryOffers.Add(buyOffer);
                        }

                        if (offer.Amount == 0)
                        {
                            RemoveOffer(offer, ref transaction);
                            monetaryTransactionRepository.Add(transaction);
                            offer = null;
                            break;
                        }

                        monetaryTransactionRepository.Add(transaction);
                    }
                }
            }

            if (offer != null)
            {
                offer.LastTransaction = lastTransaction;
            }
        }