public async Task <IActionResult> GetUnapprovedAnnouncements([FromQuery] AnnouncementParams announcementParams) { var announcements = await _announcementService.GetUnapprovedAnnouncements(announcementParams); var announcementsForReturn = _mapper.Map <IEnumerable <AnnouncementForList> >(announcements); Response.AddPagination(announcements.CurrentPage, announcements.PageSize, announcements.TotalCount, announcements.TotalPages); return(Ok(announcementsForReturn)); }
public async Task <PagedList <Announcement> > GetUnapprovedAnnouncements(AnnouncementParams announcementParams) { var announcements = _context.Announcements .IgnoreQueryFilters() .Include(a => a.Photos) .Include(a => a.Subcategory) .Where(a => a.IsApproved == false) .AsQueryable(); //if (!string.IsNullOrEmpty(userParams.Username)) //{ // users = users.Where(u => u.UserName.Contains(userParams.Username)); //} announcements = announcements.OrderBy(a => a.AddedOn); return(await PagedList <Announcement> .CreateAsync(announcements, announcementParams.PageNumber, announcementParams.PageSize)); }
public async Task <IActionResult> GetAnnouncementsByUserId([FromQuery] AnnouncementParams announcementParams) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (userId == null) { return(Unauthorized()); } var announcements = await _announcementService.GetAnnouncementsByUserId(userId, announcementParams); var announcementsForReturn = _mapper.Map <IEnumerable <AnnouncementForList> >(announcements); Response.AddPagination(announcements.CurrentPage, announcements.PageSize, announcements.TotalCount, announcements.TotalPages); return(Ok(announcementsForReturn)); }
public async Task <PagedList <Announcement> > GetAnnouncementsByUserId(string userId, AnnouncementParams announcementParams) { var announcements = _context.Announcements .IgnoreQueryFilters() .Where(a => a.PostedById == userId) .Include(a => a.Photos) .Include(a => a.Subcategory) .AsQueryable(); announcements = announcements.OrderByDescending(a => a.AddedOn); return(await PagedList <Announcement> .CreateAsync(announcements, announcementParams.PageNumber, announcementParams.PageSize)); }
public async Task <PagedList <Announcement> > GetAnnouncementsBySubcategory(string subcategoryName, AnnouncementParams announcementParams) { var announcements = _context.Announcements .Include(a => a.Photos) .Include(a => a.Subcategory) .Include(a => a.PostedBy) .Where(a => a.Subcategory.Name == subcategoryName) .AsQueryable(); if (!string.IsNullOrEmpty(announcementParams.SearchText)) { announcements = announcements .Where(a => a.Title.Contains(announcementParams.SearchText) || a.Description.Contains(announcementParams.SearchText)); } announcements = announcements.OrderByDescending(a => a.AddedOn); return(await PagedList <Announcement> .CreateAsync(announcements, announcementParams.PageNumber, announcementParams.PageSize)); }