private void CreateDb() { // Cria o banco de dados e as tabelas using var db = new XamExEFContext(); // Verifica se o banco de dados foi criado db.Database.EnsureCreated(); }
public async Task <bool> AddItemAsync(Item item) { using var context = new XamExEFContext(); await context.Items.AddAsync(item); return((await context.SaveChangesAsync()) > 0); }
public MockDataStore() { using var context = new XamExEFContext(); if (context.Items.Any() == false) { context.Items.Add(new Item { Id = Guid.NewGuid().ToString(), Text = "First item", Description = "This is an item description." }); context.Items.Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Second item", Description = "This is an item description." }); context.Items.Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Third item", Description = "This is an item description." }); context.Items.Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Fourth item", Description = "This is an item description." }); context.Items.Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Fifth item", Description = "This is an item description." }); context.Items.Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Sixth item", Description = "This is an item description." }); context.SaveChanges(); } }
public async Task <bool> DeleteItemAsync(string id) { using var context = new XamExEFContext(); var item = context.Items.Where((Item arg) => arg.Id == id).FirstOrDefault(); context.Items.Remove(item); return((await context.SaveChangesAsync()) > 0); }
public Task <List <Item> > GetItemsAsync() { using var context = new XamExEFContext(); return(context.Items.ToListAsync()); }
public Task <Item> GetItemAsync(string id) { using var context = new XamExEFContext(); return(context.Items.FirstOrDefaultAsync(s => s.Id == id)); }