Beispiel #1
0
        private static void SeedStore(SalesContext db)
        {
            db.Stores.Add(new Store()
            {
                Name = "Magazina na bay ganio"
            });
            db.Stores.Add(new Store()
            {
                Name = "24h e-mag"
            });

            db.SaveChanges();
        }
Beispiel #2
0
        private static void SeedDatabase()
        {
            using (var context = new SalesContext())
            {
                SeedProducts(context);
                SeedCustomers(context);
                SeedStore(context);
                context.SaveChanges();

                SeedSales(context);
                context.SaveChanges();
            }
        }
Beispiel #3
0
        private static void SeedCustomer(SalesContext db)
        {
            db.Customers.Add(new Customer()
            {
                Name = "Ivancheto", Email = "*****@*****.**", CreditCardNumber = "423142873181331"
            });
            db.Customers.Add(new Customer()
            {
                Name = "Todor", Email = "*****@*****.**", CreditCardNumber = "121401393190310"
            });

            db.SaveChanges();
        }
        public static void Main(string[] args)
        {
            using (var db = new SalesContext())
            {
                var store = new Store
                {
                    Name = "Magazin"
                };

                db.Stores.Add(store);

                db.SaveChanges();
            }
        }
        public static void Seeder(SalesContext context)
        {
            Store store = new Store();

            store.Name = "Kaufland";
            context.Stores.Add(store);

            Product product = new Product();

            product.Name     = "Krastavica";
            product.Price    = 7.50m;
            product.Quantity = 10;

            Product product2 = new Product();

            product2.Name     = "Domat";
            product2.Price    = 8.50m;
            product2.Quantity = 1;

            Product product3 = new Product();

            product3.Name     = "Zele";
            product3.Price    = 2.50m;
            product3.Quantity = 2;

            context.Products.Add(product);
            context.Products.Add(product2);
            context.Products.Add(product3);


            Customer customer = new Customer();

            customer.Name  = "Gosho";
            customer.Email = "Email";
            context.Customers.Add(customer);

            Sale sale = new Sale();

            sale.CustomerId = 0;
            sale.ProductId  = 1;
            sale.StoreId    = 2;
            //sale.Customer = customer;
            //sale.Product = product3;
            //sale.Store = store;

            context.Sales.Add(sale);

            context.SaveChanges();
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            using (var db = new SalesContext())
            {
                var productsToAdd = GetProductsToSeed();

                db.Products.AddRange(productsToAdd);

                var storesToAdd = GetStoresToSeed();

                db.Stores.AddRange(storesToAdd);

                db.SaveChanges();
            }
        }
Beispiel #7
0
        public static void Main(string[] args)
        {
            var context = new SalesContext();

            context.Database.Migrate();

            //var product = new Product()
            //{
            //    Name = "Koza",
            //    Quantity = 10,
            //    Price = 100,
            //    Description = "Shtastlivi balkanski kozi",
            //};

            //var customer = new Customer()
            //{
            //    Name = "Svetlin",
            //    Email = "*****@*****.**",
            //    CreditCardNumber = "2648997200",
            //};

            //var store = new Store()
            //{
            //    Name = "Gipo.OOD",
            //};

            var sale = new Sale()
            {
                Product = new Product()
                {
                    Name        = "Rimsko Pravo",
                    Quantity    = 1,
                    Price       = 25,
                    Description = "Uchebnik po Rimsko pravo",
                },
                Customer = new Customer()
                {
                    Name             = "Donika",
                    Email            = "*****@*****.**",
                    CreditCardNumber = "2543547200",
                },
                StoreId = 1,
            };

            //context.Sales.Add(sale);

            context.SaveChanges();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            var context = new SalesContext();
            var random  = new Random();
            var writer  = new ConsoleWriter();

            var seeders = new List <ISeeder>();

            seeders.Add(new ProductSeeder(context, random, writer));
            seeders.Add(new StoreSeeder(context, writer));

            foreach (var seeder in seeders)
            {
                seeder.Seed();
            }
        }
Beispiel #9
0
        public static string AddStore(SalesContext context)
        {
            Console.WriteLine("Store name:");
            string name = Console.ReadLine();

            Store store = new Store()
            {
                Name = name
            };

            context.Stores.Add(store);

            context.SaveChanges();

            return("Added store with name: " + name);
        }
Beispiel #10
0
        private static void SeedProduct(SalesContext db)
        {
            db.Prodcuts.Add(new Product()
            {
                Name = "Kola", Quantity = 5, Price = 1.2M
            });
            db.Prodcuts.Add(new Product()
            {
                Name = "Vafla borec", Quantity = 10, Price = 0.5M
            });
            db.Prodcuts.Add(new Product()
            {
                Name = "Qica ot chafka", Quantity = 30, Price = 5.0M
            });

            db.SaveChanges();
        }
Beispiel #11
0
        static ServiceProvider Main(string[] args)
        {
            SalesContext salesContext = new SalesContext();

            using (salesContext)
            {
                //..
            }

            ServiceCollection services = new ServiceCollection();

            // services.AddSingleton();

            ServiceProvider sp = services.BuildServiceProvider();

            return(sp);
        }
Beispiel #12
0
        public static void Main()
        {
            using (var db = new SalesContext())
            {
                try
                {
                    db.Database.Migrate();

                    Console.WriteLine("Database successfully created/updated!");

                    //SeedDB(db);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Beispiel #13
0
        public static string ReadStore(SalesContext context, string name)
        {
            var store = context
                        .Stores
                        .Select(s => new { Name = s.Name })
                        .Where(s => s.Name == name)
                        .FirstOrDefault();

            if (store == null)
            {
                return("There is no such store in the database");
            }

            else
            {
                return($"Store with name: {store.Name}");
            }
        }
Beispiel #14
0
        public static string DeleteSale(SalesContext context, int id)
        {
            var sale = context
                       .Sales
                       .Where(s => s.SaleId == id)
                       .FirstOrDefault();

            if (sale == null)
            {
                return("No sale with Id: " + id);
            }

            context.Sales.Remove(sale);

            context.SaveChanges();

            return($"Sale with id: {id} removed successfully");
        }
Beispiel #15
0
        private static void Seed(SalesContext db)
        {
            var products = new[]
            {
                new Product("Apples", 7.4, 2.40m),
                new Product("Pears", 6.0, 3.10m),
                new Product("Grapes", 250, 1.95m),
                new Product("Kiwi", 0.8, 3.5m),
            };

            db.Products.AddRange(products);

            var customers = new[]
            {
                new Customer("Iva", "*****@*****.**", "545056485015120"),
                new Customer("Gergana", "*****@*****.**", "545056485015120"),
                new Customer("Rositsa", "*****@*****.**", "545056485015120"),
                new Customer("Valya", "*****@*****.**", "545056485015120"),
            };

            db.Customers.AddRange(customers);

            var stores = new[]
            {
                new Store("CBA"),
                new Store("Piccadilly"),
                new Store("Kaufland"),
                new Store("Metro"),
            };

            db.Stores.AddRange(stores);

            var sales = new[]
            {
                new Sale(products[0], customers[0], stores[0]),
                new Sale(products[1], customers[1], stores[1]),
                new Sale(products[2], customers[2], stores[2]),
                new Sale(products[3], customers[3], stores[3]),
            };

            db.Sales.AddRange(sales);

            db.SaveChanges();
        }
Beispiel #16
0
        private static int FindCustomerId(SalesContext context, string name)
        {
            int result = -1;

            var customer = context
                           .Customers
                           .Select(c => new
            {
                Id   = c.CustomerId,
                Name = c.Name
            })
                           .Where(c => c.Name == name)
                           .FirstOrDefault();

            if (customer != null)
            {
                result = customer.Id;
            }
            return(result);
        }
Beispiel #17
0
        public static string DeleteStore(SalesContext context, string name)
        {
            int storeId = FindStoreId(context, name);

            if (storeId == -1)
            {
                return("No store with name " + name);
            }

            var store = context
                        .Stores
                        .Where(s => s.StoreId == storeId)
                        .First();

            context.Stores.Remove(store);

            context.SaveChanges();

            return($"Store {name} removed successfully");
        }
Beispiel #18
0
        public static void Main(string[] args)
        {
            using (SalesContext context = new SalesContext())
            {
                // context.Database.EnsureCreated();
                int[] arr = new int[] { 1, 2, 3, 4, 4, 2, 1 };

                int  lastElement  = arr.Length - 1;
                bool isTelescopic = true;
                for (int i = 0; i <= arr.Length / 2; i++)
                {
                    if (arr[i] != arr[lastElement - i])
                    {
                        isTelescopic = false;
                        break;
                    }
                }
                Console.WriteLine(isTelescopic);
            }
        }
Beispiel #19
0
        //Delete methods

        public static string DeleteCustomer(SalesContext context, string name)
        {
            int customerId = FindCustomerId(context, name);

            if (customerId == -1)
            {
                return("No customer with name: " + name);
            }

            var customer = context
                           .Customers
                           .Where(c => c.CustomerId == customerId)
                           .First();

            context.Customers.Remove(customer);

            context.SaveChanges();

            return($"Customer {name} removed successfully");
        }
Beispiel #20
0
        //Read methods
        public static string ReadCustomer(SalesContext context, string name)
        {
            var customer = context
                           .Customers
                           .Select(c => new
            {
                CustomerId       = c.CustomerId,
                Name             = c.Name,
                Email            = c.Email,
                CreditCardNumber = c.CreditCardNumber
            })
                           .FirstOrDefault(c => c.Name == name);

            if (customer == null)
            {
                return("There is no customer with that name");
            }

            return($"Customer: {customer.Name} with email: {customer.Email} amd credit card number: {customer.CreditCardNumber}");
        }
Beispiel #21
0
        public static string AddProduct(SalesContext context)
        {
            //name
            Console.WriteLine("Product name:");
            string productName = Console.ReadLine();

            //quantiti
            Console.WriteLine("Product Quantiti");
            double quantity = double.Parse(Console.ReadLine());

            //price
            Console.WriteLine("Price:");
            decimal price = decimal.Parse(Console.ReadLine());

            //description
            Console.WriteLine("Description?");
            Console.WriteLine("y/n");
            char   yorn        = char.Parse(Console.ReadLine());
            string description = string.Empty;

            if (char.ToLower(yorn) == 'y')
            {
                Console.WriteLine("Add description here:");
                description = Console.ReadLine();
            }

            var product = new Product()
            {
                Name        = productName,
                Quantity    = quantity,
                Price       = price,
                Description = description
            };

            context.Products.Add(product);

            context.SaveChanges();


            return($"Added product {productName} with quantity {quantity} and cost {price}");
        }
Beispiel #22
0
        private static int FindStoreId(SalesContext context, string name)
        {
            int result = -1;

            var store = context
                        .Stores
                        .Select(s => new
            {
                Id   = s.StoreId,
                Name = s.Name
            })
                        .Where(s => s.Name == name)
                        .FirstOrDefault();

            if (store != null)
            {
                result = store.Id;
            }

            return(result);
        }
Beispiel #23
0
        public static string ReadProduct(SalesContext context, string name)
        {
            var product = context
                          .Products
                          .Select(p => new
            {
                Name        = p.Name,
                Quantity    = p.Quantity,
                Price       = p.Price,
                Description = p.Description
            })
                          .Where(p => p.Name == name)
                          .FirstOrDefault();

            if (product == null)
            {
                return("There is no such product in the database");
            }

            return($"Product {product.Name} with price {product.Price} and quantity {product.Quantity} Description: {product.Description}");
        }
Beispiel #24
0
        private static void SeedSale(SalesContext db)
        {
            db.Sales.Add(new Sale()
            {
                ProductId = 1, CustomerId = 1, StoreId = 1
            });
            db.Sales.Add(new Sale()
            {
                ProductId = 1, CustomerId = 1, StoreId = 2
            });
            db.Sales.Add(new Sale()
            {
                ProductId = 2, CustomerId = 2, StoreId = 1
            });
            db.Sales.Add(new Sale()
            {
                ProductId = 3, CustomerId = 2, StoreId = 1
            });

            db.SaveChanges();
        }
Beispiel #25
0
        private static int FindProductId(SalesContext context, string name)
        {
            int result = -1;

            var productId = context
                            .Products
                            .Select(p => new
            {
                Id   = p.ProductId,
                Name = p.Name
            })
                            .Where(p => p.Name == name)
                            .FirstOrDefault();

            if (productId != null)
            {
                result = productId.Id;
            }

            return(result);
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            var rand = new Random();



            var context = new SalesContext();

            //context.Database.EnsureDeleted();
            //context.Database.EnsureCreated();



            for (int i = 50; i < 60; i++)
            {
                var sale = new Sale
                {
                    Product = new Product()
                    {
                        Name     = "Sharo" + i,
                        Quantity = 5,
                        Price    = 20,
                    },
                    Customer = new Customer()
                    {
                        Name             = "Pesho" + i,
                        Email            = "*****@*****.**" + i,
                        CreditCardNumber = new String(Convert.ToChar(rand.Next(0, 10).ToString()), 10)
                    },
                    Store = new Store()
                    {
                        Name = "Billa" + i
                    }
                };

                context.Sales.Add(sale);
            }

            context.SaveChanges();
        }
        private static void Seed(SalesContext context)
        {
            var customers = new[]
            {
                new Customer("Ivan", "*****@*****.**", "2685H8NSQLX"),
                new Customer("Petyr", "*****@*****.**", "829HOTYP89"),
                new Customer("Maria", "*****@*****.**", "HETAB6QW816")
            };

            context.Customers.AddRange(customers);

            var products = new[]
            {
                new Product("Apple", 12.476, 1.60m),
                new Product("Orange", 17.267, 2.70m),
                new Product("Banana", 10.682, 1.80m, "Bananas are fairly nutritious, and contain high amounts of fiber and antioxidants.")
            };

            context.Products.AddRange(products);

            var stores = new[]
            {
                new Store("Mandarin"),
                new Store("Fresh"),
                new Store("Plodchetata")
            };

            context.Stores.AddRange(stores);

            var sales = new[]
            {
                new Sale(DateTime.Parse("10.10.2017"), products[0].ProductId, customers[2].CustomerId, stores[1].StoreId),
                new Sale(products[1].ProductId, customers[0].CustomerId, stores[2].StoreId),
                new Sale(DateTime.Parse("09.04.2017"), products[2].ProductId, customers[1].CustomerId, stores[0].StoreId)
            };

            context.Sales.AddRange(sales);

            context.SaveChanges();
        }
Beispiel #28
0
        public static string ReadSale(SalesContext context, string name)
        {
            var sale = context
                       .Sales
                       .Select(s => new
            {
                SaleDate        = s.Date,
                SaledProduct    = s.Product.Name,
                SaledToCustomer = s.Customer.Name,
                StoreName       = s.Store.Name
            })
                       .Where(s => s.SaledProduct == name)
                       .FirstOrDefault();

            if (sale == null)
            {
                return("There is no such store in the database");
            }

            return($"  Selled product: {sale.SaledProduct} on date {sale.SaleDate}" +
                   $"In Store: {sale.StoreName} to customer {sale.SaledToCustomer}");
        }
Beispiel #29
0
        public static string DeleteProduct(SalesContext context, string name)
        {
            int productId = FindProductId(context, name);

            if (productId == -1)
            {
                return($"No product with name {name}");
            }

            var product = context
                          .Products
                          .Where(p => p.ProductId == productId)
                          .First();

            context
            .Products.Remove(product);

            context
            .SaveChanges();

            return("Successfully removed product: " + name);
        }
        private static void Seed(SalesContext context)
        {
            Customer customer = new Customer
            {
                Name             = "Stoqn Dimitrov",
                CreditCardNumber = "11aa-2211",
                Email            = "*****@*****.**"
            };

            context.Customers.Add(customer);

            Product product = new Product
            {
                Name        = "Table",
                Price       = 124.99m,
                Description = "Great wooden table",
                Quantity    = 2
            };

            context.Products.Add(product);

            Store store = new Store
            {
                Name = "IKEA"
            };

            context.Stores.Add(store);

            Sale sale = new Sale
            {
                Product  = product,
                Store    = store,
                Customer = customer
            };

            context.Sales.Add(sale);

            context.SaveChanges();
        }