Example #1
0
        public JsonResult GetRequestsHistory([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel, String RequestId)
        {
            string userkey     = ConfigurationManager.AppSettings["userkey"];
            string uid         = ConfigurationManager.AppSettings["uid"];
            string LoginUser   = (string)Session["LoginSAPID"];
            string _access_key = ConfigurationManager.AppSettings["Salt"];

            try
            {
                Employer.Employer employer   = new Employer.Employer();
                string            dRequestId = CryptoEngine.DecryptString(RequestId, _access_key);
                string            request_ID = dRequestId.Replace(' ', '+');

                DataTable dt = employer.FetchAssignmentHistory(dRequestId, userkey, uid);
                dt.TableName = "RequestsHistory";
                dt.Columns.ToString();

                List <RequestsHistory> requestsHistory = new List <RequestsHistory>();
                int startRec = requestModel.Start;
                int pageSize = requestModel.Length;


                List <RequestsHistory> requestCount = (from DataRow dr in dt.Rows
                                                       select new RequestsHistory()
                {
                    RequestID = dr["RequestID"].ToString()
                }).ToList();

                requestsHistory = (from DataRow dr in dt.Rows
                                   orderby dr["AssignDate"] descending
                                   select new RequestsHistory()
                {
                    RequestID = dr["RequestID"].ToString(),
                    HistoryID = dr["HistoryID"].ToString(),
                    Comment = dr["Comment"].ToString(),
                    Assignee = dr["Assignee"].ToString(),
                    Assignor = dr["Assignor"].ToString(),
                    AssignDate = Convert.ToDateTime(dr["AssignDate"]).ToString("dd-MMM-yyyy hh:mm"),
                    AssignStatus = dr["AssignStatus"].ToString()
                }).Skip(startRec).Take(pageSize).ToList();

                var totalCount    = requestCount.Count();
                var filteredCount = requestsHistory.Count();

                if (requestModel.Search.Value != string.Empty)
                {
                    var value = requestModel.Search.Value.Trim();

                    requestCount = (from DataRow dr in dt.Rows
                                    where dr["RequestID"].ToString().Contains(value) || dr["Assignee"].ToString().Contains(value) ||
                                    dr["Assignor"].ToString().Contains(value) || Convert.ToDateTime(dr["AssignDate"]).ToString("dd-MMM-yyyy hh:mm").Contains(value) ||
                                    dr["Assignee"].ToString().Contains(value) || dr["AssignStatus"].ToString().Contains(value)
                                    select new RequestsHistory()
                    {
                        RequestID = dr["RequestID"].ToString()
                    }).ToList();

                    requestsHistory = (from DataRow dr in dt.Rows
                                       orderby dr["AssignDate"] descending
                                       where dr["RequestID"].ToString().Contains(value) || dr["Assignee"].ToString().Contains(value) ||
                                       dr["Assignor"].ToString().Contains(value) || Convert.ToDateTime(dr["AssignDate"]).ToString("dd-MMM-yyyy hh:mm").Contains(value) ||
                                       dr["Assignee"].ToString().Contains(value) || dr["AssignStatus"].ToString().Contains(value)
                                       select new RequestsHistory()
                    {
                        RequestID = dr["RequestID"].ToString(),
                        HistoryID = dr["HistoryID"].ToString(),
                        Comment = dr["Comment"].ToString(),
                        Assignee = dr["Assignee"].ToString(),
                        Assignor = dr["Assignor"].ToString(),
                        AssignDate = Convert.ToDateTime(dr["AssignDate"]).ToString("dd-MMM-yyyy hh:mm"),
                        AssignStatus = dr["AssignStatus"].ToString()
                    }).Skip(startRec).Take(pageSize).ToList();

                    totalCount    = requestCount.Count();
                    filteredCount = requestsHistory.Count();
                }

                var sortedColumns = requestModel.Columns.GetSortedColumns();
                var orderByString = String.Empty;

                foreach (var column in sortedColumns)
                {
                    orderByString += orderByString != String.Empty ? "," : "";
                    orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc");
                }

                var data = requestsHistory.Select(emList => new
                {
                    RequestID    = emList.RequestID,
                    HistoryID    = emList.HistoryID,
                    Comment      = emList.Comment,
                    Assignee     = emList.Assignee,
                    Assignor     = emList.Assignor,
                    AssignDate   = emList.AssignDate,
                    AssignStatus = emList.AssignStatus
                }).OrderBy(orderByString == string.Empty ? "ID asc" : orderByString).ToList();

                return(Json(new DataTablesResponse(requestModel.Draw, data, totalCount, totalCount), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogError logerror = new LogError();
                logerror.ErrorLog("", LoginUser, "", "Requests/GetRequests", "Requests", "GetRequests", "FetchIncidents Error", ex.Message.ToString(), 0);
                return(Json(new { data = "Error has occured" }, JsonRequestBehavior.AllowGet));
            }
        }