예제 #1
0
        public async System.Threading.Tasks.Task <ActionResult> Products()
        {
            _northwindRepository = new NorthwindRepository();
            var list = await _northwindRepository.GetProductList();

            return(View(list.Data));
        }
예제 #2
0
        public async System.Threading.Tasks.Task <ActionResult> OffShelf(int ProductID)
        {
            _northwindRepository = new NorthwindRepository();
            var result = await _northwindRepository.OffShelf(ProductID);

            //可考慮回傳訊息:新增成功、失敗,原因。
            return(RedirectToAction("Products", "Home"));
        }
예제 #3
0
        public async System.Threading.Tasks.Task <ActionResult> EditPrice(ProductsModel Product)
        {
            _northwindRepository = new NorthwindRepository();
            var result = await _northwindRepository.UpdatePrice(Product.ProductID, Product.UnitPrice);

            //可考慮回傳訊息:新增成功、失敗,原因。
            return(RedirectToAction("Products", "Home"));
        }
예제 #4
0
        public void ExecuteReaderWithPagingByPersister(int pageIndex, int pageSize)
        {
            var persister = new TrimReaderPersister <OrderDetail>();

            using (var cmd = NorthwindRepository.GetCommand(GetOrderDetailsSql)) {
                var orderDetails = NorthwindRepository.ExecuteInstance <OrderDetail>(persister, cmd, pageIndex, pageSize);

                Console.WriteLine(orderDetails);
            }
        }
예제 #5
0
        public ActionResult AmountToShow(string searchTerm, int num)
        {
            var repo     = new NorthwindRepository(Properties.Settings.Default.ConStr);
            var products = repo.SearchProductName(searchTerm);

            if (num == 0)
            {
                num = products.Count();
            }
            return(Json(products.Take(num), JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        static void Main(string[] args)
        {
            NorthwindRepository r = new NorthwindRepository();
            //var empl = r.GetAllEmployees(i => i.ReportsTo == 2, i => i.LastName);
            //var empl = r.GetAllEmployees(i => i.LastName);
            var empl = r.GetAllEmployees();

            foreach (var item in empl)
            {
                Console.WriteLine($"{item.Id}: {item.FirstName} {item.LastName}");
            }
        }
예제 #7
0
        /// <summary>
        /// Save Northwind metadata to a script file
        /// Certain tests will load this script dynamically so they can get metadata
        /// without making a Web API call
        /// </summary>
        public static void WriteNorthwindMetadataScriptFile()
        {
            var          metadata       = new NorthwindRepository().Metadata;
            var          scriptFilename = HostingEnvironment.MapPath("~/tests/helpers/northwindMetadata.js");
            const string prefix         = "docCode.northwindMetadata = ";
            const string postfix        = ";";

            using (var writer = new StreamWriter(scriptFilename))
            {
                writer.WriteLine(prefix + metadata + postfix);
            }
        }
예제 #8
0
        public async System.Threading.Tasks.Task <ActionResult> InsertProduct(ProductsModel Product)
        {
            _northwindRepository = new NorthwindRepository();
            var result = await _northwindRepository.InsertProduct(Product);

            //使用多執行緒的原因:一個動作可同時做多件事,但這個範例沒有做。

            /* 正規的設計下,會制定標準化的回傳格式。讓接收端,了解該真實狀態。
             * 另外也會將結果回傳給前端,這邊省略
             */
            return(RedirectToAction("Products", "Home"));
        }
예제 #9
0
        public void Can_Create_Command_By_NamedQueryCommand_With_QueryKey(string queryKey)
        {
            NorthwindRepository.QueryProvider.Should().Not.Be.Null();

            using (var cmd = NorthwindRepository.GetNamedQueryCommand(queryKey))
                using (var dataTable = NorthwindRepository.ExecuteDataTable(cmd)) {
                    Assert.IsNotNull(dataTable);
                    Assert.IsFalse(dataTable.HasErrors);
                    Assert.IsTrue(dataTable.Rows.Count > 0);
                }

            using (var dataTable = NorthwindRepository.ExecuteDataTable(queryKey)) {
                dataTable.Should().Not.Be.Null();
                Assert.IsFalse(dataTable.HasErrors);
                Assert.IsTrue(dataTable.Rows.Count > 0);
            }
        }
예제 #10
0
        public void Can_Create_Command_By_NamedQueryCommand_With_Section_And_QueryName(string section, string queryName)
        {
            if (NorthwindRepository.QueryProvider != null)
            {
                using (var cmd = NorthwindRepository.GetNamedQueryCommand(section, queryName))
                    using (var dataTable = NorthwindRepository.ExecuteDataTable(cmd)) {
                        Assert.IsNotNull(dataTable);
                        Assert.IsFalse(dataTable.HasErrors);
                        Assert.IsTrue(dataTable.Rows.Count > 0);
                    }

                var queryKey = string.Concat(section, ",", queryName);
                using (var dataTable = NorthwindRepository.ExecuteDataTable(queryKey)) {
                    Assert.IsNotNull(dataTable);
                    Assert.IsFalse(dataTable.HasErrors);
                    Assert.IsTrue(dataTable.Rows.Count > 0);
                }
            }
        }
예제 #11
0
 // Todo: inject via an interface rather than "new" the concrete class
 public NorthwindController(NorthwindRepository repository)
 {
     _repository = repository ?? new NorthwindRepository();
 }
예제 #12
0
 public ProductsController(NorthwindRepository context)
 {
     this.repository = context;
 }
 // Todo: inject via an interface rather than "new" the concrete class
 protected MultiBaseController(NorthwindRepository repository)
 {
     Repository = repository ?? new NorthwindRepository();
 }
예제 #14
0
 public NorthwindController()
 {
     // Todo: inject via an interface rather than "new" the concrete class
     _repository = new NorthwindRepository();
 }
예제 #15
0
        public IRepository <TEntity> GetNorthwindEntities <TEntity>() where TEntity : class, IEntity
        {
            IRepository <TEntity> entityRepository = new NorthwindRepository <TEntity>(_northwindDb);

            return(entityRepository);
        }
예제 #16
0
 public TerritoriesWebSvc()
 {
     _northwindRepository =
         new NorthwindRepository(WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString);
 }
예제 #17
0
        public ActionResult GetSearchResults(string searchTerm)
        {
            var repo = new NorthwindRepository(Properties.Settings.Default.ConStr);

            return(Json(repo.SearchProductName(searchTerm), JsonRequestBehavior.AllowGet));
        }
        public ProductsController()
        {
            String cs = ConfigurationManager.ConnectionStrings["NorthwindSQL"].ConnectionString;

            _repository = new NorthwindRepository(new NorthwindDbContext(cs));
        }
 public DynamicColumnsAndRowsController(NorthwindRepository northwindRepository)
 {
     _northwindRepository = northwindRepository;
 }