public JsonResult Get(int pageIndex, int pageSize, string pageOrder, string title) { if (pageOrder.Trim() == "ID") { pageOrder = "OrderID"; } var list = Producers.Get(pageIndex, pageSize, pageOrder, title); int total = Producers.Count(title); int totalPage = (int)Math.Ceiling((decimal)total / pageSize); if (pageSize > total) { pageSize = total; } if (list.Count < pageSize) { pageSize = list.Count; } JsonResult result = new JsonResult() { Data = new { TotalPages = totalPage, PageIndex = pageIndex, PageSize = pageSize, Rows = list }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return(result); }
private void HandleTimer() { System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => { lastFarmID = "-1"; lastProducerID = "-1"; lastFieldID = "-1"; var selProducerID = (SelectedProducer != null) ? SelectedProducer.ID : ""; var selFarmID = (SelectedFarm != null) ? SelectedFarm.ID : ""; var selFieldID = (SelectedField != null) ? SelectedField.ID : ""; var selItemID = ""; if (SelectedItem != null) { selItemID = SelectedItem.ListID; } refresh(); //restore selections int producerIndex = 0; for (producerIndex = 0; producerIndex < Producers.Count(); producerIndex++) { if (Producers[producerIndex].ID == selProducerID) { break; } } if (producerIndex >= Producers.Count()) { producerIndex = 0; } if (Producers.Count() > 0) { SelectedProducer = Producers[producerIndex]; } int farmIndex = 0; for (farmIndex = 0; farmIndex < Farms.Count(); farmIndex++) { if (Farms[farmIndex].ID == selFarmID) { break; } } if (farmIndex >= Farms.Count()) { farmIndex = 0; } if (Farms.Count() > 0) { SelectedFarm = Farms[farmIndex]; } int fieldIndex = 0; for (fieldIndex = 0; fieldIndex < Fields.Count(); fieldIndex++) { if (Fields[fieldIndex].ID == selFieldID) { break; } } if (fieldIndex >= Fields.Count()) { fieldIndex = 0; } if (Fields.Count() > 0) { SelectedField = Fields[fieldIndex]; } var item = Lists.SingleOrDefault(l => l.ListID == selItemID); if (item != null) { SelectedItem = item; } else if (Lists.Count() > 0) { SelectedItem = Lists[0]; } else { SelectedItem = null; } })); }