Sandeep Kumar

Sandeep Kumar

  • 1.1k
  • 683
  • 60.8k

i want to implement paging in this api,how

Feb 9 2023 9:27 AM
async Task<List<ContentData>> IMaterialManager.GetContentDetailsWithPaging(int PageNo, int PazeSize)
{
    var UserRole = _authenticationManager.GetAuthenticatedUser().Result.RoleId;
    var UserId = _authenticationManager.GetAuthenticatedUser().Result.UserId;
    List<ContentData> ContentDtls = new List<ContentData>();
    try
    {
        if (UserRole == 3)
        {

            var MaxVersionData = from ContentDetails in _dbContext.ContentDetails
                                 join VersionDetails in _dbContext.VersionDetails on ContentDetails.Id equals VersionDetails.ContentId
                                 join MstStage in _dbContext.MstStage on ContentDetails.Status equals MstStage.Id
                                 where ContentDetails.FacultyId == UserId && ContentDetails.Status == 0
                                 select new
                                 {
                                     VersionDetails.ContentId,
                                     ContentDetails.Id,
                                     ContentDetails.DeptId,
                                     ContentDetails.DeptName,
                                     ContentDetails.CourseId,
                                     ContentDetails.CourseName,
                                     ContentDetails.Semester,
                                     ContentDetails.PaperId,
                                     ContentDetails.PaperName,
                                     ContentDetails.ContentTypeId,
                                     ContentDetails.ContenType,
                                     ContentDetails.FacultyId,
                                     ContentDetails.FacultyName,
                                     ContentDetails.Topic,
                                     ContentDetails.LanguageId,
                                     ContentDetails.LanguageName,
                                     MstStage.Mode,
                                     VersionDetails.VersionId,
                                     VersionDetails.VersionName,
                                     VersionDetails.VersionNote,
                                     ContentDetails.CreatedBy,
                                     ContentDetails.CreatedOn,
                                     ContentDetails.ModifiedBy,
                                     ContentDetails.ModifiedOn

                                 };
            var ContentDatas = from ConDtls in MaxVersionData
                               where
                               (from ContentDetails in _dbContext.ContentDetails
                                join VersionDetails in _dbContext.VersionDetails on ContentDetails.Id equals VersionDetails.ContentId
                                where ContentDetails.FacultyId == UserId && ContentDetails.Status == 0
                                group VersionDetails by VersionDetails.ContentId into g
                                select g.Max(x => x.VersionId)).Contains(ConDtls.VersionId)
                               select new
                               {

                                   ContentId = ConDtls.ContentId,
                                   Id = ConDtls.Id,
                                   DeptId = ConDtls.DeptId,
                                   DeptName = ConDtls.DeptName,
                                   CourseId = ConDtls.CourseId,
                                   CourseName = ConDtls.CourseName,
                                   Semester = ConDtls.Semester,
                                   PaperId = ConDtls.PaperId,
                                   PaperName = ConDtls.PaperName,
                                   ContentTypeId = ConDtls.ContentTypeId,
                                   ContenType = ConDtls.ContenType,
                                   FacultyId = ConDtls.FacultyId,
                                   FacultyName = ConDtls.FacultyName,
                                   Topic = ConDtls.Topic,
                                   LanguageId = ConDtls.LanguageId,
                                   LanguageName = ConDtls.LanguageName,
                                   StatusName = ConDtls.Mode,
                                   VersionId = ConDtls.VersionId,
                                   VersionName = ConDtls.VersionName,
                                   VersionNote = ConDtls.VersionNote,
                                   CreatedBy = ConDtls.CreatedBy,
                                   CreatedOn = ConDtls.CreatedOn,
                                   ModifiedBy = ConDtls.ModifiedBy,
                                   ModifiedOn = ConDtls.ModifiedOn
                               };
            ContentDtls = (from ContentInfo in ContentDatas
                           select new
                           {


                               Id = ContentInfo.Id,
                               DeptId = (int)ContentInfo.DeptId,
                               DeptName = ContentInfo.DeptName,
                               CourseId = (int)ContentInfo.CourseId,
                               CourseName = ContentInfo.CourseName,
                               Semester = (int)ContentInfo.Semester,
                               PaperId = (int)ContentInfo.PaperId,
                               PaperName = ContentInfo.PaperName,
                               ContentTypeId = (int)ContentInfo.ContentTypeId,
                               ContenType = ContentInfo.ContenType,
                               FacultyId = (int)ContentInfo.FacultyId,
                               FacultyName = ContentInfo.FacultyName,
                               Topic = ContentInfo.Topic,
                               LanguageId = ContentInfo.LanguageId,
                               LanguageName = ContentInfo.LanguageName,
                               StatusName = ContentInfo.StatusName,
                               VersionId = ContentInfo.VersionId,
                               VersionName = ContentInfo.VersionName,
                               VersionNote = ContentInfo.VersionNote,
                               CreatedBy = (int)ContentInfo.CreatedBy,
                               CreatedOn = ApplicationData.AppDateToString(ContentInfo.CreatedOn) ?? String.Empty,
                               ModifiedBy = (int)ContentInfo.ModifiedBy,
                               ModifiedOn = ApplicationData.AppDateToString(ContentInfo.ModifiedOn) ?? String.Empty
                           }).AsEnumerable().Select((k, index) => new ContentData()
                           {
                               SrlNo = index + 1,
                               ContentId = k.Id,
                               DeptId = k.DeptId,
                               DeptName = k.DeptName,
                               CourseId = (int)k.CourseId,
                               CourseName = k.CourseName,
                               Semester = (int)k.Semester,
                               PaperId = (int)k.PaperId,
                               PaperName = k.PaperName,
                               ContentTypeId = (int)k.ContentTypeId,
                               ContenType = k.ContenType,
                               FacultyId = (int)k.FacultyId,
                               FacultyName = k.FacultyName,
                               Topic = k.Topic,
                               LanguageId = (int)k.LanguageId,
                               LanguageName = k.LanguageName,
                               StatusName = k.StatusName,
                               VersionId = k.VersionId,
                               VersionName = k.VersionName,
                               VersionNote = k.VersionNote,
                               CreatedBy = k.CreatedBy,
                               CreatedOn = k.CreatedOn,
                               ModifiedBy = k.ModifiedBy,
                               ModifiedOn = k.ModifiedOn
                           }).ToList();
        }

       
    }
    catch (Exception ex)
    {

    }
    return await Task.Run(() =>
    {
        return ContentDtls;
    });
}

 


Answers (2)