Пример #1
0
        public async Task <JsonResult> GetAsync(string id)
        {
            WikiPassage wikiPassage = await this._wikiPassageService.GetByRoutePathAsync(id);

            WikiPassageDto wikiPassageDto = new WikiPassageDto().ConvertFromDataModel(wikiPassage);

            wikiPassageDto.AnchorTitles = await this._wikiPassageService.CollectAnchorTitlesAsync(wikiPassageDto.Content);

            wikiPassageDto.MainAuthors = this._userInfoService.CollectAuthorInfoes(wikiPassage.MainAuthors.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
            wikiPassageDto.CoAuthors   = wikiPassage.CoAuthors != null?this._userInfoService.CollectAuthorInfoes(wikiPassage.CoAuthors?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) : null;

            wikiPassageDto.BreadCrumbs          = wikiPassage.ParentPassageId != 0 ? this._wikiPassageService.CollectBreadCrumbs(wikiPassageDto) : null;
            wikiPassageDto.ChildPageBreadCrumbs = await this._wikiPassageService.CollectChildPageBreadCrumbs(wikiPassageDto);

            int editingUserId = this._wikiPassageService.GetEditingUserId(wikiPassageDto.Id);

            wikiPassageDto.EditingUser = editingUserId == 0 ? null : new UserInfoDto().ConvertFromDataModel(this._userInfoService.GetById(editingUserId));

            //
            //此处是有意不做等待的,阅读量的统计不应当影响文本内容的返回。

            TaskAwaiter taskAwaiter = Task.Run(() =>
            {
                this._wikiPassageService.AddViewsCount(wikiPassageDto.Id, base.HttpContext.Connection.RemoteIpAddress);
            }).GetAwaiter();

            return(new JsonResult(wikiPassageDto));
        }
Пример #2
0
        public async Task TestBaseServiceDbWrite_ShouldCreateAsync()
        {
            var service = new WikiPassageService();

            await service.AddAsync(BuildOneEntity());

            WikiPassage passage = service.GetById(1);

            Assert.NotNull(passage);
        }
Пример #3
0
        public async Task <IActionResult> Post(WikiPassageDto wikiPassageDto)
        {
            Ensure.NotNull(wikiPassageDto, nameof(wikiPassageDto));

            WikiPassage wikiPassage = await this._wikiPassageService.Create(wikiPassageDto);

            wikiPassageDto = new WikiPassageDto().ConvertFromDataModel(wikiPassage);

            return(Json(wikiPassageDto));
        }
Пример #4
0
        private WikiPassage BuildOneEntity()
        {
            WikiPassage passage = new WikiPassage();

            passage.Title          = "功能介绍";
            passage.Content        = "这是第一篇维基内容";
            passage.CreateDate     = DateTime.Now;
            passage.LastModifyDate = DateTime.Now;

            return(passage);
        }
Пример #5
0
        public async Task <JsonResult> GetAsync(string id)
        {
            string      routePath   = id;
            WikiPassage wikiPassage = await this._wikiPassageService.GetByRoutePathAsync(id);

            WikiPassageDto wikiPassageDto = new WikiPassageDto().ConvertFromDataModel(wikiPassage);

            wikiPassageDto.AnchorTitles = await CollectAnchorTitlesAsync(wikiPassageDto.Content);

            return(new JsonResult(wikiPassageDto));
        }
Пример #6
0
        public async Task <IActionResult> PostAsync([FromBody] WikiPassageDto dto)
        {
            dto.MainAuthors = new List <UserInfoDto> {
                base.CurrentUser
            };
            WikiPassage wikiPassage = await this._wikiPassageService.Create(dto);

            WikiPassageDto wikiPassageDto = new WikiPassageDto().ConvertFromDataModel(wikiPassage);

            return(Json(wikiPassageDto));
        }
Пример #7
0
        public async Task TestBaseServiceDbUpdate_ShouldUpdate()
        {
            WikiPassageService service = new WikiPassageService();
            await service.AddAsync(BuildOneEntity());

            WikiPassage passage = service.GetById(1);

            passage.Content = "这是修改后的内容";

            await service.UpdateAsync(passage);

            Assert.True(service.GetById(1).Content == "这是修改后的内容");
        }
Пример #8
0
        public async Task TestBaseServiceDbDelte_ShouldDeleteAsync()
        {
            WikiPassageService service = new WikiPassageService();
            await service.AddAsync(BuildOneEntity());

            WikiPassage passageToFind = service.GetById(1);

            await service.DeleteByIdAsync(1);

            WikiPassage passage = service.GetById(1);

            Assert.NotNull(passageToFind);
            Assert.Null(passage);
        }