/// <summary> /// 取得 Blog /// </summary> /// <param name="blogQueryDto">查詢條件</param> /// <returns></returns> public async Task <IEnumerable <BlogDto> > GetAsync(BlogQueryDto blogQueryDto) { var blogs = await this._blogRepository.GetAllAsync(); // Convert Blog to BlogDto var blogDtos = this._mapper.Map <IEnumerable <BlogDto> >(blogs); return(blogDtos); }
/// <summary> /// 取得特定數量 Blog /// </summary> /// <param name="dto"></param> /// <returns></returns> public IEnumerable <BlogDto> GetRange(BlogQueryDto dto) { using (ProfilingSession.Current.Step($"{nameof(BlogService)} - {nameof(GetRange)}")) { var blogs = this._blogRepository.GetAll(); // 有帶起迄筆數的篩選 if (dto.Start < 0 || dto.End < 0) { throw new Exception("起迄參數有為 0"); } else { var skipCount = dto.Start - 1; var takeCount = dto.End - dto.Start + 1; blogs = blogs.Skip(skipCount).Take(takeCount); } var dtos = this._mapper.Map <List <BlogDto> >(blogs); return(dtos); } }