public async Task <ActionResult> List(DataSourceRequest command, SearchIssueModel model)
        {
            //var type = (IssueType)model.Type;
            // Works
            DateTime dateSearch = DateTime.Parse(model.Datetime, CultureInfo.InvariantCulture);

            //var userId = _workContext.CurrentUser.IsAdmin() ? 0 : _workContext.CurrentUser.Id;
            //var issues = await _issueService.SearchIssues(new List<int>{userId}, searchKeyword:model.SearchKeyword, createdDate:dateSearch, departmentId:7);

            var        includeUserCreated = false;
            List <int> users = null;
            //if (_workContext.CurrentUser != null && !_workContext.CurrentUser.IsAdmin())
            //{
            //    users = new List<int> { _workContext.CurrentUser.Id };
            //    includeUserCreated = true;
            //}
            //else
            //    users = String.IsNullOrEmpty(model.UserId) ? null : model.UserId.Split(',').Select(int.Parse).ToList();

            var issues = await _issueService.SearchIssues(false, users, includeUserCreated, searchKeyword : model.SearchKeyword, createdDate : dateSearch, departmentId : 7, pageIndex : command.Page - 1, pageSize : command.PageSize);

            var listIssueModel = issues.Select(p => new IssueModel()
            {
                Id             = p.Id,
                Content        = p.Content,
                CreatedDate    = p.CreatedDate.ToShortDateString(),
                NextStep       = p.NextStep,
                Status         = p.IssueStatus.ToString(),
                StatusId       = (int)p.IssueStatus,
                UserCreated    = p.User.Username,
                UserAssigned   = p.UserOwner.Username,
                UserAssignedId = p.UserOwnerId,
                //Type = p.IssueType.ToString(),
                ActionPlan          = p.ActionPlan,
                When                = p.When,
                Note                = p.Note,
                SystemFixDMSLinkage = p.SystemFixDmsLinkage,
                WhenDue             = p.WhenDue.ToShortDateString()
            });

            var result = new DataSourceResult()
            {
                Data  = listIssueModel,   // Process data (paging and sorting applied)
                Total = issues.TotalCount // Total number of records
            };

            // Return the result as JSON
            return(Json(result));
        }
        public async Task <ActionResult> ManageList(DataSourceRequest command, SearchIssueModel model)
        {
            var issues = new List <Issue>();

            if (_workContext.CurrentUser == null || _workContext.CurrentUser.IsAdmin())
            {
                issues = await _issueService.GetAllIssues();

                if (!String.IsNullOrEmpty(model.SearchKeyword))
                {
                    issues = issues.Where(p => (p.ActionPlan != null && p.ActionPlan.Contains(model.SearchKeyword)) || (p.Content != null && p.Content.Contains(model.SearchKeyword)))
                             .ToList();
                }
                if (!String.IsNullOrEmpty(model.UserId))
                {
                    var lstUser = Enumerable.Cast <int>(model.UserId.Split(',')).ToList();
                    issues = await _issueService.GetIssuesOfListUser(lstUser);

                    if (!String.IsNullOrEmpty(model.SearchKeyword))
                    {
                        issues = issues.Where(p => (p.ActionPlan != null && p.ActionPlan.Contains(model.SearchKeyword)) || (p.Content != null && p.Content.Contains(model.SearchKeyword)))
                                 .ToList();
                    }
                }
                if (!String.IsNullOrEmpty(model.Status))
                {
                    var lstStatus = model.Status.Split(',');
                    var lstResult = new List <Issue>();
                    foreach (var item in lstStatus)
                    {
                        if (!String.IsNullOrEmpty(item))
                        {
                            var status       = (IssueStatus)int.Parse(item);
                            var resultIssues = issues.Where(p => p.IssueStatus == status)
                                               .ToList();
                            lstResult.AddRange(resultIssues);
                        }
                    }
                    issues = lstResult;
                }
                if (model.Type > 0)
                {
                    //khang comment var type = (IssueType)model.Type;
                    //issues = issues.Where(p => p.IssueType == type)
                    // .ToList();
                }
            }
            else
            {
                issues = _workContext.CurrentUser.CreatedIssues.ToList();
                if (!String.IsNullOrEmpty(model.SearchKeyword))
                {
                    issues = issues.Where(p => (p.ActionPlan != null && p.ActionPlan.Contains(model.SearchKeyword)) || (p.Content != null && p.Content.Contains(model.SearchKeyword)))
                             .ToList();
                }
                if (!String.IsNullOrEmpty(model.Status))
                {
                    var lstStatus = model.Status.Split(',');
                    var lstResult = new List <Issue>();
                    foreach (var item in lstStatus)
                    {
                        if (!String.IsNullOrEmpty(item))
                        {
                            var status       = (IssueStatus)int.Parse(item);
                            var resultIssues = issues.Where(p => p.IssueStatus == status)
                                               .ToList();
                            lstResult.AddRange(resultIssues);
                        }
                    }
                    issues = lstResult;
                }
                if (model.Type > 0)
                {
                    //khang comment var type = (IssueType)model.Type;
                    //issues = issues.Where(p => p.IssueType == type)
                    //   .ToList();
                }
            }

            issues = issues.OrderByDescending(p => p.WhenDue).ToList();
            var listIssueModel = issues.AsEnumerable().Select((p, i) => new IssueModel()
            {
                Index          = i + 1,
                Id             = p.Id,
                Content        = p.Content,
                CreatedDate    = p.CreatedDate.ToShortDateString(),
                UpdatedDate    = p.UpdatedDate.ToShortDateString(),
                NextStep       = p.NextStep,
                Status         = p.IssueStatus.ToString(),
                StatusId       = p.IssueStatusId,
                UserCreated    = p.User.Username,
                UserAssigned   = p.UserOwner.Username,
                UserAssignedId = p.UserOwnerId,
                //Type = p.IssueType.ToString(),
                //TypeId =p.IssueTypeId.ToString(),
                ActionPlan          = p.ActionPlan,
                When                = p.When,
                Note                = p.Note,
                WhenDue             = p.WhenDue.ToShortDateString(),
                SystemFixDMSLinkage = p.SystemFixDmsLinkage,
                IssuesPriority      = p.IssuesPriority
            }).AsQueryable();



            // Calculate the total number of records before paging
            var total = listIssueModel.Count();


            // Apply paging
            if (command.Page > 0)
            {
                listIssueModel = listIssueModel.Skip((command.Page - 1) * command.PageSize);
            }
            listIssueModel = listIssueModel.Take(command.PageSize);

            var result = new DataSourceResult()
            {
                Data  = listIssueModel.AsEnumerable(), // Process data (paging and sorting applied)
                Total = total                          // Total number of records
            };

            // Return the result as JSON
            return(Json(result));
        }