コード例 #1
0
ファイル: Program.cs プロジェクト: lusinekh/ADO.NET
        static void Main(string[] args)
        {
            var simpleShopDB = new DataSet();

            simpleShopDB.ReadXmlSchema(@"C:\Users\HP\Desktop\Test\ShopDbSchema.xml");
            simpleShopDB.ReadXml(@"C:\Users\HP\Desktop\Test\ShopDBData.xml");

            var strongShopDB = new ShopDb();

            strongShopDB.Customers.Merge(simpleShopDB.Tables["Customers"]);
            strongShopDB.Orders.Merge(simpleShopDB.Tables["Orders"]);

            var selectedCustomer = strongShopDB.Customers.FindByCustomerNo(3);

            Console.WriteLine($"{selectedCustomer.LName} {selectedCustomer.FName} {selectedCustomer.MName}");

            foreach (ShopDb.OrdersRow row in selectedCustomer.GetOrdersRows())
            {
                Console.WriteLine($"\tOrderID: {row.OrderID}");
                Console.WriteLine($"\tOrderDate: {row.OrderDate}");
                Console.WriteLine();
            }

            Console.ReadKey();
        }
コード例 #2
0
        public IEnumerable <RegisteredCanalesTotal> GetCanalesByCategory(string category)
        {
            using (var db = new ShopDb())
            {
                return(db.CanalesTotal
                       .Where(x => x.GENERO.Equals(category))
                       .ToList()
                       .Select(x => new RegisteredCanalesTotal
                {
                    TECNOLOGIA = x.TECNOLOGIA,
                    DEFINICION = x.DEFINICION,
                    GENERO = x.GENERO,
                    NUMERO_CANAL = x.NUMERO_CANAL,
                    NUMERO_CANAL2 = x.NUMERO_CANAL2,
                    OBSERVACIONES = x.OBSERVACIONES,
                    NOMBRE_CANAL = x.NOMBRE_CANAL,
                    Claro_HDTV_Basico = x.Claro_HDTV_Basico,
                    Claro_HDTV_Avanzado = x.Claro_HDTV_Avanzado,
                    Claro_HDTV_Superior = x.Claro_HDTV_Superior,

                    Paquete_HBO = x.Paquete_HBO,
                    Paquete_Fox_Premium = x.Paquete_Fox_Premium,
                    Canal_NHK = x.Canal_NHK,
                    HotPack_HD = x.HotPack_HD,
                    ADRENALINA_SPORTS_NETWORK = x.ADRENALINA_SPORTS_NETWORK,
                    Golden_Premier = x.Golden_Premier,
                    nombreCanal = x.nombreCanal
                }));
            }
        }
コード例 #3
0
        private static void PrintCustomerOrdersAndReviews(ShopDb db)
        {
            var customerId = int.Parse(Console.ReadLine());

            var customerData = db
                               .Customers
                               .Where(c => c.Id == customerId)
                               .Select(c => new
            {
                Orders = c.Orders
                         .Select(o => new
                {
                    o.Id,
                    Items = o.Items.Count
                })
                         .OrderBy(o => o.Id),
                Reviews = c.Reviews.Count
            })
                               .FirstOrDefault();

            foreach (var order in customerData.Orders)
            {
                Console.WriteLine($"order {order.Id}: {order.Items} items");
            }

            Console.WriteLine($"reviews: {customerData.Reviews}");
        }
コード例 #4
0
        public RegisteredProduct RegisterProduct(CreateProducto newProducto)
        {
            var product = new Product()
            {
                CategoryId  = newProducto.CategoryId,
                Name        = newProducto.Name,
                Descripcion = newProducto.Descripcion
            };

            using (var db = new ShopDb())
            {
                if (db.Products.Where(x => x.Name.Equals(product.Name)).Any())
                {
                    throw new Exception("No se pueden registrar Productos con el mismo nombre");
                }
                db.Products.Add(product);
                db.SaveChanges();
                return(new RegisteredProduct()
                {
                    Id = product.Id,
                    CategoryName = db.Categories.Find(product.CategoryId).Name,
                    Description = product.Descripcion,
                    Name = product.Name
                });
            }
        }
コード例 #5
0
        private static void ProcessCommands(ShopDb db)
        {
            while (true)
            {
                var commandInfo = Console.ReadLine()
                                  .Split(new[] { ' ', '-', ';' }, StringSplitOptions.RemoveEmptyEntries);

                if (commandInfo[0] == "END")
                {
                    break;
                }
                switch (commandInfo[0])
                {
                case "register": RegisterCustomer(db, commandInfo);
                    break;

                case "order": MakeOrder(db, commandInfo);
                    break;

                case "review": LeaveReview(db, commandInfo);
                    break;

                default:
                    break;
                }
            }
        }
コード例 #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseSession();
            //app.UseMvcWithDefaultRoute();



            using (var scope = app.ApplicationServices.CreateScope())
            {
                ShopDb content = scope.ServiceProvider.GetRequiredService <ShopDb>();
                DbObjects.Initial(content);
            };

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                //routes.MapRoute( // Bu yazilis formasi da var!!!
                //   name: "CategoryFilter",
                //   template: "{controller=Car}/{action=Index}/{category?}", defaults: new { controller = "Car", action = "Index"});
            });
        }
コード例 #7
0
 private static void AddItem(ShopDb db, string name, decimal price)
 {
     db
     .Items
     .Add(new Item {
         Name = name, Price = price
     });
     db.SaveChanges();
 }
コード例 #8
0
        private static void RegisterCustomer(ShopDb db, string[] commandInfo)
        {
            var customerName = commandInfo[1];
            var salesmanId   = int.Parse(commandInfo[2]);

            db.Customers.Add(new Customer {
                Name = customerName, SalesmanId = salesmanId
            });
            db.SaveChanges();
        }
コード例 #9
0
        private static void LeaveReview(ShopDb db, string[] commandInfo)
        {
            var customerId = int.Parse(commandInfo[1]);
            var itemId     = int.Parse(commandInfo[2]);

            db
            .Reviews
            .Add(new Review {
                CustomerId = customerId, ItemId = itemId
            });
            db.SaveChanges();
        }
コード例 #10
0
 public IEnumerable <RegisteredCategory> GetAllCategories()
 {
     using (var db = new ShopDb())
     {
         return(db.Categories.ToList().Select(x => new RegisteredCategory
         {
             Id = x.Id,
             Description = x.Description,
             Name = x.Name
         }));
     }
 }
コード例 #11
0
        //public IEnumerable<RegisteredCanales> GetAllCanales()
        //{
        //    using (var db = new ShopDb())
        //    {
        //        return db.Canales.ToList().Select(x => new RegisteredCanales
        //        {
        //            Plan = x.Plan,
        //            HD = x.HD,
        //            SD = x.SD,
        //            Audio = x.Audio
        //        });
        //    }
        //}
        public IEnumerable <RegisteredGenero> GetAllGenero()
        {
            using (var db = new ShopDb())
            {
                //EFContext.TestAddresses.Select(m => m.Name).Distinct();


                return(db.Generos.ToList().Select(x => new RegisteredGenero
                {
                    Genero = x.GeneroCanal
                }));
            }
        }
コード例 #12
0
        private static void SaveSalesmen(ShopDb db)
        {
            var names = Console.ReadLine()
                        .Split(new[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var name in names)
            {
                db.Salesmans.Add(new Salesman {
                    Name = name
                });
            }
            db.SaveChanges();
        }
コード例 #13
0
 public void CategoryInsertionTest()
 {
     using (var db = new ShopDb())
     {
         Category newCatery = new Category()
         {
             Name        = "Frutas",
             Description = "Vegetales dulces"
         };
         db.Categories.Add(newCatery);
         db.SaveChanges();
         Assert.IsTrue(newCatery.Id > 0);
     }
 }
コード例 #14
0
 private static void PrintSalesmenWithCustomersCount(ShopDb db)
 {
     db
     .Salesmans
     .Select(x => new
     {
         x.Name,
         Customers = x.Customers.Count
     })
     .OrderByDescending(s => s.Customers)
     .ThenBy(s => s.Name)
     .ToList()
     .ForEach(x => Console.WriteLine($"{x.Name} - {x.Customers} customers"));
 }
コード例 #15
0
 public static void Main()
 {
     using (var db = new ShopDb())
     {
         ClearDatabase(db);
         SaveSalesmen(db);
         ReadItemCommands(db);
         ProcessCommands(db);
         //PrintSalesmenWithCustomersCount(db);
         //PrintCustomersWithOrdersCountAndReviewCount(db);
         //PrintCustomerOrdersAndReviews(db);
         //PrintCustomerData(db);
         PrintOrdersWithMoreThanOneItem(db);
     }
 }
コード例 #16
0
 private static void PrintCustomersWithOrdersCountAndReviewCount(ShopDb db)
 {
     db
     .Customers
     .Select(c => new
     {
         c.Name,
         Orders  = c.Orders.Count,
         Reviews = c.Reviews.Count
     })
     .OrderByDescending(c => c.Orders)
     .ThenByDescending(c => c.Reviews)
     .ToList()
     .ForEach(c => Console.WriteLine($"{c.Name}{Environment.NewLine}Orders: {c.Orders}{Environment.NewLine}Reviews: {c.Reviews}"));
 }
コード例 #17
0
 public IEnumerable <RegisteredCanalesPlus> GetAllCanalesPlus()
 {
     using (var db = new ShopDb())
     {
         return(db.CanalesPlus
                .ToList()
                .Select(x => new RegisteredCanalesPlus
         {
             Plan = x.Plan,
             HD = x.HD,
             SD = x.SD,
             Total = x.Total
         }));
     }
 }
コード例 #18
0
        private static void ReadItemCommands(ShopDb db)
        {
            while (true)
            {
                var commandInfo = Console.ReadLine()
                                  .Split(';');

                if (commandInfo[0] == "END")
                {
                    break;
                }

                AddItem(db, commandInfo[0], decimal.Parse(commandInfo[1]));
            }
        }
コード例 #19
0
 public IEnumerable <RegisteredProduct> GetAllProducts()
 {
     using (var db = new ShopDb())
     {
         return(db.Products
                .Include("Category")
                .ToList()
                .Select(x => new RegisteredProduct
         {
             Id = x.Id,
             Description = x.Descripcion,
             Name = x.Name,
             CategoryName = x.Category.Name
         }));
     }
 }
コード例 #20
0
 public IEnumerable <RegisteredProduct> GetProductByCategoryId(int categoryId)
 {
     using (var db = new ShopDb())
     {
         return(db.Products
                .Include("Category")
                .Where(x => x.CategoryId.Equals(categoryId))
                .ToList()
                .Select(x => new RegisteredProduct
         {
             Id = x.Id,
             Description = x.Descripcion,
             Name = x.Name,
             CategoryName = x.Category.Name
         }));
     }
 }
コード例 #21
0
ファイル: Program.cs プロジェクト: lusinekh/ADO.NET
        static void Main(string[] args)
        {
            var shopDB = new ShopDb();
            var customersTableAdapter = new CustomersTableAdapter();

            customersTableAdapter.Fill(shopDB.Customers); //this will fill shopdb.customers table with data, so easy!

            foreach (DataRow row in shopDB.Customers.Rows)
            {
                foreach (DataColumn column in shopDB.Customers.Columns)
                {
                    Console.WriteLine($"{column.ColumnName}: {row[column]}");
                }
                Console.WriteLine();
            }

            Console.ReadKey();
        }
コード例 #22
0
        private static void MakeOrder(ShopDb db, string[] commandInfo)
        {
            var customerId = int.Parse(commandInfo[1]);
            var order      = new Order {
                CustomerId = customerId
            };

            for (int i = 2; i < commandInfo.Length; i++)
            {
                order.Items.Add(new ItemOrder
                {
                    ItemId = int.Parse(commandInfo[i])
                });
            }
            db
            .Orders
            .Add(order);
            db.SaveChanges();
        }
コード例 #23
0
        private static void PrintCustomerData(ShopDb db)
        {
            var customerId = int.Parse(Console.ReadLine());

            var customerData = db
                               .Customers
                               .Where(c => c.Id == customerId)
                               .Select(c => new
            {
                c.Name,
                Orders       = c.Orders.Count,
                Revies       = c.Reviews.Count,
                SalesmanName = c.Salesman.Name
            })
                               .FirstOrDefault();

            Console.WriteLine($"Customer: {customerData.Name}{Environment.NewLine}Orders count: {customerData.Orders}");
            Console.WriteLine($"Reviews: {customerData.Revies}{Environment.NewLine}Salesman: {customerData.SalesmanName}");
        }
コード例 #24
0
        public RegisteredProduct RegisterProduct(CreateProducto newProducto)
        {
            var product = new Product()
            {
                CategoryId  = newProducto.CategoryId,
                Name        = newProducto.Name,
                Descripcion = newProducto.Descripcion
            };

            using (var db = new ShopDb())
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(new RegisteredProduct()
                {
                    Id = product.Id,
                    CategoryName = db.Categories.Find(product.CategoryId).Name,
                    Description = product.Descripcion,
                    Name = product.Name
                });
            }
        }
コード例 #25
0
        public async Task <ActionResult> Create(ShopView shopView)
        {
            if (ModelState.IsValid)
            {
                ShopDb shopDb = new ShopDb();
                shopView.ViewFromDb(shopDb);
                if (shopView.ShopImage != null && shopView.ShopImage.ContentLength > 0)
                {
                    shopDb.SaveImageFile(shopView.ShopImage, "/Image/Shops");
                }
                else
                {
                    shopDb.ImagePath = null;
                }
                shopDb.IsActive = Convert.ToBoolean(shopView.Activ);
                db.Shops.Add(shopDb);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(shopView));
        }
コード例 #26
0
        private static void PrintOrdersWithMoreThanOneItem(ShopDb db)
        {
            var customerId = int.Parse(Console.ReadLine());

            //var customerOrderWithMoreThanOneItem = db
            //    .Customers
            //    .Where(c => c.Id == customerId)
            //    .Select(c => new
            //    {
            //        Orders=c.Orders.Count(o=>o.Items.Count>1)
            //    })
            //    .FirstOrDefault();
            //Console.WriteLine($"Orders:{customerOrderWithMoreThanOneItem.Orders}");

            var order = db
                        .Orders
                        .Where(o => o.CustomerId == customerId)
                        .Where(o => o.Items.Count > 1)
                        .Count();

            Console.WriteLine($"Orders:{order}");
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: marioleiva/appHFC
 static void Main(string[] args)
 {
     using (var db = new ShopDb())
     {
         SalesTurn turn = new SalesTurn()
         {
             Active    = true,
             Start     = DateTime.Now,
             End       = DateTime.Now,
             Employees = new HashSet <Employe>()
             {
                 new Employe()
                 {
                     Address  = "Av La Marina 766",
                     Birthday = DateTime.Now.ToString(),
                     Nombre   = "Daniel Carbajal",
                     Sex      = Sex.Male,
                 }
             }
         };
         db.SalesTurns.Add(turn);
         db.SaveChanges();
     }
 }
 public CategoryRepository(ShopDb shopdb)
 {
     _dbshop = shopdb;
 }
コード例 #29
0
 private static void ClearDatabase(ShopDb db)
 {
     db.Database.EnsureDeleted();
     db.Database.EnsureCreated();
 }
コード例 #30
0
 public Register_Form()
 {
     db = new ShopDb();
     InitializeComponent();
 }