public async Task <IActionResult> GetPrenotazione([FromQuery] int id) { using (var context = new PrenotazioniDbContext()) { return(Ok(await context.Prenotazioni.FirstOrDefaultAsync(x => x.Id == id))); } }
public async Task <IActionResult> GetPrenotazione([FromQuery] string campo) { using (var context = new PrenotazioniDbContext()) { return(Ok(await context.Prenotazioni.FirstOrDefaultAsync(x => x.Campo == campo))); } }
public async Task <IActionResult> UpdatePrenotazione([FromBody] Prenotazione prenotazione) { using (var context = new PrenotazioniDbContext()) { context.Prenotazioni.Update(prenotazione); await context.SaveChangesAsync(); return(Ok()); } }
public async Task <IActionResult> CreateUtente([FromBody] Utente utente) { using (var context = new PrenotazioniDbContext()) { context.Utenti.Add(utente); await context.SaveChangesAsync(); return(Ok()); } }
static void Main(string[] args) { using (var context = new PrenotazioniDbContext()) { // Create database context.Database.EnsureCreated(); //inserisco dei campi manualmente Prenotazione s1 = new Prenotazione() { Email = "*****@*****.**", Time = "20:00", Date = "7/11/2017", Campo = "Calcio" }; Prenotazione s2 = new Prenotazione() { Email = "*****@*****.**", Time = "20:00", Date = "7/11/2017", Campo = "Tennis" }; context.Prenotazioni.Add(s1); context.Prenotazioni.Add(s2); context.SaveChanges(); Utente t1 = new Utente() { Surname = "Rossi", Name = "Mario", Email = "*****@*****.**", Password = "******", }; context.Utenti.Add(t1); context.SaveChanges(); } var host = new WebHostBuilder() .UseKestrel() .UseStartup <Startup>() .Build(); Task restService = host.RunAsync(); System.Diagnostics.Process.Start("cmd", "/C start http://localhost/netcoreapp2.0/corsoing/"); restService.Wait(); }
public async Task <IActionResult> DeletePrenotazione([FromQuery] int id) { using (var context = new PrenotazioniDbContext()) { var prenotazione = await context.Prenotazioni.FirstOrDefaultAsync(x => x.Id == id); context.Prenotazioni.Remove(prenotazione); await context.SaveChangesAsync(); return(Ok()); } }
public IActionResult SetupDatabase() { lock (setupLock) { using (var context = new PrenotazioniDbContext()) { // Create database context.Database.EnsureCreated(); } return(Ok("Database creato")); } }
public async Task <IActionResult> GetPrenotazioni() { try { await parallelism.WaitAsync(); using (var context = new PrenotazioniDbContext()) { return(Ok(context.Prenotazioni.ToList())); } } finally { parallelism.Release(); } }