Пример #1
0
        public async Task AddAsync(int pageId, string area, string controller, string action)
        {
            var page = await _context.Pages.SingleOrDefaultAsync(x => x.PageId == pageId);

            if (page == null)
            {
                return;
            }

            var orderPosition = 0;

            if (page.PageAssociations.Any())
            {
                orderPosition = page.PageAssociations.Max(x => x.PageAssociationOrder + 1);
            }

            var pageAssociation = new PageAssociation
            {
                PageId = page.PageId,
                PageAssociationOrder = orderPosition,
                PagePartial          = new PagePartial
                {
                    RouteArea       = area,
                    RouteController = controller,
                    RouteAction     = action
                }
            };

            _context.PageAssociations.Add(pageAssociation);

            await _context.SaveChangesAsync();
        }
Пример #2
0
        public PageAssociation Add(int pageId, int pageSectionTypeId, string componentStamp)
        {
            var page = _context.Pages.SingleOrDefault(x => x.PageId == pageId);

            if (page == null)
            {
                return(null);
            }

            var sectionType = _context.PageSectionTypes.SingleOrDefault(x => x.PageSectionTypeId == pageSectionTypeId);

            if (sectionType == null)
            {
                return(null);
            }

            var sectionPosition = 1;

            if (page.PageAssociations.Any())
            {
                sectionPosition = page.PageAssociations.Max(x => x.PageAssociationOrder) + 1;
            }

            var newPageAssociation = new PageAssociation
            {
                PageId      = pageId,
                PageSection = new PageSection
                {
                    PageSectionBody = sectionType.PageSectionTypeBody,
                },
                PageAssociationOrder = sectionPosition
            };

            _context.PageAssociations.Add(newPageAssociation);

            _context.SaveChanges();

            var document = new Document(newPageAssociation.PageSection.PageSectionBody);

            newPageAssociation.PageSection.PageSectionBody = Document.ReplaceTokens(newPageAssociation.PageSection.PageSectionBody, newPageAssociation.PageSection.PageSectionId, componentStamp);

            _context.SaveChanges();

            return(newPageAssociation);
        }
        public async Task CloneAsync(int pageAssociationId, int pageId)
        {
            var pageAssociation = await _context.PageAssociations.FirstOrDefaultAsync(pa => pa.PageAssociationId == pageAssociationId);

            if (pageAssociation == null)
            {
                return;
            }

            var page = await _context.Pages.FirstOrDefaultAsync(p => p.PageId == pageId);

            if (page == null)
            {
                return;
            }

            if (pageAssociation.PageSection != null)
            {
                var clonePageAssociation = new PageAssociation
                {
                    PageSectionId        = pageAssociation.PageSectionId,
                    PageId               = page.PageId,
                    PageAssociationRoles = pageAssociation.PageAssociationRoles,
                };

                if (page.PageAssociations.Any())
                {
                    clonePageAssociation.PageAssociationOrder = page.PageAssociations.Max(pa => pa.PageAssociationOrder + 1);
                }
                else
                {
                    clonePageAssociation.PageAssociationOrder = 1;
                }

                _context.PageAssociations.Add(clonePageAssociation);

                await _context.SaveChangesAsync();
            }
        }