public ActionResult Index() { try { var cloudTableClient = cloudStorageAccount.CreateCloudTableClient(); cloudTableClient.CreateTableIfNotExist("Customers"); var context = new CustomerDataContext(cloudStorageAccount.TableEndpoint.AbsoluteUri, cloudStorageAccount.Credentials); var list = context.Customers.ToList(); // 如果表中有实体信息则显示该表到UI层 if (list.Count() > 0) { MVCSessionCachedDataProvider<Customer> provider = new MVCSessionCachedDataProvider<Customer>(this, "provider1"); TableStoragePagingUtility<Customer> pagingUtility = new TableStoragePagingUtility<Customer>(provider, cloudStorageAccount, context, 10, "Customers"); return View("Index", new CustomersSet() { Customers = pagingUtility.GetCurrentOrFirstPage().ToList(), ReadyToShowUI = true }); } else { //如果表中没有实体显示指引用户向表中添加数据的链接. ViewResult vr = View("Index", new CustomersSet() { ReadyToShowUI = false }); return vr; } } catch (Exception ex) { return View("Error", new HandleErrorInfo(ex, "HomeController", "Index")); } }
public ActionResult AddDataToTest() { var cloudTableClient = cloudStorageAccount.CreateCloudTableClient(); var context = new CustomerDataContext(cloudStorageAccount.TableEndpoint.AbsoluteUri, cloudStorageAccount.Credentials); try { // 向表中添加65个实体 for (int i = 0; i < 65; i++) { context.AddObject("Customers", new Customer() { Age = r.Next(16, 70), Name = "Customer" + i.ToString() }); } context.SaveChanges(); MVCSessionCachedDataProvider<Customer> provider = new MVCSessionCachedDataProvider<Customer>(this, "provider1"); TableStoragePagingUtility<Customer> pagingUtility = new TableStoragePagingUtility<Customer>(provider, cloudStorageAccount, context, 10, "Customers"); return View("Index", new CustomersSet() { Customers = pagingUtility.GetNextPage().ToList(), ReadyToShowUI = true }); } catch (Exception ex) { return View("Error",new HandleErrorInfo(ex,"HomeController","AddDataToTest")); } }
public ActionResult Next() { var cloudTableClient = cloudStorageAccount.CreateCloudTableClient(); var context = new CustomerDataContext(cloudStorageAccount.TableEndpoint.AbsoluteUri, cloudStorageAccount.Credentials); MVCSessionCachedDataProvider<Customer> provider = new MVCSessionCachedDataProvider<Customer>(this, "provider1"); TableStoragePagingUtility<Customer> pagingUtility = new TableStoragePagingUtility<Customer>(provider, cloudStorageAccount, context, 10, "Customers"); return View("Index", new CustomersSet() { Customers = pagingUtility.GetNextPage().ToList(), ReadyToShowUI=true }); }