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

            string WebUserID   = (string)Session["WebUserID"];
            string EMPLOYER_ID = (string)Session["EMPLOYER_ID"];

            try
            {
                Employer.Employer employer = new Employer.Employer();
                DataTable         dt       = employer.FetchIncidents("6", EMPLOYER_ID, "N/A", userkey, uid);
                dt.TableName = "Requests";
                dt.Columns.ToString();

                List <Requests> requests = new List <Requests>();
                int             startRec = requestModel.Start;
                int             pageSize = requestModel.Length;

                //DateTime dateTime10 = Convert.ToDateTime(loginStatus[0].LastLogin);
                //Session["LastLogin"] = dateTime10.ToString("dd-MMM-yyyy hh:mm");

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

                requests = (from DataRow dr in dt.Rows
                            orderby dr["Datecreated"] descending
                            select new Requests()
                {
                    ID = dr["RequestID"].ToString(),
                    RequestID = dr["RequestID"].ToString(),
                    Category = dr["Cat"].ToString(),
                    Comment = dr["Comment"].ToString(),
                    Datecreated = Convert.ToDateTime(dr["Datecreated"]).ToString("dd-MMM-yyyy hh:mm"),
                    CurrentStatus = dr["CurrentStatus"].ToString(),
                    CurrentAssignedToID = dr["CurrentAssignedToID"].ToString(),
                    CurrentAssignedRoleID = dr["CurrentAssignedRoleID"].ToString()
                }).Skip(startRec).Take(pageSize).ToList();

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

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

                    requestCount = (from DataRow dr in dt.Rows
                                    where dr["RequestID"].ToString().ToLower().Contains(value) || dr["Cat"].ToString().ToLower().Contains(value) ||
                                    dr["Datecreated"].ToString().ToLower().Contains(value) || dr["CurrentStatus"].ToString().ToLower().Contains(value)
                                    select new Requests()
                    {
                        RequestID = dr["RequestID"].ToString()
                    }).ToList();

                    requests = (from DataRow dr in dt.Rows
                                orderby dr["Datecreated"] descending
                                where dr["RequestID"].ToString().ToLower().Contains(value) || dr["Cat"].ToString().ToLower().Contains(value) ||
                                Convert.ToDateTime(dr["Datecreated"]).ToString("dd-MMM-yyyy hh:mm").ToLower().Contains(value) ||
                                dr["CurrentStatus"].ToString().ToLower().Contains(value)
                                select new Requests()
                    {
                        RequestID = dr["RequestID"].ToString(),
                        Category = dr["Cat"].ToString(),
                        Comment = dr["Comment"].ToString(),
                        Datecreated = Convert.ToDateTime(dr["Datecreated"]).ToString("dd-MMM-yyyy hh:mm"),
                        CurrentStatus = dr["CurrentStatus"].ToString(),
                        CurrentAssignedToID = dr["CurrentAssignedToID"].ToString(),
                        CurrentAssignedRoleID = dr["CurrentAssignedRoleID"].ToString()
                    }).Skip(startRec).Take(pageSize).ToList();

                    totalCount    = requestCount.Count();
                    filteredCount = requests.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 = requests.Select(emList => new
                {
                    RequestID             = emList.RequestID,
                    Category              = emList.Category,
                    Comment               = emList.Comment,
                    CurrentStatus         = emList.CurrentStatus,
                    Datecreated           = emList.Datecreated,
                    CurrentAssignedToID   = emList.CurrentAssignedToID,
                    CurrentAssignedRoleID = emList.CurrentAssignedRoleID
                }).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));
            }
        }