Esempio n. 1
0
        public ThrowType SaveThrowType(ThrowType model)
        {
            model.ValidateModel();
            ThrowType result = null;

            using (var db = new CFLSuiteDB())
            {
                var dup = db.ThrowTypes.FirstOrDefault(x => x.Description == model.Description && x.ThrowTypeID != model.ThrowTypeID);
                if (dup == null)
                {
                    if (model.ThrowTypeID > 0)
                    {
                        db.ThrowTypes.Attach(model);
                        db.Entry(model).State = EntityState.Modified;
                    }
                    else
                    {
                        db.ThrowTypes.Add(model);
                    }
                }
                else
                {
                    throw new Exception("This throw already exists");
                }

                db.SaveChanges();
                result = model;
            }

            return(result);
        }
Esempio n. 2
0
        public BetGridModel SaveBetGridModel(BetGridModel model)
        {
            model.ValidateModel();
            BetGridModel result = null;

            using (var db = new CFLSuiteDB())
            {
                Bet dataModel = null;
                if (model.BetID > 0)
                {
                    dataModel             = db.Bets.First(x => x.BetID == model.BetID);
                    dataModel.BetStarted  = model.BetStarted;
                    dataModel.Description = model.Description;
                }
                else
                {
                    dataModel = new Bet
                    {
                        BetStarted  = model.BetStarted.ToUniversalTime(),
                        Description = model.Description
                    };
                    db.Bets.Add(dataModel);
                }
                db.SaveChanges();
                result = db.Bets.Where(x => x.BetID == dataModel.BetID).ToBetGridModel().First();
            }

            return(result);
        }
Esempio n. 3
0
        public Throw SaveThrow(Throw model)
        {
            model.ValidateModel();
            Throw result = null;

            using (var db = new CFLSuiteDB())
            {
                if (model.ThrowID > 0)
                {
                    db.Throws.Attach(model);
                    db.Entry(model).State = EntityState.Modified;
                }
                else
                {
                    db.Throws.Add(model);
                }
                db.SaveChanges();
                result = db.Throws
                         .Include(x => x.ThrowType)
                         .Include(x => x.Bets)
                         .Include(x => x.Participant.Player)
                         .First(x => x.ThrowID == model.ThrowID);
            }

            return(result);
        }
Esempio n. 4
0
        public PrizeModel SavePrizeModel(PrizeModel model)
        {
            model.ValidateModel();
            PrizeModel result    = null;
            Prize      dataModel = null;

            using (var db = new CFLSuiteDB())
            {
                if (model.PrizeID > 0)
                {
                    dataModel = db.Prizes.First(x => x.PrizeID == model.PrizeID);
                    dataModel.LosingParticipantID  = model.LosingParticipantID;
                    dataModel.WinningParticipantID = model.WinningParticipantID;
                    dataModel.PrizeDescription     = model.PrizeDescription;
                }
                else
                {
                    dataModel = new Prize
                    {
                        LosingParticipantID  = model.LosingParticipantID,
                        WinningParticipantID = model.WinningParticipantID,
                        PrizeDescription     = model.PrizeDescription
                    };
                    db.Prizes.Add(dataModel);
                }
                db.SaveChanges();
                result = db.Prizes.Where(x => x.PrizeID == dataModel.PrizeID).ToPrizeModel().First();
            }

            return(result);
        }
Esempio n. 5
0
        public Player SavePlayer(Player model)
        {
            model.ValidateModel();
            Player result = null;

            using (var db = new CFLSuiteDB())
            {
                var dup = db.Players.FirstOrDefault(x => x.Name == model.Name && x.PlayerID != model.PlayerID);
                if (dup == null)
                {
                    if (model.PlayerID < 0)
                    {
                        db.Players.Attach(model);
                        db.Entry(model).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Players.Add(model);
                    }
                }
                else
                {
                    throw new Exception("That player already exists.");
                }
                db.SaveChanges();
                result = model;
            }
            return(result);
        }
Esempio n. 6
0
        public List <Bet> GetAllAssociatedBets(CFLSuiteDB db, int betID)
        {
            var parentBet = db.Bets.GetTopParentBet(betID);
            var result    = GetAllChildBets(db, parentBet.BetID).ToList();

            result.Add(parentBet);
            result.AddRange(GetAllChildBets(db, parentBet.BetID));
            return(result);
        }
Esempio n. 7
0
        public List <Player> GetBetParticipantPlayers(int betID)
        {
            var result = new List <Player>();

            using (var db = new CFLSuiteDB())
            {
                result = db.Players.Where(x => x.Participants.Any(y => y.BetID == betID)).ToList();
            }
            return(result);
        }
Esempio n. 8
0
        public ParticipantModel GetParticipantModel(int partcipantID)
        {
            ParticipantModel result = null;

            using (var db = new CFLSuiteDB())
            {
                result = db.Participants.Where(x => x.ParticipantID == partcipantID).ToParticipantModels().First();
            }
            return(result);
        }
Esempio n. 9
0
        public Bet GetBet(int betID)
        {
            Bet result = null;

            using (var db = new CFLSuiteDB())
            {
                result = db.Bets.First(x => x.BetID == betID);
            }

            return(result);
        }
Esempio n. 10
0
        public Participant GetParticipant(int participantID)
        {
            Participant result = null;

            using (var db = new CFLSuiteDB())
            {
                result = db.Participants.Include(x => x.Player).First(x => x.ParticipantID == participantID);
            }

            return(result);
        }
Esempio n. 11
0
        public ThrowModel GetThrowModel(int throwID)
        {
            ThrowModel result = null;

            using (var db = new CFLSuiteDB())
            {
                result = db.Throws.Where(x => x.ThrowID == throwID).ToThrowModels().First();
            }

            return(result);
        }
Esempio n. 12
0
        public List <ParticipantModel> GetBetParticipantModels(int betID)
        {
            var result = new List <ParticipantModel>();

            using (var db = new CFLSuiteDB())
            {
                result = db.Participants.Where(x => x.BetID == betID).ToParticipantModels().ToList();
            }

            return(result);
        }
Esempio n. 13
0
        public List <PrizeModel> GetPrizeModelsByLosingParticipant(int losingParticipantID)
        {
            var result = new List <PrizeModel>();

            using (var db = new CFLSuiteDB())
            {
                result = db.Prizes.Where(x => x.LosingParticipantID == losingParticipantID).ToPrizeModel().ToList();
            }

            return(result);
        }
Esempio n. 14
0
        public Bet GetBetByParticipant(int participantID)
        {
            Bet result = null;

            using (var db = new CFLSuiteDB())
            {
                result = db.Bets.First(x => x.Participants.Any(y => y.ParticipantID == participantID));
            }

            return(result);
        }
Esempio n. 15
0
        public List <ThrowType> GetThrowTypes()
        {
            var result = new List <ThrowType>();

            using (var db = new CFLSuiteDB())
            {
                result = db.ThrowTypes.ToList();
            }

            return(result);
        }
Esempio n. 16
0
        public List <Player> GetPlayers()
        {
            var result = new List <Player>();

            using (var db = new CFLSuiteDB())
            {
                result = db.Players.ToList();
            }

            return(result);
        }
Esempio n. 17
0
        public ThrowModel DeleteThrowModel(ThrowModel model)
        {
            var result = model;

            using (var db = new CFLSuiteDB())
            {
                var existing = db.Throws.First(x => x.ThrowID == model.ThrowID);
                db.Throws.Remove(existing);
                db.SaveChanges();
            }
            return(result);
        }
Esempio n. 18
0
        public List <Bet> GetAllChildBets(CFLSuiteDB db, int betID)
        {
            var result = new List <Bet>();
            var bets   = db.Bets.Where(x => x.ParentBetID == betID).ToList();

            result.AddRange(bets);
            foreach (var bet in bets)
            {
                result.AddRange(GetAllChildBets(db, bet.BetID));
            }
            return(result);
        }
Esempio n. 19
0
        public List <ThrowModel> GetThrowModels(int participantID)
        {
            var result = new List <ThrowModel>();

            using (var db = new CFLSuiteDB())
            {
                result = db.Throws.Where(x => x.ParticipantID == participantID)
                         .ToThrowModels().ToList();
            }

            return(result);
        }
Esempio n. 20
0
        public List <BetGridModel> GetBetGridModels()
        {
            var result = new List <BetGridModel>();

            using (var db = new CFLSuiteDB())
            {
                result = db.Bets.Where(x => x.ParentBetID == null)
                         .OrderByDescending(x => x.BetStarted)
                         .ToBetGridModel().ToList();
            }
            return(result);
        }
Esempio n. 21
0
        public RedemptionModel SaveRedemptionModel(RedemptionModel model)
        {
            model.ValidateModel();
            RedemptionModel result    = null;
            Bet             dataModel = null;

            using (var db = new CFLSuiteDB())
            {
                if (model.BetID > 0)
                {
                    dataModel             = db.Bets.First(x => x.BetID == model.BetID);
                    dataModel.BetStarted  = model.BetStarted;
                    dataModel.Description = model.Description;
                    dataModel.ThrowID     = model.ThrowID;
                    dataModel.ParentBetID = model.ParentBetID;
                    var participant = db.Participants.FirstOrDefault(x => x.BetID == model.BetID && x.PlayerID == model.PlayerID);
                    if (participant == null)
                    {
                        participant = new Participant
                        {
                            PlayerID = model.PlayerID,
                            Winner   = false,
                        };

                        dataModel.Participants.Add(participant);
                    }
                }
                else
                {
                    dataModel = new Bet
                    {
                        BetStarted   = model.BetStarted,
                        Description  = model.Description,
                        ThrowID      = model.ThrowID,
                        ParentBetID  = model.ParentBetID,
                        Participants = new List <Participant>()
                        {
                            new Participant
                            {
                                PlayerID = model.PlayerID,
                                Winner   = false
                            }
                        }
                    };

                    db.Bets.Add(dataModel);
                }
                db.SaveChanges();
                result = db.Bets.Where(x => x.BetID == dataModel.BetID).ToRedemptionModel().First();
            }

            return(result);
        }
Esempio n. 22
0
        public RedemptionModel DeleteRedemptionModel(RedemptionModel model)
        {
            var result = model;

            using (var db = new CFLSuiteDB())
            {
                var existing = db.Bets.First(x => x.BetID == model.BetID);
                db.Bets.Remove(existing);
            }

            return(result);
        }
Esempio n. 23
0
        public Bet AddNewBetWithNewParticipants(Bet bet)
        {
            Bet result = null;

            using (var db = new CFLSuiteDB())
            {
                db.Bets.Add(bet);
                db.SaveChanges();
                result = bet;
            }
            return(result);
        }
Esempio n. 24
0
        public List <RedeemedThrowModel> GetRedeemedThrowModels(int playerID, int betID)
        {
            var result = new List <RedeemedThrowModel>();

            using (var db = new CFLSuiteDB())
            {
                result = db.Throws.Where(x => x.Participant.BetID == betID && x.Participant.PlayerID == playerID)
                         .ToRedeemedThrowModels().ToList();
            }

            return(result);
        }
Esempio n. 25
0
        public List <Player> GetAllPlayersForRedemption(int betID)
        {
            var result = new List <Player>();

            using (var db = new CFLSuiteDB())
            {
                var betIDs = GetAllAssociatedBets(db, betID).Select(x => x.BetID);

                result = db.Players.Where(x => x.Participants.Any(y => betIDs.Contains(y.BetID))).ToList();
            }

            return(result);
        }
Esempio n. 26
0
        public PrizeModel DeletePrizeModel(PrizeModel model)
        {
            var result = model;

            using (var db = new CFLSuiteDB())
            {
                var existing = db.Prizes.First(x => x.PrizeID == model.PrizeID);
                db.Prizes.Remove(existing);
                db.SaveChanges();
            }

            return(result);
        }
Esempio n. 27
0
        public List <PlayerPrizeModel> GetPlayerPrizeModels(int betID, int playerID)
        {
            var result = new List <PlayerPrizeModel>();

            using (var db = new CFLSuiteDB())
            {
                var betIDs = GetAllAssociatedBets(db, betID).Select(x => x.BetID);

                result = db.Prizes.Where(x => x.LosingParticipant.PlayerID == playerID && betIDs.Contains(x.LosingParticipant.BetID)).ToPlayerPrizeModel().ToList();
            }

            return(result);
        }
Esempio n. 28
0
        public List <RedemptionModel> GetBetsByParentBet(int betID)
        {
            var result = new List <RedemptionModel>();

            using (var db = new CFLSuiteDB())
            {
                var topParentBet = db.Bets.GetTopParentBet(betID);
                var betIDs       = GetAllChildBets(db, topParentBet.BetID).Select(x => x.BetID);
                result = db.Bets.Where(x => betIDs.Contains(x.BetID))
                         .OrderByDescending(x => x.BetStarted)
                         .ToRedemptionModel().ToList();
            }

            return(result);
        }
Esempio n. 29
0
        public ParticipantModel SaveParticipantModel(ParticipantModel model)
        {
            model.ValidateModel();
            ParticipantModel result = null;

            using (var db = new CFLSuiteDB())
            {
                Participant dataModel = null;
                var         dup       = db.Participants.FirstOrDefault(x => x.PlayerID == model.PlayerID &&
                                                                       x.BetID == model.BetID &&
                                                                       x.ParticipantID != model.ParticipantID);

                if (dup == null)
                {
                    if (model.ParticipantID > 0)
                    {
                        dataModel          = db.Participants.First(x => x.ParticipantID == model.ParticipantID);
                        dataModel.Winner   = model.Winner;
                        dataModel.PlayerID = model.PlayerID;
                    }
                    else
                    {
                        dataModel = new Participant()
                        {
                            BetID    = model.BetID,
                            PlayerID = model.PlayerID,
                            Winner   = model.Winner
                        };
                        db.Participants.Add(dataModel);
                    }
                    db.SaveChanges();
                    result =
                        db.Participants.Where(x => x.ParticipantID == dataModel.ParticipantID)
                        .ToParticipantModels().First();
                }
                else
                {
                    throw new Exception("That participant already exists for this bet.");
                }
            }
            return(result);
        }
Esempio n. 30
0
        public ParticipantModel DeleteParticipantModel(ParticipantModel model)
        {
            var result = model;

            using (var db = new CFLSuiteDB())
            {
                var existing = db.Participants.First(x => x.ParticipantID == model.ParticipantID);
                var throws   = db.Throws.Any(x => x.ParticipantID == existing.ParticipantID);
                var prizes   = db.Prizes.Any(x => x.LosingParticipantID == existing.ParticipantID || x.WinningParticipantID == existing.ParticipantID);

                if (throws || prizes)
                {
                    throw new Exception("Cannot delete this participant because they either have throws or payouts associated with them.");
                }

                db.Participants.Remove(existing);
                db.SaveChanges();
            }
            return(result);
        }