public IHttpActionResult CloseSweepstake()
        {
            try
            {
                List <string> sweepstakeEntries = new List <string>();
                var           everything        = this.sweepStakeEntryRepository.GetAll();
                if (everything.Count == 0)
                {
                    SweepStake sweepstakeClosed = sweepStakeRepository.GetSingle(x => x.UsernameWinner == "No Winner" & x.ClosedDateTime >= DateTime.Now);
                    var        wins             = "Closed By Admin";
                    sweepstakeClosed.UsernameWinner = wins;
                    sweepStakeRepository.Update(sweepstakeClosed);
                    return(Ok("No Winner"));
                }
                else
                {
                    var sweepstake = db.SweepStakes
                                     .Where(x => x.UsernameWinner == "No Winner" & x.ClosedDateTime >= DateTime.Now)
                                     .FirstOrDefault <SweepStake>();
                    foreach (var entry in everything)
                    {
                        var entries = (entry.Cost / sweepstake.Price);
                        for (int i = 0; i < entries; i++)
                        {
                            sweepstakeEntries.Add(entry.Account.UserName);
                        }
                    }
                    // ALL THE TICKET ENTRIES ARE PUT IN A LIST AND RANDOMLY ONE WINNER CHOSEN
                    Random rnd        = new Random();
                    int    r          = rnd.Next(sweepstakeEntries.Count);
                    var    winner     = (string)sweepstakeEntries[r];
                    var    nameWinner = sweepStakeEntryRepository.GetSingle(x => x.UserName == winner);
                    // GOT THE USERNMAE WHO WON
                    SweepStake sweep = sweepStakeRepository.GetSingle(x => x.UsernameWinner == "No Winner" & x.ClosedDateTime >= DateTime.Now);

                    var wins = nameWinner.UserName;
                    sweep.UsernameWinner = wins;
                    sweepStakeRepository.Update(sweep);
                    var deleteEntries = db.SweepStakeEntries.ToList();

                    // DELETING ALL ENTRIES IN A SWEEPSTAKE ENTRY TABLE

                    foreach (var del in deleteEntries)
                    {
                        db.SweepStakeEntries.Remove(del);
                    }
                    ;
                    db.SaveChanges();
                    return(Ok(wins));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Source + "\n" + e.Message + "\n" + e.InnerException + "\n" + e.StackTrace));
            }
        }
 public IHttpActionResult SubmitSweepstake(SweepstakeAdminDTO sweepstakeSet)
 {
     if (sweepstakeSet.OpenDateTime <= DateTime.Now & sweepstakeSet.ClosedDateTime >= DateTime.Now)
     {
         SweepStake sweep = new SweepStake()
         {
             SweepStakesID  = sweepstakeSet.SweepStakesID,
             OpenDateTime   = sweepstakeSet.OpenDateTime,
             ClosedDateTime = sweepstakeSet.ClosedDateTime,
             Prize          = sweepstakeSet.Prize,
             UsernameWinner = sweepstakeSet.UsernameWinner,
             Price          = sweepstakeSet.Price,
         };
         sweepStakeRepository.Insert(sweep);
         return(Ok("Post Sweepstake by Admin"));
     }
     else
     {
         return(Ok("Wrong Sweepstakes Dates"));
     }
 }