public static void SaveThumb(int gameId, string imageUrl, string contentType) { lock (Lock) { using (var ctx = new DIHMTEntities()) { var existingThumb = ctx.ThumbImages.FirstOrDefault(x => x.GameId == gameId); if (existingThumb == null) { ctx.ThumbImages.Add(new ThumbImage { GameId = gameId, ImageUrl = imageUrl, ContentType = contentType, LastUpdated = DateTime.UtcNow }); ctx.SaveChanges(); } else { existingThumb.ImageUrl = imageUrl; existingThumb.ContentType = contentType; existingThumb.LastUpdated = DateTime.UtcNow; ctx.Entry(existingThumb).State = EntityState.Modified; ctx.SaveChanges(); } } } }
public static void SaveGame(DbGame input) { lock (Lock) { using (var ctx = new DIHMTEntities()) { var existingRecord = ctx.DbGames.FirstOrDefault(x => x.Id == input.Id); if (existingRecord != null) { ctx.Entry(existingRecord).CurrentValues.SetValues(input); ctx.Entry(existingRecord).State = EntityState.Modified; } else { ctx.DbGames.Add(input); } ctx.SaveChanges(); } } }