public Dictionary <string, object> getWorkOrders(int pageIndex, int pageSize, string sorting, string search) { Dictionary <string, object> dic = new Dictionary <string, object>(); int LoginUserID = Convert.ToInt32(HttpContext.Current.Session["am_userid"].ToString()); int CompanyID = Convert.ToInt32(HttpContext.Current.Session["cid_SCL_account"].ToString()); try { bool isDate = IsDateTime(search); DateTime dt; if (isDate) { dt = Convert.ToDateTime(search); } Pagenation <SCL_JobCards> complaintList = new Pagenation <SCL_JobCards>(); List <SCL_JobCards> listCmp = new List <SCL_JobCards>(); Func <SCL_JobCards, object> orderBy = complaintList.orderByType2(sorting); listCmp = ((from cd in gc.db.SCL_JobCards where cd.USER_ID == LoginUserID && cd.COMPANY_ID == CompanyID && cd.COMP_STATUS != "Completed" select new { cd })) //.OrderByDescending(s => s.cd.Id)) .ToList() .Select(d => new SCL_JobCards { COMPLAINT_ID = d.cd.COMPLAINT_ID, JC_REFERENCE = d.cd.JC_REFERENCE, COMP_STATUS = d.cd.COMP_STATUS, CATEGORY = d.cd.CATEGORY, SUB_CATEGORY = d.cd.SUB_CATEGORY, DEPARTMENT = d.cd.DEPARTMENT, JC_DATE = d.cd.JC_DATE, ADDRESS = d.cd.ADDRESS, COMP_COMMENTS = d.cd.COMP_COMMENTS, }).AsQueryable().ToList(); if (search != "undefined") { // searching if (!string.IsNullOrWhiteSpace(search)) { if (isDate) { dt = Convert.ToDateTime(search); listCmp = listCmp.Where(x => DateTime.Compare(x.JC_DATE.Date, dt.Date) <= 0).ToList(); } else { listCmp = listCmp.Where(x => (x.JC_REFERENCE.ToUpper() ?? "").Contains(search.ToUpper()) || (x.CATEGORY.ToUpper() ?? "").Contains(search.ToUpper()) || (x.SUB_CATEGORY.ToUpper() ?? "").Contains(search.ToUpper()) || (x.DEPARTMENT.ToUpper() ?? "").Contains(search.ToUpper()) || (x.COMP_STATUS.ToUpper() ?? "").Contains(search.ToUpper()) ).ToList(); } } } complaintList.totalCount = listCmp.Count().ToString(); listCmp = listCmp.OrderBy(orderBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).AsQueryable().ToList(); complaintList.complaints = listCmp; if (listCmp.Count() > 0) { dic.Add("success", complaintList); } else { dic.Add("success", "No results found!"); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } dic.Add("error", raise.Message); } return(dic); }
public Dictionary <string, object> getMapAssignedComplaints() { Dictionary <string, object> dic = new Dictionary <string, object>(); int LoginUserID = Convert.ToInt32(HttpContext.Current.Session["am_userid"].ToString()); int CompanyID = Convert.ToInt32(HttpContext.Current.Session["cid_SCL_account"].ToString()); try { Pagenation <Map_Jobcards> complaintList = new Pagenation <Map_Jobcards>(); List <Map_Jobcards> listCmp = new List <Map_Jobcards>(); Func <SCL_JobCards, object> orderBy = complaintList.orderByType2("JC_DATE"); listCmp = ((from cd in gc.db.SCL_JobCards where cd.USER_ID == LoginUserID && cd.COMPANY_ID == CompanyID && cd.COMP_STATUS != "Completed" select new { cd })) //.OrderByDescending(s => s.cd.Id)) .ToList() .Select(d => new Map_Jobcards { COMPLAINT_ID = d.cd.COMPLAINT_ID, JC_REFERENCE = d.cd.JC_REFERENCE, COMP_STATUS = d.cd.COMP_STATUS, CATEGORY = d.cd.CATEGORY, SUB_CATEGORY = d.cd.SUB_CATEGORY, DEPARTMENT = d.cd.DEPARTMENT, JC_DATE = d.cd.JC_DATE, ADDRESS = d.cd.ADDRESS, COMP_COMMENTS = d.cd.COMP_COMMENTS, LAT = gc.db.SCL_Mobile_Complaints.FirstOrDefault(x => x.ID == d.cd.COMPLAINT_ID).Lattitude, LONG = gc.db.SCL_Mobile_Complaints.FirstOrDefault(x => x.ID == d.cd.COMPLAINT_ID).Longitude, }).AsQueryable().ToList(); complaintList.totalCount = listCmp.Count().ToString(); complaintList.complaints = listCmp; if (listCmp.Count() > 0) { dic.Add("success", complaintList); } else { dic.Add("error", "No results found!"); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } dic.Add("error", raise.Message); } return(dic); }