// azure link: http://productssample.azurewebsites.net/api/products //Product prodList; // GET: Products public ActionResult Index() { IEnumerable<Vendor> vendList; WebClient client = new WebClient(); string output = client.DownloadString(dashboardUrlBase); vendList = JsonConvert.DeserializeObject<List<Vendor>>(output); VendorListViewModel vendorList = new VendorListViewModel(); List<VendorViewModel> vendVMs = new List<VendorViewModel>(); foreach (Vendor v in vendList) { VendorViewModel vvm = new VendorViewModel(); vvm.VendorName = v.VendorName; vvm.VendorCode = v.VendorCode; vvm.ValidFrom = v.ValidFrom; vvm.ValidThru = v.ValidThru; vendVMs.Add(vvm); }; vendorList.Vendors = vendVMs; return View("Index",vendorList); }
// GET: Vendors public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page) { IEnumerable<Vendor> vendList; WebClient client = new WebClient(); string output = client.DownloadString(dashboardUrlBase); vendList = JsonConvert.DeserializeObject<List<Vendor>>(output); if (String.IsNullOrEmpty(sortOrder)) { sortOrder = "name"; }; string inSortOrder = sortOrder; if (Session != null) { if (Session["sort"] == null) { Session["sort"] = ""; } if (Session["sortDir"] == null) { Session["sortDir"] = "asc"; } } string sortDir = Session["sortDir"].ToString(); if (sortOrder == Session["sort"].ToString()) { sortDir = sortDir == "asc" ? "desc" : "asc"; } else { sortDir = "asc"; } Session["sortDir"] = sortDir; Session["sort"] = inSortOrder; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var vendors = from v in vendList select v; if (!String.IsNullOrEmpty(searchString)) { vendors = vendors.Where(v => v.VendorName.ToLower().Contains(searchString.ToLower())); } switch (sortOrder+sortDir) { case "namedesc": vendors = vendors.OrderByDescending(v => v.VendorName); break; case "codedesc": vendors = vendors.OrderByDescending(v => v.VendorCode); break; case "codeasc": vendors = vendors.OrderBy(v => v.VendorCode); break; case "fromasc": vendors = vendors.OrderBy(v => v.ValidFrom); break; case "fromdesc": vendors = vendors.OrderByDescending(v => v.ValidFrom); break; case "thruasc": vendors = vendors.OrderBy(v => v.ValidThru); break; case "thrudesc": vendors = vendors.OrderByDescending(v => v.ValidThru); break; default: vendors = vendors.OrderBy(v => v.VendorName); break; } int pageSize = 30; int pageNumber = (page ?? 1); VendorListViewModel vendorList = new VendorListViewModel(); List<VendorViewModel> vendVMs = new List<VendorViewModel>(); foreach (Vendor v in vendors) { VendorViewModel vvm = new VendorViewModel(); vvm.VendorName = v.VendorName; vvm.VendorCode = v.VendorCode; vvm.ValidFrom = v.ValidFrom; vvm.ValidThru = v.ValidThru; vvm.Id = v.Id; vendVMs.Add(vvm); }; vendorList.Vendors = vendVMs; return View("Index", vendorList); }