Пример #1
0
        static void Main(string[] args)
        {
            InitializeMapper();

            //LinqToDB.Common.Configuration.Linq.AllowMultipleQuery = true;
            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (s, s1) => Debug.WriteLine(s, s1);

            using (var db = new NorthwindDb())
            {
                var q =
                    (from o in db.OrderDetails
                     .LoadWith(o => o.OrderDetailsOrder)
                     .LoadWith(o => o.OrderDetailsOrder.Customer)
                     .LoadWith(o => o.OrderDetailsOrder.Employee)
                     where o.OrderDetailsOrder.Employee.LastName.StartsWith("King")
                     select o)
                    .ProjectTo <OrderDto>()
                    .ToList();

                foreach (var o in q)
                {
                    Console.WriteLine(
                        $"OrderDate: {o.OrderDetailsOrderOrderDate}\tOrderDetailsProductProductName:{o.OrderDetailsProductProductName}\tCustomerContactName: {o.OrderDetailsOrderCustomerContactName}\tQuantity: {o.Quantity}");
                }
            }

            Console.ReadLine();
        }
Пример #2
0
        public ActionResult Products(int categoryId)
        {
            NorthwindDb           db       = new NorthwindDb(connectionString);
            IEnumerable <Product> products = db.GetProductsByCategoryId(categoryId);

            return(View(products));
        }
Пример #3
0
        public ActionResult Categories()
        {
            NorthwindDb            db         = new NorthwindDb(connectionString);
            IEnumerable <Category> categories = db.GetAll();

            return(View(categories));
        }
Пример #4
0
        public ActionResult CustomerDetails(string customerId)
        {
            var      db       = new NorthwindDb(connectionString);
            Customer customer = db.GetCustomerById(customerId);

            return(View(customer));
        }
Пример #5
0
        public ActionResult Customers()
        {
            var db        = new NorthwindDb(connectionString);
            var customers = db.GetCustomers();

            return(View(customers));
        }
        public IActionResult OrderDetails(int year, string country)
        {
            NorthwindDb  db     = new NorthwindDb(_connectionString);
            List <Order> orders = db.GetOrdersForYear(year, country);

            return(View(orders));
        }
Пример #7
0
        public ActionResult Products()
        {
            NorthwindViewModel vm = new NorthwindViewModel();
            NorthwindDb        db = new NorthwindDb(_connectionString);

            vm.Products = db.GetProducts();

            return(View(vm));
        }
        public IActionResult Products(int catId)
        {
            NorthwindDb       db = new NorthwindDb(_connectionString);
            ProductsViewModel vm = new ProductsViewModel();

            vm.Products     = db.GetProductsForCategory(catId);
            vm.CategoryName = db.GetCategoryName(catId);
            return(View(vm));
        }
        public IActionResult Orders()
        {
            NorthwindDb     db = new NorthwindDb(_connectionString);
            OrdersViewModel vm = new OrdersViewModel();

            vm.Orders      = db.GetOrders();
            vm.CurrentDate = DateTime.Now;
            return(View(vm));
        }
        public IActionResult ShowSearchResults(string searchText)
        {
            NorthwindDb            db = new NorthwindDb(_connectionString);
            SearchResultsViewModel vm = new SearchResultsViewModel();

            vm.Products   = db.Search(searchText);
            vm.SearchText = searchText;
            return(View(vm));
        }
Пример #11
0
        public ActionResult Categories()
        {
            NorthwindDb             db = new NorthwindDb(_connectionString);
            CategoriesPageViewModel vm = new CategoriesPageViewModel
            {
                Categories = db.GetCategories()
            };

            return(View(vm));
        }
Пример #12
0
        public ActionResult ShowProductSearchResults(string searchText)
        {
            NorthwindDb            db = new NorthwindDb(_connectionString);
            ProductSearchViewModel vm = new ProductSearchViewModel
            {
                Products   = db.SearchProducts(searchText),
                SearchText = searchText
            };

            return(View(vm));
        }
Пример #13
0
        public ActionResult Index(string categoryName, int?minStock)
        {
            NorthwindDb           db       = new NorthwindDb(Properties.Settings.Default.ConStr);
            IEnumerable <Product> products = db.Search(categoryName, minStock);
            HomePageViewModel     vm       = new HomePageViewModel();

            vm.Products        = products;
            vm.CategoryName    = categoryName;
            vm.MinUnitsInStock = minStock;
            return(View(vm));
        }
Пример #14
0
        public ActionResult Products(int catid)
        {
            NorthwindDb           db        = new NorthwindDb(connectionString);
            Category              category  = db.GetCategoryById(catid);
            IEnumerable <Product> products  = db.GetProductsForCategory(catid);
            ProductsViewModel     viewModel = new ProductsViewModel();

            viewModel.Products = products;
            viewModel.Category = category;
            return(View(viewModel));
        }
Пример #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync(NorthwindDb.GetData());
            });
        }
Пример #16
0
        public ActionResult Orders()
        {
            NorthwindDb         db        = new NorthwindDb(_connectionString);
            List <Order>        orders    = db.GetOrders();
            OrdersPageViewModel viewModel = new OrdersPageViewModel
            {
                Orders = orders,
                Date   = DateTime.Now
            };

            return(View(viewModel));
        }
Пример #17
0
        static void Main(string[] args)
        {
            NorthwindDb           db       = new NorthwindDb(Properties.Settings.Default.ConStr);
            IEnumerable <Product> products = db.Search("Beverages", 50);

            products.ToList().ForEach(p =>
            {
                Console.WriteLine($"{p.Name} - {p.CategoryName} - {p.UnitsInStock}");
            });

            Console.ReadKey(true);
        }
Пример #18
0
        public IActionResult Index()
        {
            // Add to the service
            var path       = hostingEnvironment.ContentRootPath;
            var folderPath = Path.Combine(path, "Database");
            var filePath   = Path.Combine(folderPath, "northwind.xml");

            //var data = new[] { "Foo", "Bar" };
            var data = NorthwindDb.GetRetiredEmployees(filePath);

            return(View("index", data));
        }
Пример #19
0
        public IActionResult SearchResults(int minStock, int maxStock)
        {
            NorthwindDb             db       = new NorthwindDb(@"Data Source=.\sqlexpress;Initial Catalog=Northwnd;Integrated Security=True;");
            List <Product>          products = db.SearchProducts(minStock, maxStock);
            SearchProductsViewModel vm       = new SearchProductsViewModel
            {
                Products = products,
                MinStock = minStock,
                MaxStock = maxStock
            };

            return(View(vm));
        }
Пример #20
0
        public ActionResult SearchResults(int min, int max)
        {
            NorthwindDb            db       = new NorthwindDb(_connectionString);
            List <Product>         products = db.Search(min, max);
            SearchResultsViewModel vm       = new SearchResultsViewModel
            {
                Products = products,
                Min      = min,
                Max      = max
            };

            return(View(vm));
        }
Пример #21
0
        public void SimpleQuery()
        {
            using (var db = new NorthwindDb())
            {
                var q =
                    from c in db.Categories
                    select c;

                foreach (var c in q)
                {
                    Debug.WriteLine(c.CategoryName);
                }
            }
        }
Пример #22
0
        public async Task <ActionResult> Report(Period period)
        {
            if (period.End == new DateTime())
            {
                period.End = DateTime.Now;
            }
            else
            {
                period.End = period.End.AddSeconds(86399);
            }

            IEnumerable <OrderDetail> list;

            using (NorthwindDb db = new NorthwindDb())
            {
                list = await db.OrderDetails
                       .Include(o => o.Order)
                       .Where(o => o.Order.OrderDate >= period.Start)
                       .Where(o => o.Order.OrderDate <= period.End)
                       .Include(o => o.Product).ToListAsync();
            }

            var report = new List <Report>();

            foreach (var order in list)
            {
                report.Add(new Report
                {
                    Number    = order.Order.ID,
                    OrderDate = order.Order.OrderDate,
                    Article   = order.Product.ID,
                    Name      = order.Product.Name,
                    Quantity  = order.Quantity,
                    UnitPrice = order.UnitPrice,
                    Cost      = order.Quantity * order.UnitPrice
                });
            }

            CreatingExcelDoc.CreateDoc(report, period);

            ViewBag.Period = period;

            return(View("Report", report));
        }
Пример #23
0
 public CategoriesRepository(NorthwindDb db) : base(db)
 {
 }
 public NorthwindRepository(NorthwindDb db)
 {
     Db    = db;
     DbSet = db.Set <TEntity>();
 }
Пример #25
0
 public CustomersService(NorthwindDb db)
 {
     _db = db;
 }
Пример #26
0
 public ImagesService(NorthwindDb db)
 {
     _db = db;
 }
 public ProductsService(NorthwindDb db)
 {
     _db = db;
 }
Пример #28
0
 //public ReportsController(NorthwindDb db)
 //{
 //    this.db = db;
 //}
 public ReportsController(NorthwindDb db) => this.db = db;
        public IActionResult Categories()
        {
            NorthwindDb db = new NorthwindDb(_connectionString);

            return(View(db.GetCategories()));
        }
Пример #30
0
 public OrdersService(NorthwindDb db)
 {
     _db = db;
 }