public virtual async Task <PostWithDetailsDto> GetForReadingAsync(GetPostInput input) { return(await RequestAsync <PostWithDetailsDto>(nameof(GetForReadingAsync), new ClientProxyRequestTypeValue { { typeof(GetPostInput), input } })); }
public async Task <GetPostOutput> GetById(GetPostInput input) { var entity = await _manager.GetById(input.Id); if (entity == null) { throw new UserFriendlyException($"Post {input.Id} not found"); } return(ObjectMapper.Map <GetPostOutput>(entity)); }
public async Task <IReadOnlyList <GetTagOutput> > GetPostTags(GetPostInput input) { var entity = await _manager.GetById(input.Id); if (entity == null) { throw new UserFriendlyException($"Post {input.Id} not found"); } return(entity.Tags.Select(ObjectMapper.Map <GetTagOutput>).ToList()); }
public async Task <double> GetPostRating(GetPostInput input) { return((await _manager.GetById(input.Id))?.Rating ?? 0); }
public Task <PostWithDetailsDto> GetForReadingAsync(GetPostInput input) { return(_postAppService.GetForReadingAsync(input)); }
public async Task<GetCategoryOutput> GetCategoriesByPostId(GetPostInput input) { Guid postId = input.IdOrEntryName.ToGuid(); var post = (await this._postRepository.GetPostByWhere(w => w.Id == postId)).FirstOrDefault(); var categories = post.Categories; return new GetCategoryOutput { CategoryCollection = categories.MapTo<IReadOnlyList<CategoryDto>>() }; }
/// <summary> /// 根据文章Id或文章友好地址获取文章 /// </summary> /// <param name="idOrentryName">文章的Id或者友好地址</param> /// <returns></returns> public async Task<GetPostOutput> GetPostByIdOrEntryName(GetPostInput input) { string idOrentryName = input.IdOrEntryName; if (idOrentryName.IsNullOrEmpty()) throw new HttpException(404, "Not Found"); Guid guidId; Post post = null; if (Guid.TryParse(idOrentryName, out guidId)) { //Id var postIEnumable = await this._postRepository.GetPostByWhere(w => w.Id == guidId); post = postIEnumable.FirstOrDefault(); } else { //EntryName var postIEnumable = await this._postRepository.GetPostByWhere(w => w.EntryName.ToLower() == idOrentryName.ToLower()); post = postIEnumable.FirstOrDefault(); } //校验获取的数据 if (post == null) throw new HttpException(404, "Not Found"); post.PVCount++;//TODOL:文章的访问量。目前是自加1 以后根据用户ip计算 return new GetPostOutput { Post = post.MapTo<PostDto>() }; }