private static CompetitionContext GetContextData() { if (_contextData == null) { _contextData = new CompetitionContext(); } return(_contextData); }
public static void EnsureSeedData(this CompetitionContext db) { if (!db.Competitions.Any()) { var competition = new Competition { Name = "Liga 2017/2018", Country = "Spain" }; db.Competitions.Add(competition); db.SaveChanges(); } }
public ActionResult Index() { using (var context = new CompetitionContext()) { var competitions = context.Competitions .Include(x => x.Games); var model = new HomeViewModel { Competitions = competitions.Select(c => new CompetitionViewModel { Id = c.Id, GameType = c.GameType, Name = c.Name, NumberOfGames = c.Games.Count }).ToList() }; return View(model); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CompetitionContext db) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); db.EnsureSeedData(); }
public BattleBitsGame CreateGame(Action<BattleBitsGame> onGameStart, Action<BattleBitsGame, IList<BattleBitsScore>> onGameEnd) { if (CurrentGame != null || NextGame != null) { throw new Exception("Please wait for the current game to end."); } var date = DateTime.UtcNow; var game = new BattleBitsGame(CompetitionMeta.NumberCount) { StartTime = date + GameDelay, EndTime = date + GameDelay + CompetitionMeta.Duration }; gameStartTimer = new Timer(state => { CurrentGame = game; NextGame = null; onGameStart(CurrentGame); gameStartTimer.Dispose(); gameStartTimer = null; }, null, game.StartTime - DateTime.UtcNow, Timeout.InfiniteTimeSpan); gameEndTimer = new Timer(state => { using (var context = new CompetitionContext()) { var competition = context.Competitions.FirstOrDefault(x => x.Id == CompetitionMeta.Id); if (competition != null) { competition.Games.Add(CreateGameModel(game)); context.SaveChanges(); } } onGameEnd(game, UpdateHighScores(game.Scores.Values)); gameEndTimer.Dispose(); gameEndTimer = null; PreviousGameScores = game.Scores.Values .OrderByDescending(s => s.Value) .ThenBy(s => s.Time).ToList(); CurrentGame = null; }, null, game.EndTime - DateTime.UtcNow, Timeout.InfiniteTimeSpan); NextGame = game; return game; }
public ActionResult Display(int id) { using (var context = new CompetitionContext()) { var competition = context.Competitions.Find(id); var model = new CompetitionRankingViewModel { Id = competition.Id, Name = competition.Name, Scores = context.Scores.Where(entry => entry.Game.Competition.Id == competition.Id).OrderByDescending(e => e.Value).ThenBy(e => e.Time).Take(50).ToList() }; // TODO remove when actual records are added model.Scores.Add(new Score { UserId = "mstaessen", Value = 29, Time = TimeSpan.FromSeconds(134) }); model.Scores.Add(new Score { UserId = "Samwise", Value = 23, Time = TimeSpan.FromSeconds(100) }); return View(model); } }
public BlockchainController(CompetitionContext context) { _context = context; }
public static void Main(string[] args) { Console.WriteLine(@"Initializing data context..."); CompetitionContext context; try { context = new CompetitionContext(); Console.WriteLine(@"Done"); } catch (Exception e) { Console.WriteLine(@"Error occured: " + e.Message); Console.ReadKey(); return; } Console.WriteLine("Available commands:"); Console.WriteLine("\timport - write new services to database"); Console.WriteLine("\tlist - get list of services in database"); Console.WriteLine("\tdelete [serviceId] - delete service from database"); while (true) { Console.Write(">>> "); var line = Console.ReadLine(); if (line == null) { return; } var lineData = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var command = lineData[0]; switch (command) { case "list": var services = (from service in context.Services select new[] { service.ServiceId, service.Description }).ToList(); Console.WriteLine($"Total entries: {services.Count}"); if (services.Count != 0) { Console.WriteLine("ServiceId\tDescription"); Console.WriteLine("------------------------"); foreach (var service in services) { Console.WriteLine($"{service[0]}\t{service[1]}"); } } break; case "delete": var serviceIdToDelete = lineData[1]; var serviceToDelete = (from service in context.Services where service.ServiceId == serviceIdToDelete select service).FirstOrDefault(); if (serviceToDelete != null) { Console.WriteLine($"Deleting service {serviceToDelete.ServiceId}"); context.Services.Remove(serviceToDelete); context.SaveChanges(); Console.WriteLine("Completed"); } else { Console.WriteLine($"Cannot find service with id {serviceIdToDelete}"); } break; case "import": Console.WriteLine("Enter services in folowing format: [serviceId] [description]"); Console.WriteLine("Write \"end\" to complete import and flush changes"); var newServices = new List <Service>(); while (true) { var newService = Console.ReadLine(); if (newService == null) { break; } if (newService == "end") { break; } var newServiceData = newService.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var description = newServiceData.Skip(1).Aggregate((a, b) => a + ' ' + b); newServices.Add( new Service { ServiceId = newServiceData[0], Description = description }); } Console.WriteLine($"Writing {newServices.Count} new entries..."); context.Services.AddRange(newServices); context.SaveChanges(); Console.WriteLine("Completed"); break; default: Console.WriteLine("Unknown command. Use one of the following:"); Console.WriteLine("Available commands:"); Console.WriteLine("\timport - write new services to database"); Console.WriteLine("\tlist - get list of services in database"); Console.WriteLine("\tdelete [serviceId] - delete service from database"); break; } } }
public ChallengesController(CompetitionContext context, IAmazonS3 s3Client, UserManager <IdentityUser> userManager) { _context = context; this.S3Client = s3Client; _userManager = userManager; }
public CompetitionUnitOfWork(string connectionString) { this.competitionContext = new CompetitionContext(connectionString); }
public ApiController() { _dbContext = new CompetitionContext(); }
public CompetitionsController(CompetitionContext context, UserManager <IdentityUser> userManager) { _context = context; _userManager = userManager; }
public CompetitionRepository(CompetitionContext db) { _db = db; }
public static void Main() { var context = new CompetitionContext(); context.Database.Initialize(true); }
public TeamsController(CompetitionContext context) { _context = context; }
public CompetitionsController(CompetitionContext context, IAmazonS3 s3Client) { _context = context; this.S3Client = s3Client; }
public PlayersController(CompetitionContext context) { _context = context; }
public CategoryDefaultsController(CompetitionContext context) { _context = context; }