Ejemplo n.º 1
0
        public async Task chooseQuaterlyWinner(object obj)
        {
            var qdaydiff = DateTime.Now.NextQuater(18, 0, 0, 0) - DateTime.Now;

            //var qdaydiff = DateTime.Now.NextFiveMinutes() - DateTime.Now;

            //Drawing Takes a maximum of two minutes
            if (qdaydiff.TotalMinutes >= 0 && qdaydiff.TotalMinutes <= 1)
            {
                if ((int)Math.Floor(qdaydiff.TotalSeconds) < 1)
                {
                    //stop ongoingQuaterlyDraw
                    //Get current scholarship winner Id
                    var winnerIds = await ChooseWinnerAsync("quaterly", EntityTypes.Scholarship);

                    //Get the winning scholarship object
                    var selectedScholarships = context.Scholarships.Where(i => winnerIds.Contains(i.Id));


                    //Put a dummy Scholarship Stake
                    DummyService.FixScholarshipDummy();

                    if (selectedScholarships?.Count() > 0)
                    {
                        //send the selected scholarship to the UI
                        await WinnerSelectionHub.Clients.All.SendAsync("scholarshipWinner", selectedScholarships.Select(i => new ScholarshipParticipantDTO
                        {
                            Id           = i.Id,
                            UserName     = i.User.FirstName + " " + i.User.LastName,
                            UserId       = i.UserId,
                            AmountStaked = i.Amount.ToString("0.##"),
                            AmountToWin  = i.AmountToWin.ToString("0.##"),
                            Status       = i.Status,
                            DateDeclared = i.DateDeclared
                        }));

                        //clear all current participants
                        await StakersHub.Clients.All.SendAsync("getCurrentScholarshipParticipants", DataHub.GetScholarshipParticipants());
                    }
                    else
                    {
                        //send a blank winner
                        await WinnerSelectionHub.Clients.All.SendAsync("scholarshipWinner", new List <ScholarshipParticipantDTO>(){ new ScholarshipParticipantDTO
                                                                                                                                    {
                                                                                                                                        UserName     = "******",
                                                                                                                                        UserId       = "",
                                                                                                                                        AmountStaked = "",
                                                                                                                                        AmountToWin  = ""
                                                                                                                                    } });
                    }



                    await WinnerSelectionHub.Clients.All.SendAsync("ongoingQuaterlyDraw", false);

                    await WinnerSelectionHub.Clients.All.SendAsync("ongoingQuaterlyDraw", false);
                }
                else if ((int)Math.Floor(qdaydiff.TotalSeconds) > 1)
                {
                    await WinnerSelectionHub.Clients.All.SendAsync("ongoingQuaterlyDraw", true);
                }
            }
            else
            {
                //Make sure the countdown does not run to negatives
                if (qdaydiff.TotalSeconds >= 0)
                {
                    //subtract the 1minutes draw time from the countdown time
                    await CountdownHub.Clients.All.SendAsync("getQuaterlyTime", qdaydiff.Days, qdaydiff.Hours, qdaydiff.Add(TimeSpan.FromMinutes(-1)).Minutes, qdaydiff.Seconds);
                }
            }
        }