public static void SaveResult(int tournamentId, int golferId, int place, decimal winnings, bool isCut, bool isTied, bool isWithdrawn, bool isDisqualified, bool isPlayoff) { using (var db = new FantasyGolfContext()) { var query = from x in db.TournamentResult where x.TournamentId == tournamentId && x.GolferId == golferId select x; var result = query.FirstOrDefault(); if (result == null) { result = new TournamentResult(); db.TournamentResult.Add(result); } else { db.Entry(result).State = System.Data.Entity.EntityState.Modified; } result.TournamentId = tournamentId; result.GolferId = golferId; result.Place = place; result.Winnings = winnings; result.IsCut = isCut; result.IsTied = isTied; result.IsWithdrawn = isWithdrawn; result.IsDisqualified = isDisqualified; result.IsPlayoff = isPlayoff; db.SaveChanges(); } }
public static void Save(string firstName, string lastName, int tourId) { //TODO: need to handle spelling updates by passing in ID # using (var db = new FantasyGolfContext()) { var query = from x in db.Golfer where x.FirstName == firstName && x.LastName == lastName && x.TourId == tourId select x; var golfer = query.FirstOrDefault(); if (golfer == null) { golfer = new Golfer(); db.Golfer.Add(golfer); } else { db.Entry(golfer).State = System.Data.Entity.EntityState.Modified; } golfer.FirstName = firstName; golfer.LastName = lastName; golfer.TourId = tourId; golfer.CreatedOn = DateTime.Now; golfer.LastSyncedOn = null; golfer.IsActive = true; db.SaveChanges(); var cache = new CacheService(); cache.Remove("fg.golfers"); } }
public static League SaveResult(int id, string name, int tourId, int season) { League result = null; using (var db = new FantasyGolfContext()) { if (id > 0) { var query = from x in db.League where x.Id == id select x; var temp = query.FirstOrDefault(); if (temp == null) { result = new League(); db.League.Add(result); } else { result = temp; db.Entry(result).State = System.Data.Entity.EntityState.Modified; } } else { result = new League(); db.League.Add(result); } result.Name = name; result.TourId = tourId; result.Season = season; result.ManagerId = 1; result.PlayoffFormatId = 1; result.RegularSeasonFormatId = 1; result.BeginsOn = null; result.EndsOn = null; result.IsActive = true; result.CreatedOn = DateTime.Now; db.SaveChanges(); } return(result); }
public static void Save(int userId, int tournamentId, int golferId) { using (var db = new FantasyGolfContext()) { var query = from up in db.UserPick where up.UserId == userId && up.TournamentId == tournamentId select up; var pick = query.FirstOrDefault(); if (pick == null) { pick = new UserPick(); db.UserPick.Add(pick); } else { db.Entry(pick).State = System.Data.Entity.EntityState.Modified; } pick.UserId = userId; pick.TournamentId = tournamentId; pick.GolferId = golferId; pick.CreatedOn = DateTime.Now; var pickChange = new UserPickChangeLog { UserId = userId, TournamentId = tournamentId, GolferId = golferId, CreatedOn = DateTime.Now }; db.UserPickChangeLog.Add(pickChange); db.SaveChanges(); } }