Example #1
0
        private static void AddingNewProductType()
        {
            using (var dbContext = new CoffeeShopDbContext())
            {
                dbContext.Database.Log = Console.WriteLine;
                var productType = new ProductType()
                {
                    Description = "Who Knocks"
                };

                dbContext.ProductTypes.Add(productType);
                dbContext.SaveChanges();
            }
        }
Example #2
0
        private static void UpdateProduct()
        {
            using (var dbContext = new CoffeeShopDbContext())
            {
                dbContext.Database.Log = Console.WriteLine;
                var productListBeforeUpdate = dbContext.Products.ToList();
                DisplayProductList(productListBeforeUpdate);
                var modifiedProduct = dbContext.Products
                                      .SingleOrDefault(p => p.Description == "Medium Coffee");
                if (modifiedProduct == null)
                {
                    return;
                }

                modifiedProduct.FullPrice += 1.20m;
                dbContext.SaveChanges();
                var productListAfterUpdate = dbContext.Products.ToList();
                Console.WriteLine("==================================");
                DisplayProductList(productListAfterUpdate);
            }
        }
Example #3
0
        private static void DeleteProductType()
        {
            using (var dbContext = new CoffeeShopDbContext())
            {
                dbContext.Database.Log = Console.WriteLine;
                var productTypeListBeforeDelete = dbContext.ProductTypes.ToList();
                DisplayProductTypeList(productTypeListBeforeDelete);
                var deleteProductType = dbContext.ProductTypes
                                        .SingleOrDefault(p => p.Description == "Who Knocks");

                if (deleteProductType == null)
                {
                    return;
                }

                dbContext.ProductTypes.Remove(deleteProductType);
                dbContext.SaveChanges();
                var productTypeListAfterDelete = dbContext.ProductTypes.ToList();
                DisplayProductTypeList(productTypeListAfterDelete);
            }
        }