public async Task <IActionResult> GetUser([FromBody] Datilogin dati) { try { await parallelism.WaitAsync(); using (var context = new GameLibraryDbContext()) { var userlogin = context.Users.Where(p => p.Username == dati.Username && p.Password == dati.Password).ToList(); if (userlogin.Count == 0) { return(NotFound()); } return(Ok(userlogin)); } } catch (Exception e) { Console.WriteLine(e.Message); return(NotFound()); } finally { parallelism.Release(); } }
public static void Main(string[] args) { using (var context = new GameLibraryDbContext()) { context.Database.EnsureCreated(); } BuildWebHost(args).Run(); }
public async Task <IActionResult> GetGame([FromQuery] int id) { await parallelism.WaitAsync(); using (var context = new GameLibraryDbContext()) { return(Ok(context.Games.Where(p => p.Id == id).ToList())); } }
public async Task <IActionResult> UpdateUser([FromBody] User user) { using (var context = new GameLibraryDbContext()) { context.Users.Update(user); await context.SaveChangesAsync(); return(Ok()); } }
public async Task <IActionResult> UpdateGame([FromBody] Game game) { using (var context = new GameLibraryDbContext()) { context.Games.Update(game); await context.SaveChangesAsync(); return(Ok()); } }
public async Task <IActionResult> DeleteUser([FromQuery] int id) { using (var context = new GameLibraryDbContext()) { var user = await context.Users.FirstOrDefaultAsync(x => x.Id == id); context.Users.Remove(user); await context.SaveChangesAsync(); return(Ok()); } }
public async Task <IActionResult> GetUsers() { try { await parallelism.WaitAsync(); using (var context = new GameLibraryDbContext()) { return(Ok(context.Users.ToList())); } } finally { parallelism.Release(); } }
public async Task <IActionResult> GetGameOfUser([FromQuery] int id) { try { await parallelism.WaitAsync(); using (var context = new GameLibraryDbContext()) { return(Ok(context.Games.Where(p => p.Userid == id).ToList())); } } finally { parallelism.Release(); } }