示例#1
0
 public Gum GetGum(int id)
 {
     using (var dbContext = new PieShopContext())
     {
         return(dbContext.Gums.Find(id));
     }
 }
示例#2
0
 public List <Gum> GetAllGums()
 {
     using (var dbContext = new PieShopContext())
     {
         return(dbContext.Gums.ToList());
     }
 }
示例#3
0
 public async Task <Pie> GetPieAsync(int id)
 {
     using (var dbContext = new PieShopContext())
     {
         return(await dbContext.Pies.FindAsync(id));
     }
 }
示例#4
0
 public async Task <List <Pie> > GetAllPiesAsync()
 {
     using (var dbContext = new PieShopContext())
     {
         return(await dbContext.Pies.ToListAsync());
     }
 }
示例#5
0
        public void SaveGum(Gum gum)
        {
            using (var dbContext = new PieShopContext())
            {
                if (gum.Id == 0)
                {
                    dbContext.Gums.Add(gum);
                }
                else
                {
                    dbContext.Gums.Update(gum);
                }

                dbContext.SaveChanges();
            }
        }
示例#6
0
        //private void AddDummyData()
        //{
        //    _pies = new List<Pie>
        //    {
        //        new Pie
        //        {
        //            Id = 1,
        //            IsInStock = true,
        //            ImageUrl = "strawberrypiesmall.jpg",
        //            Name = "Strawberry Pie",
        //            Price = 15.95,
        //            Description =
        //                "Icing carrot cake jelly-o cheesecake. Sweet roll marzipan marshmallow toffee brownie brownie candy tootsie roll. Chocolate cake gingerbread tootsie roll oat cake pie chocolate bar cookie dragée brownie. Lollipop cotton candy cake bear claw oat cake. Dragée candy canes dessert tart. Marzipan dragée gummies lollipop jujubes chocolate bar candy canes. Icing gingerbread chupa chups cotton candy cookie sweet icing bonbon gummies. Gummies lollipop brownie biscuit danish chocolate cake. Danish powder cookie macaroon chocolate donut tart. Carrot cake dragée croissant lemon drops liquorice lemon drops cookie lollipop toffee. Carrot cake carrot cake liquorice sugar plum topping bonbon pie muffin jujubes. Jelly pastry wafer tart caramels bear claw. Tiramisu tart pie cake danish lemon drops. Brownie cupcake dragée gummies."
        //        },
        //        new Pie
        //        {
        //            Id = 2,
        //            IsInStock = true,
        //            ImageUrl = "cheesecakesmall.jpg",
        //            Name = "Cheese cake",
        //            Price = 18.95,
        //            Description =
        //                "Icing carrot cake jelly-o cheesecake. Sweet roll marzipan marshmallow toffee brownie brownie candy tootsie roll. Chocolate cake gingerbread tootsie roll oat cake pie chocolate bar cookie dragée brownie. Lollipop cotton candy cake bear claw oat cake. Dragée candy canes dessert tart. Marzipan dragée gummies lollipop jujubes chocolate bar candy canes. Icing gingerbread chupa chups cotton candy cookie sweet icing bonbon gummies. Gummies lollipop brownie biscuit danish chocolate cake. Danish powder cookie macaroon chocolate donut tart. Carrot cake dragée croissant lemon drops liquorice lemon drops cookie lollipop toffee. Carrot cake carrot cake liquorice sugar plum topping bonbon pie muffin jujubes. Jelly pastry wafer tart caramels bear claw. Tiramisu tart pie cake danish lemon drops. Brownie cupcake dragée gummies."
        //        },
        //        new Pie
        //        {
        //            Id = 3,
        //            IsInStock = true,
        //            ImageUrl = "rhubarbpiesmall.jpg",
        //            Name = "Rhubarb Pie",
        //            Price = 15.95,
        //            Description =
        //                "Icing carrot cake jelly-o cheesecake. Sweet roll marzipan marshmallow toffee brownie brownie candy tootsie roll. Chocolate cake gingerbread tootsie roll oat cake pie chocolate bar cookie dragée brownie. Lollipop cotton candy cake bear claw oat cake. Dragée candy canes dessert tart. Marzipan dragée gummies lollipop jujubes chocolate bar candy canes. Icing gingerbread chupa chups cotton candy cookie sweet icing bonbon gummies. Gummies lollipop brownie biscuit danish chocolate cake. Danish powder cookie macaroon chocolate donut tart. Carrot cake dragée croissant lemon drops liquorice lemon drops cookie lollipop toffee. Carrot cake carrot cake liquorice sugar plum topping bonbon pie muffin jujubes. Jelly pastry wafer tart caramels bear claw. Tiramisu tart pie cake danish lemon drops. Brownie cupcake dragée gummies."
        //        },
        //        new Pie
        //        {
        //            Id = 4,
        //            IsInStock = true,
        //            ImageUrl = "pumpkinpiesmall.jpg",
        //            Name = "Pumpkin Pie",
        //            Price = 12.95,
        //            Description =
        //                "Icing carrot cake jelly-o cheesecake. Sweet roll marzipan marshmallow toffee brownie brownie candy tootsie roll. Chocolate cake gingerbread tootsie roll oat cake pie chocolate bar cookie dragée brownie. Lollipop cotton candy cake bear claw oat cake. Dragée candy canes dessert tart. Marzipan dragée gummies lollipop jujubes chocolate bar candy canes. Icing gingerbread chupa chups cotton candy cookie sweet icing bonbon gummies. Gummies lollipop brownie biscuit danish chocolate cake. Danish powder cookie macaroon chocolate donut tart. Carrot cake dragée croissant lemon drops liquorice lemon drops cookie lollipop toffee. Carrot cake carrot cake liquorice sugar plum topping bonbon pie muffin jujubes. Jelly pastry wafer tart caramels bear claw. Tiramisu tart pie cake danish lemon drops. Brownie cupcake dragée gummies."
        //        }
        //    };
        //}

        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);
                }

                await dbContext.SaveChangesAsync();
            }
        }