public async Task <IActionResult> GetPageMain( [FromQuery] GetMainPagePinsDto model ) { try { var responsePayload = await _pinService.GetPageMain(model); return(Ok(responsePayload)); } catch (UnauthorizedAccessException) { return(Unauthorized()); } catch (Exception ex) { return(BadRequest(new { ex.Message })); } }
public async Task <PinsReturnDto> GetPageMain(GetMainPagePinsDto model) { var pinsForPage = (await _pinService.GetAllAsync()) .Include(e => e.BoardPins) .ThenInclude(e => e.Board) .Where(x => x.BoardPins.Any(c => !c.Board.IsPrivate)) .Skip(model.Offset) .Take(model.Take) .Select(e => new { Pin = e.ToPinReturnDto(), IsPrivate = e.BoardPins.Select(i => i.Board).All(ii => ii.IsPrivate), }) //.Where(e => e.IsPrivate == false) .OrderBy(e => e.Pin.Created) .ToList(); var pinsForPageCount = (await _pinService.GetAllAsync()) .Include(e => e.BoardPins) .ThenInclude(e => e.Board) .Count(x => x.BoardPins.Any(c => !c.Board.IsPrivate)); return(pinsForPage.Select(e => e.Pin).OrderByDescending(e => e.Created).ToList().ToPinsReturnDtoExtensions(pinsForPageCount)); }