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