コード例 #1
0
        /// <summary>
        /// Creates the new page.
        /// </summary>
        public async Task <Page> CreateAsync(PageEditorVM vm, ClaimsPrincipal principal)
        {
            await ValidateRequestAsync(vm);

            var key             = PageHelper.EncodeTitle(vm.Title);
            var existingRemoved = await _db.Pages
                                  .Where(x => x.Key == key && x.IsDeleted == true)
                                  .Select(x => new { x.Id })
                                  .FirstOrDefaultAsync();

            if (existingRemoved != null)
            {
                return(await UpdateAsync(vm, principal, pageId : existingRemoved.Id));
            }

            var page = _mapper.Map <Page>(vm);

            page.Id           = Guid.NewGuid();
            page.CreationDate = DateTimeOffset.Now;
            page.MainPhoto    = await FindMainPhotoAsync(vm.MainPhotoKey);

            await _validator.ValidateAsync(page, vm.Facts);

            var changeset = await GetChangesetAsync(null, _mapper.Map <PageEditorVM>(page), page.Id, principal, null);

            _db.Changes.Add(changeset);

            _db.Pages.Add(page);
            _db.PageAliases.AddRange(GetPageAliases(vm.Aliases, vm.Title, page));
            _db.PageReferences.AddRange(await GetPageReferencesAsync(vm.Description, page));

            await DiscardPageDraftAsync(null, principal);

            return(page);
        }
コード例 #2
0
ファイル: PagesManagerService.cs プロジェクト: hbrtv/bonsai
        /// <summary>
        /// Creates the new page.
        /// </summary>
        public async Task <Page> CreateAsync(PageEditorVM vm, ClaimsPrincipal principal)
        {
            await ValidateRequestAsync(vm);

            var key             = PageHelper.EncodeTitle(vm.Title);
            var existingRemoved = await _db.Pages
                                  .Where(x => x.Key == key && x.IsDeleted == true)
                                  .Select(x => new { x.Id })
                                  .FirstOrDefaultAsync();

            if (existingRemoved != null)
            {
                return(await UpdateAsync(vm, principal, pageId : existingRemoved.Id));
            }

            var page = _mapper.Map <Page>(vm);

            page.Id           = Guid.NewGuid();
            page.CreationDate = DateTimeOffset.Now;
            page.MainPhoto    = await FindMainPhotoAsync(vm.MainPhotoKey);

            await _validator.ValidateAsync(page, vm.Facts);

            var changeset = await GetChangesetAsync(null, vm, page.Id, principal, null);

            _db.Changes.Add(changeset);

            _db.Pages.Add(page);

            var aliasValues = JsonConvert.DeserializeObject <List <string> >(vm.Aliases ?? "[]");

            if (!aliasValues.Contains(vm.Title))
            {
                aliasValues.Add(vm.Title);
            }

            _db.PageAliases.AddRange(
                aliasValues.Select((x, idx) =>
                                   new PageAlias
            {
                Id    = Guid.NewGuid(),
                Page  = page,
                Key   = PageHelper.EncodeTitle(x).ToLowerInvariant(),
                Title = x,
                Order = idx
            }
                                   )
                );

            await DiscardPageDraftAsync(null, principal);

            return(page);
        }
コード例 #3
0
        /// <summary>
        /// Creates the new page.
        /// </summary>
        public async Task <Page> CreateAsync(PageEditorVM vm, ClaimsPrincipal principal)
        {
            await ValidateRequestAsync(vm);

            var page = _mapper.Map <Page>(vm);

            page.Id           = Guid.NewGuid();
            page.CreationDate = DateTimeOffset.Now;
            page.MainPhoto    = await FindMainPhotoAsync(vm.MainPhotoKey);

            await _validator.ValidateAsync(page, vm.Facts);

            var changeset = await GetChangesetAsync(null, vm, page.Id, principal, null);

            _db.Changes.Add(changeset);

            _db.Pages.Add(page);

            var aliasValues = JsonConvert.DeserializeObject <List <string> >(vm.Aliases ?? "[]");

            if (!aliasValues.Contains(vm.Title))
            {
                aliasValues.Add(vm.Title);
            }

            _db.PageAliases.AddRange(
                aliasValues.Select((x, idx) =>
                                   new PageAlias
            {
                Id    = Guid.NewGuid(),
                Page  = page,
                Key   = PageHelper.EncodeTitle(x).ToLowerInvariant(),
                Title = x,
                Order = idx
            }
                                   )
                );

            _cache.Remove <TreeVM>();

            await DiscardPageDraftAsync(null, principal);

            return(page);
        }