Esempio n. 1
0
        public IActionResult ContentList(SearchPaginationListModel searchModel)
        {
            try
            {
                if (searchModel.pageNo <= 0)
                {
                    searchModel.pageNo = 1;
                }
                var contentList = iContent.ContentDetails(searchModel.searchString);
                if (contentList != null)
                {
                    List <ContentDetails> contentDetailsResult = new List <ContentDetails>();

                    #region Sorting
                    if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortContentType.contentid)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.asc)))
                    {
                        contentDetailsResult = contentList.OrderBy(x => x.ContentId).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortContentType.name)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.desc)))
                    {
                        contentDetailsResult = contentList.OrderByDescending(x => x.Name).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortContentType.contentid)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.desc)))
                    {
                        contentDetailsResult = contentList.OrderByDescending(x => x.ContentId).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortContentType.name)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.asc)))
                    {
                        contentDetailsResult = contentList.OrderBy(x => x.Name).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else
                    {
                        contentDetailsResult = contentList.OrderBy(x => x.ContentId).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    #endregion

                    ////var contentPagedResult = contentList.OrderByDescending(x => x.ContentId).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    List <AddContentModel>          addContentModelList = ContentHelper.BindAddContentModel(contentDetailsResult);
                    PagedListModel <ContentDetails> pagedListModel      = new PagedListModel <ContentDetails>();
                    pagedListModel.Items = contentDetailsResult.ToList();
                    pagedListModel.Total = DBHelper.ParseInt32(contentList.Count);
                    return(Ok(ResponseHelper.Success(pagedListModel)));
                }
                else
                {
                    return(Ok(ResponseHelper.Error(MessageConstants.ContentNotFound)));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
                return(Ok(ResponseHelper.Error(ex.Message)));
            }
        }