Ejemplo n.º 1
0
        public async Task <IActionResult> Render(string url, [Bind("PageId,Content")] CMSPageVersion cmsPageVersion, [Bind("PageId")] CMSPageHistory cmsPageHistory)
        {
            if (url == null && HttpContext.Items["CMSUrl"] != null)
            {
                url = (string)HttpContext.Items["CMSUrl"];
            }
            if (url == null)
            {
                return(NotFound());
            }

            var cmsPage = await _context.CMSPage.SingleOrDefaultAsync(p => p.Url == url);

            if (cmsPage == null)
            {
                return(NotFound());
            }

            // check if the content has changed from the last active version - if not then don't do anything
            var testVersion = (cmsPage.VersionId != null && cmsPage.VersionId > 0) ? await _context.CMSPageVersion.SingleOrDefaultAsync(v => v.VersionId == cmsPage.VersionId) : null;

            if (testVersion == null || cmsPageVersion.Content != testVersion.Content)
            {
                // add the new content version to the database
                cmsPageVersion.Status = 1;
                _context.Add(cmsPageVersion);

                // write changes to the database
                await _context.SaveChangesAsync();

                // get current user id
                string userId = _userManager.GetUserId(User);

                // add the history item for this update
                cmsPageHistory.VersionId    = cmsPageVersion.VersionId;
                cmsPageHistory.Title        = cmsPage.Title;
                cmsPageHistory.Url          = cmsPage.Url;
                cmsPageHistory.Status       = cmsPage.Status;
                cmsPageHistory.ModifiedBy   = userId;
                cmsPageHistory.ModifiedDate = DateTime.Now;
                _context.Add(cmsPageHistory);

                // update page info to reflect the update
                cmsPage.VersionId    = cmsPageVersion.VersionId;
                cmsPage.ModifiedBy   = cmsPageHistory.ModifiedBy;
                cmsPage.ModifiedDate = cmsPageHistory.ModifiedDate;
                _context.Update(cmsPage);

                // write changes to the database
                await _context.SaveChangesAsync();
            }

            // reload the page
            return(Redirect("/" + url));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ArchiveVersion(int pageId, int id)
        {
            CMSPage cmsPage = _context.CMSPage.SingleOrDefault(p => p.PageId == pageId);

            if (cmsPage == null)
            {
                return(NotFound());
            }

            CMSPageVersion cmsPageVersion = _context.CMSPageVersion.SingleOrDefault(p => p.PageId == pageId && p.VersionId == id);

            if (cmsPageVersion == null)
            {
                return(NotFound());
            }

            try
            {
                // update status to reflect change
                cmsPageVersion.Status = 0;
                _context.Update(cmsPageVersion);

                // write changes to the database
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CMSPageVersionExists(cmsPageVersion.PageId, cmsPageVersion.VersionId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction("Edit", new { url = cmsPage.Url }));
        }