Пример #1
0
        public async Task <IActionResult> Create([Required] Template model)
        {
            if (_pagesContext.Templates.Any(x => x.Name == model.Name))
            {
                ModelState.AddModelError(string.Empty, "Name is used by another template!");
                return(View(model));
            }
            try
            {
                model.IdentifierName = $"template_{model.Name}";
                _pagesContext.Templates.Add(model);
                _pagesContext.SaveChanges();
                await _cacheService.SetAsync(model.IdentifierName, new TemplateCacheModel
                {
                    Identifier = model.IdentifierName,
                    Value      = model.Value
                });

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }

            return(View(model));
        }
Пример #2
0
 public IActionResult Edit([Required] CreateBlockViewModel model)
 {
     model.Changed = DateTime.Now;
     try
     {
         _pagesContext.Blocks.Update(model);
         _pagesContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         ModelState.AddModelError(string.Empty, e.Message);
         Console.WriteLine(e);
     }
     return(View(model));
 }
Пример #3
0
        public IActionResult Create([Required] BlockCategory model)
        {
            try
            {
                _pagesContext.BlockCategories.Add(model);
                _pagesContext.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }

            return(View(model));
        }
Пример #4
0
 public IActionResult Create([Required] CreateBlockViewModel model)
 {
     try
     {
         model.TenantId = CurrentUserTenantId;
         model.Author   = GetCurrentUser().Id;
         model.Changed  = DateTime.Now;
         _pagesContext.Blocks.Add(model);
         _pagesContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
     model.BlockCategories = _pagesContext.BlockCategories.ToList();
     return(View(model));
 }
Пример #5
0
        public IActionResult Create(PageType model)
        {
            if (model != null)
            {
                try
                {
                    _pagesContext.PageTypes.Add(model);
                    _pagesContext.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
            }

            return(View(model));
        }
Пример #6
0
        public async Task <IActionResult> GetCode(CodeViewModel model)
        {
            if (model.PageId == Guid.Empty)
            {
                ModelState.AddModelError(string.Empty, "Invalid data input");
                return(View(model));
            }

            var page = await _pageRender.GetPageAsync(model.PageId);

            if (page == null)
            {
                ModelState.AddModelError(string.Empty, "Page not found");
                return(View(model));
            }

            if (page.Settings == null)
            {
                page.Settings = new PageSettings();
            }

            switch (model.Type)
            {
            case "css":
                page.Settings.CssCode = model.Code;
                break;

            case "js":
                page.Settings.JsCode = model.Code;
                break;

            case "html":
                page.Settings.HtmlCode = model.Code;
                break;
            }

            try
            {
                _pagesContext.Pages.Update(page);
                _pagesContext.SaveChanges();
                await _cacheService.RemoveAsync($"_page_dynamic_{page.Id}");

                //return RedirectToAction(page.IsLayout ? "Layouts" : "Index");
                return(RedirectToAction("GetCode", new { type = model.Type, id = model.PageId }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            ModelState.AddModelError(string.Empty, "Invalid data input");
            return(View(model));
        }
Пример #7
0
        /// <summary>
        /// Save page data
        /// </summary>
        /// <param name="pageId"></param>
        /// <param name="html"></param>
        /// <param name="css"></param>
        /// <param name="js"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> SavePageContent(Guid pageId, string html, string css, string js = null)
        {
            var result = new ResultModel();

            if (pageId == Guid.Empty)
            {
                return(result);
            }
            var page = await GetPageAsync(pageId);

            if (page == null)
            {
                return(result);
            }
            page.Settings.CssCode  = css;
            page.Settings.HtmlCode = html;
            try
            {
                _pagesContext.Pages.Update(page);
                _pagesContext.SaveChanges();
                await _cacheService.RemoveAsync($"{PageRenderConstants.PageCacheIdentifier}{pageId}");

                result.IsSuccess = true;
                DynamicUiEvents.Pages.PageUpdated(new PageCreatedEventArgs
                {
                    PageId   = pageId,
                    PageName = page.Settings.Name
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(result);
        }