public Product DeleteProducts(int productID)
        {
            Product dbentry = context.Products.FirstOrDefault(x => x.ProductID == productID);

            if (dbentry != null)
            {
                context.Products.Remove(dbentry);
                context.SaveChanges();
            }
            return(dbentry);
        }
Пример #2
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            ApplicationDataBaseContext context = app.ApplicationServices
                                                 .GetRequiredService <ApplicationDataBaseContext>();



            if (!context.Products.Any())
            {
                context.Products.AddRange(
                    new Product
                {
                    Name        = "Kayak",
                    Price       = 32.23M,
                    Description = "A boat fot one person.",
                    Category    = "Water sport."
                },
                    new Product
                {
                    Name        = "Boxing glowes",
                    Price       = 23.42M,
                    Description = "Glowes from natural skin.",
                    Category    = "Boxing."
                },
                    new Product
                {
                    Name        = "Lifejucket",
                    Price       = 21.32M,
                    Description = "Protective and fashionable.",
                    Category    = "Water sport."
                },
                    new Product
                {
                    Name        = "Soccet ball",
                    Price       = 10.21M,
                    Description = "FIFA=approved size and weight.",
                    Category    = "Football."
                }
                    );
                context.SaveChanges();
            }
        }
Пример #3
0
 public void DeleteOrder(int productId)
 {
     context.Orders.RemoveRange(Orders.Where(x => x.Lines.OrderBy(y => y.Product.ProductID == productId).Count() != 0));
     context.SaveChanges();
 }