コード例 #1
0
 public async Task <Pie> GetPieAsync(int id)
 {
     using (var dbContext = new PieshopContext())
     {
         return(await dbContext.Pies.FindAsync(id));
     }
 }
コード例 #2
0
 public async Task <T> FindItemAsync(int id)
 {
     using (var dbContext = new PieshopContext())
     {
         return(await dbContext.FindAsync <T>(id));
     }
 }
コード例 #3
0
 public async Task <List <Pie> > GetAllPiesAsync()
 {
     using (var dbContext = new PieshopContext())
     {
         return(await dbContext.Pies.ToListAsync());
     }
 }
コード例 #4
0
 public async Task <Coffee> GetCoffeeAsync(int id)
 {
     using (var dbContext = new PieshopContext())
     {
         return(await dbContext.Coffees.FindAsync());
     }
 }
コード例 #5
0
        public async Task AddCoffeeAsync(Coffee coffee)
        {
            using (var dbContext = new PieshopContext())
            {
                if (coffee.ID == 0)
                {
                    await dbContext.Coffees.AddAsync(coffee);
                }
                else
                {
                    dbContext.Coffees.Update(coffee);
                }

                await dbContext.SaveChangesAsync();
            }
        }
コード例 #6
0
        public async Task AddItem(T product)
        {
            using (var dbContext = new PieshopContext())
            {
                if (product.ID == 0)
                {
                    await dbContext.AddAsync(product);
                }
                else
                {
                    dbContext.Update(product);
                }

                // Don't forget to save changes after operating.
                await dbContext.SaveChangesAsync();
            }
        }
コード例 #7
0
        public async Task SavePieAsync(Pie pie)
        {
            using (var dbContext = new PieshopContext())
            {
                if (pie.ID == 0)
                {
                    await dbContext.Pies.AddAsync(pie);
                }
                else
                {
                    dbContext.Pies.Update(pie);
                }

                // Don't forget to save changes after operating.
                await dbContext.SaveChangesAsync();
            }
        }