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); }