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> getReceivedComplaints(int pageIndex, int pageSize, string sorting, string search) { Dictionary <string, object> dic = new Dictionary <string, object>(); 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_Mobile_Complaints> complaintList = new Pagenation <SCL_Mobile_Complaints>(); List <SCL_Mobile_Complaints> listCmp = new List <SCL_Mobile_Complaints>(); Func <SCL_Mobile_Complaints, object> orderBy = complaintList.orderByType1("ID"); listCmp = ((from cd in gc.db.SCL_Mobile_Complaints.Where(x => x.CompanyID == CompanyID && (x.ComplaintStatus == "Received" || x.ComplaintStatus == "Reallocate" || x.ComplaintStatus == "Redirect")) select new { cd })) //.OrderByDescending(s => s.cd.Id)) .AsEnumerable() .Select(d => new SCL_Mobile_Complaints { ID = d.cd.ID, Complaint_ReferenceNo = d.cd.Complaint_ReferenceNo, ComplaintStatus = d.cd.ComplaintStatus, Category_Desc = d.cd.Category_Desc, SubCategory_Desc = d.cd.SubCategory_Desc, Dept_Desc = d.cd.Dept_Desc, Complaint_Date = d.cd.Complaint_Date, Address = d.cd.Address, automatic_complaint = d.cd.automatic_complaint, Comments = d.cd.Comments, JC_REF = d.cd.JC_REF, img_data = gc.db.SCL_ComplaintImages.Where(x => x.Complaint_ReferenceNo == d.cd.Complaint_ReferenceNo).FirstOrDefault() != null ? gc.db.SCL_ComplaintImages.Where(x => x.Complaint_ReferenceNo == d.cd.Complaint_ReferenceNo).FirstOrDefault().AttachmentName : "" }).AsQueryable().ToList(); if (search != "undefined") { // searching if (!string.IsNullOrWhiteSpace(search)) { if (isDate) { dt = Convert.ToDateTime(search); listCmp = listCmp.Where(x => DateTime.Compare(x.CreatedDate.Value.Date, dt.Date) <= 0).ToList(); } else { listCmp = listCmp.Where(x => (x.Complaint_ReferenceNo.ToUpper() ?? "").Contains(search.ToUpper()) || (x.Category_Desc.ToUpper() ?? "").Contains(search.ToUpper()) || (x.SubCategory_Desc.ToUpper() ?? "").Contains(search.ToUpper()) || (x.Dept_Desc.ToUpper() ?? "").Contains(search.ToUpper()) || (x.ComplaintStatus.ToUpper() ?? "").Contains(search.ToUpper()) ).ToList(); } } } complaintList.totalCount = listCmp.Count().ToString(); listCmp = listCmp.OrderByDescending(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); }