public JsonResult LoadData(int type, string keyword, int status, int pageIndex, int pageSize) { string str = NonUnicode.RemoveUnicode(keyword).ToLower(); var model = new OrderDao().ListAll(); switch (type) { case 0: model = model.Where(x => NonUnicode.RemoveUnicode(x.NameAccount.ToLower()).Contains(str) || x.ShipMobile.ToString().Contains(str) || NonUnicode.RemoveUnicode(x.ShipName.ToLower()).Contains(str) || NonUnicode.RemoveUnicode(x.ShipAddress.ToLower()).Contains(str) ); break; case 1: model = model.Where(x => NonUnicode.RemoveUnicode(x.NameAccount.ToLower()).Contains(str)); break; case 2: model = model.Where(x => NonUnicode.RemoveUnicode(x.ShipName.ToLower()).Contains(str)); break; case 3: model = model.Where(x => x.ShipMobile.ToString().Contains(str)); break; case 4: model = model.Where(x => NonUnicode.RemoveUnicode(x.ShipAddress.ToLower()).Contains(str)); break; } switch (status) { case 0: break; //tất cả case 1: model = model.Where(x => x.Status == 1); break; //đơn mới case 2: model = model.Where(x => x.Status == 2); break; //đang giao case 3: model = model.Where(x => x.Status == 3); break; //đã giao } int totalRow = model.Count(); model = model.OrderByDescending(x => x.ID) .Skip((pageIndex - 1) * pageSize) .Take(pageSize); int totalRowCurent = model.Count(); return(Json(new { data = model, total = totalRow, totalCurent = totalRowCurent, status = true }, JsonRequestBehavior.AllowGet)); }
// AJAX: Get Chart datas public JsonResult GetChartData() { // Find current user Id int patienId = User.Identity.GetUserId <int>(); //Get current user Id if (patienId <= 0) { patienId = 1021; } // Get list of all orders of current user var models = new OrderDao().GetHistories(patienId).ToList(); List <object> dataset = new List <object>(); var labels = new List <string>(); var lowPress = new List <int>(); var highPress = new List <int>(); var heartBeat = new List <int>(); var gpt = new List <int>(); var insulin = new List <int>(); var cholesteron = new List <int>(); // Loop through all order to add datas for (var i = 0; i < models.Count(); i++) { labels.Add(((DateTime)models[i].CreatedDate).ToString("dd/MM/yy")); foreach (var param in models[i].ClinicalParams) { if (param.CodeName.Equals("HeartBeat")) { heartBeat.Add((int)param.Value); } if (param.CodeName.Equals("LowPressure")) { lowPress.Add((int)param.Value); } if (param.CodeName.Equals("HighPressure")) { highPress.Add((int)param.Value); } if (param.CodeName.Equals("GPT")) { lowPress.Add((int)param.Value); } if (param.CodeName.Equals("Insulin")) { highPress.Add((int)param.Value); } if (param.CodeName.Equals("Cholesteron")) { highPress.Add((int)param.Value); } } foreach (var param in models[i].ParaclinicalParams) { if (param.CodeName.Equals("GPT")) { gpt.Add((int)param.Value); } if (param.CodeName.Equals("Insulin")) { insulin.Add((int)param.Value); } if (param.CodeName.Equals("Cholesteron")) { cholesteron.Add((int)param.Value); } } // if one has null value, add zero to it if (heartBeat.Count < i + 1) { heartBeat.Add(0); } if (lowPress.Count < i + 1) { lowPress.Add(0); } if (highPress.Count < i + 1) { highPress.Add(0); } if (gpt.Count < i + 1) { gpt.Add(0); } if (cholesteron.Count < i + 1) { cholesteron.Add(0); } if (insulin.Count < i + 1) { insulin.Add(0); } } dataset.Add(labels); dataset.Add(heartBeat); dataset.Add(lowPress); dataset.Add(highPress); dataset.Add(gpt); dataset.Add(insulin); dataset.Add(cholesteron); return(Json(new { d = dataset })); }