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); }
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); }
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); }
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); }
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); }
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); }
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); }
public Bet AddNewBetWithNewParticipants(Bet bet) { Bet result = null; using (var db = new CFLSuiteDB()) { db.Bets.Add(bet); db.SaveChanges(); result = bet; } return(result); }
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); }
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); }
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); }