Ejemplo n.º 1
0
        public IActionResult AddNewGame(PricePredictionIndexViewModel viewModel)
        {
            var user        = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser");
            var currentUser = _sysUserService.Queryable().FirstOrDefault(x => x.Id == user.Id && x.IsAdmin == true);

            if (currentUser != null)
            {
                // Update database

                // Add quartz job
                // Cmt out because of new PricePrediction logic
                //var scheduler = _quartzSchedulerService.GetScheduler<IScheduler, IPricePredictionUpdateResultFactory>();
                //QuartzHelper.AddJob<PricePredictionUpdateResultJob>(scheduler, viewModel.PredictionResultTime);

                return(new EmptyResult());
            }
            else
            {
                return(new JsonResult(new { success = false, message = "You don't have permission to do this action" }));
            }
        }
Ejemplo n.º 2
0
        public IActionResult Index(bool?predictedTrend)
        {
            //Test quartz job price prediction update result
            // Cmt out because of new PricePrediction logic
            //var scheduler = _quartzSchedulerService.GetScheduler<IScheduler, IPricePredictionUpdateResultFactory>();
            //QuartzHelper.AddJob<PricePredictionUpdateResultJob>(scheduler, new DateTime(2018, 07, 30, 12, 56, 0));

            var viewModel = new PricePredictionIndexViewModel();

            viewModel.SysUserId = HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser")?.Id;
            if (viewModel.SysUserId.HasValue)
            {
                viewModel.TokenAmount = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id).TokenAmount;
            }

            var adminPricePredictionTabs = _pricePredictionService.Queryable()
                                           .Where(x => x.ResultTime.Date == DateTime.Now.Date && x.PricePredictionCategoryId != (int)EnumPricePredictionCategory.SYSTEM)
                                           .Select(x => new PricePredictionTab
            {
                Id               = x.Id,
                ResultTime       = x.ResultTime,
                ToBeComparedTime = x.ToBeComparedTime,
                CloseBettingTime = x.CloseBettingTime,
                IsDisabled       = (x.OpenBettingTime > DateTime.Now || x.CloseBettingTime < DateTime.Now),
                Title            = x.PricePredictionDetails.FirstOrDefault(y => y.LangId == HttpContext.Session.GetInt32("LangId").Value).Title,
                CoinBase         = x.Coinbase
            });

            var systemPricePredictionTabs = _pricePredictionService.Queryable()
                                            .Where(x => x.ResultTime > DateTime.Now && x.PricePredictionCategoryId == (int)EnumPricePredictionCategory.SYSTEM)
                                            .Select(x => new PricePredictionTab
            {
                Id               = x.Id,
                ResultTime       = x.ResultTime,
                ToBeComparedTime = x.ToBeComparedTime,
                CloseBettingTime = x.CloseBettingTime,
                IsDisabled       = (x.CloseBettingTime < DateTime.Now),
                Title            = x.PricePredictionDetails.FirstOrDefault(y => y.LangId == HttpContext.Session.GetInt32("LangId").Value).Title,
                CoinBase         = x.Coinbase
            });


            viewModel.PricePredictionTabs = adminPricePredictionTabs.Concat(systemPricePredictionTabs)
                                            .OrderBy(x => x.ResultTime.ToString("HH:mm"))
                                            .ToList();

            // Move first tab to the end of the array
            viewModel.PricePredictionTabs = Enumerable.Range(1, viewModel.PricePredictionTabs.Count).Select(i => viewModel.PricePredictionTabs[i % viewModel.PricePredictionTabs.Count]).ToList();

            var pricePredictionActiveTab = viewModel.PricePredictionTabs.FirstOrDefault(x => x.CloseBettingTime >= DateTime.Now);

            if (predictedTrend.HasValue)
            {
                if (viewModel.PricePredictionTabs.OrderBy(x => x.CloseBettingTime).FirstOrDefault(x => x.CloseBettingTime >= DateTime.Now) != null)
                {
                    viewModel.PricePredictionTabs.OrderBy(x => x.CloseBettingTime).FirstOrDefault(x => x.CloseBettingTime >= DateTime.Now).IsActive       = true;
                    viewModel.PricePredictionTabs.OrderBy(x => x.CloseBettingTime).FirstOrDefault(x => x.CloseBettingTime >= DateTime.Now).PredictedTrend = predictedTrend;
                }
            }
            else
            {
                if (pricePredictionActiveTab != null)
                {
                    viewModel.PricePredictionTabs.FirstOrDefault(x => x.CloseBettingTime >= DateTime.Now).IsActive       = true;
                    viewModel.PricePredictionTabs.FirstOrDefault(x => x.CloseBettingTime >= DateTime.Now).PredictedTrend = predictedTrend;
                }
            }

            return(View(viewModel));
        }