public async Task <IActionResult> Create(PagesEditViewModel model) { Regex checkStub = new Regex(@"^[\w\-]*$"); if (!checkStub.IsMatch(model.Page.Stub)) { ModelState.AddModelError("Page.Stub", "Invalid stub, only letters, numbers, hypens and underscores are allowed"); } if (ModelState.IsValid) { try { await _pageService.AddPageAsync(model.Page); AlertSuccess = $"Page '{model.Page.Title}' created"; return(RedirectToAction("Index")); } catch (GraException gex) { AlertInfo = gex.Message; } } PageTitle = "Create Page"; return(View(model)); }
public async Task <IActionResult> Detail(PageDetailViewModel model) { var language = await _languageService.GetActiveByIdAsync(model.SelectedLanguageId); var currentPage = await _pageService.GetByHeaderAndLanguageAsync( model.HeaderId, language.Id); if (ModelState.IsValid) { var page = model.Page; page.LanguageId = language.Id; page.PageHeaderId = model.HeaderId; if (currentPage == null) { await _pageService.AddPageAsync(page); ShowAlertSuccess("Page content added!"); } else { await _pageService.EditPageAsync(page); ShowAlertSuccess("Page content updated!"); } return(RedirectToAction(nameof(Detail), new { id = model.HeaderId, language = language.Name })); } var header = await _pageService.GetHeaderByIdAsync(model.HeaderId); var languages = await _languageService.GetActiveAsync(); model.HeaderName = header.PageName; model.HeaderStub = header.Stub; model.LanguageList = new SelectList(languages, "Name", "Description", language.Name); if (currentPage?.IsPublished == true) { var baseUrl = await _siteService.GetBaseUrl(Request.Scheme, Request.Host.Value); var action = Url.Action("Index", "Info", new { area = "", culture = language.Name, id = header.Stub }); model.PageUrl = baseUrl + action; } return(View(model)); }
private async Task SavePage() { Page page = null; try { if (_name != string.Empty && !string.IsNullOrEmpty(_themetype) && (_layouts.Count == 0 || !string.IsNullOrEmpty(_layouttype))) { page = new Page(); page.SiteId = PageState.Page.SiteId; page.Name = _name; page.Title = _title; if (_path == "") { _path = _name; } if (_path.Contains("/")) { _path = _path.Substring(_path.LastIndexOf("/") + 1); } if (string.IsNullOrEmpty(_parentid)) { page.ParentId = null; page.Path = Utilities.GetFriendlyUrl(_path); } else { page.ParentId = Int32.Parse(_parentid); var parent = PageState.Pages.Where(item => item.PageId == page.ParentId).FirstOrDefault(); if (parent.Path == string.Empty) { page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path); } else { page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path); } } if (!PagePathIsUnique(page.Path, page.SiteId, _pageList)) { AddModuleMessage($"A page with path {_path} already exists for the selected parent page. The page path needs to be unique for the selected parent.", MessageType.Warning); return; } Page child; switch (_insert) { case "<<": page.Order = 0; break; case "<": child = PageState.Pages.Where(item => item.PageId == _childid).FirstOrDefault(); page.Order = child.Order - 1; break; case ">": child = PageState.Pages.Where(item => item.PageId == _childid).FirstOrDefault(); page.Order = child.Order + 1; break; case ">>": page.Order = int.MaxValue; break; } page.IsNavigation = (_isnavigation == null ? true : Boolean.Parse(_isnavigation)); page.Url = _url; page.ThemeType = (_themetype != "-") ? _themetype : string.Empty; if (!string.IsNullOrEmpty(page.ThemeType) && page.ThemeType == PageState.Site.DefaultThemeType) { page.ThemeType = string.Empty; } page.LayoutType = (_layouttype != "-") ? _layouttype : string.Empty; if (!string.IsNullOrEmpty(page.LayoutType) && page.LayoutType == PageState.Site.DefaultLayoutType) { page.LayoutType = string.Empty; } page.DefaultContainerType = (_containertype != "-") ? _containertype : string.Empty; if (!string.IsNullOrEmpty(page.DefaultContainerType) && page.DefaultContainerType == PageState.Site.DefaultContainerType) { page.DefaultContainerType = string.Empty; } page.Icon = (_icon == null ? string.Empty : _icon); page.Permissions = _permissionGrid.GetPermissions(); page.IsPersonalizable = (_ispersonalizable == null ? false : Boolean.Parse(_ispersonalizable)); page.UserId = null; page = await PageService.AddPageAsync(page); await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, page.ParentId); await logger.LogInformation("Page Added {Page}", page); NavigationManager.NavigateTo(NavigateUrl(page.Path)); } else { AddModuleMessage("You Must Provide Page Name And Theme", MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Saving Page {Page} {Error}", page, ex.Message); AddModuleMessage("Error Saving Page", MessageType.Error); } }