public async Task <IActionResult> OnGetAsync(Guid?pageId = null) { if (pageId != null) { PageId = pageId; ViewData["PageId"] = PageId; AddArticleUrl = "/WebPage/Articles/Add"; UpdateArticleUrl = "/WebPage/Articles/Update"; var page = await _webPagesService.FindByIdAllIncludedAsync(pageId); if (page == null) { return(NotFound()); } Vm = new ArticlesViewModel { Articles = page.Articles.OrderBy(a => a.Name).Select(a => new ArticleDto { Id = a.Id, Name = a.Name, DateTimeCreated = $"{a.DateTimeCreated?.ToShortDateString()} - ({a.DateTimeCreated?.ToShortTimeString()})" }).ToList() }; } else { AddArticleUrl = "/Articles/Add"; UpdateArticleUrl = "/Article/Index"; var articles = await Service.GetAll().Include(a => a.Webpage) .Include(a => a.Images) .ToListAsync(); Vm = new ArticlesViewModel { Articles = articles.OrderBy(a => a.Name).Select(a => new ArticleDto { Id = a.Id, Name = a.Name, DateTimeCreated = $"{a.DateTimeCreated?.ToShortDateString()} - ({a.DateTimeCreated?.ToShortTimeString()})" }).ToList() }; } PageTitle = await TranslationsService.TranslateAsync("Artikels"); TxtName = await TranslationsService.TranslateAsync("Name"); TxtAddedOn = await TranslationsService.TranslateAsync("Toegevoegd op"); return(Page()); }
public async Task <IActionResult> OnPostAddAsync() { Webpage page = await _webPagesService.FindByIdAllIncludedAsync(PageId); var formDict = Request.Form.ToDictionary(k => k.Key.ToString(), k => k.Value); var addArticleResult = await Service.CreateAsync(formDict); if (addArticleResult.Successfull) { if (page == null) { return(RedirectToPage("/Articles/Index")); } var addArticleToPageResult = await _webPagesService.AddArticleAsync(page, addArticleResult.Entity as Article); if (addArticleToPageResult.Successfull) { return(RedirectToPage("/WebPage/Articles/Index", new { pageId = page.Id })); } foreach (var error in addArticleToPageResult.Errors) { ModelState.AddModelError(string.Empty, error.Message); } } foreach (var error in addArticleResult.Errors) { ModelState.AddModelError(string.Empty, error.Message); } return(await OnGetAsync(PageId ?? null)); }
public virtual async Task <IActionResult> OnGetAsync(Guid pageId) { var page = await _webPagesService.FindByIdAllIncludedAsync(pageId); if (page == null) { return(NotFound()); } PageTitle = await TranslationsService.TranslateAsync("Links"); TxtAddLink = await TranslationsService.TranslateAsync("Add Link"); NameDisplay = await TranslationsService.TranslateAsync("name"); LinkNameRequiredError = TranslationsService.TranslateErrorByDescriber(ErrorDescriberConstants.RequiredField, $"The field '{NameDisplay}' is required.", NameDisplay); LinkNameLengthError = TranslationsService.TranslateErrorByDescriber(ErrorDescriberConstants.StringLength, $"The field '{NameDisplay}' must contain a minimum of {4} and a maximum of {30} characters.", NameDisplay, 4.ToString(), 30.ToString()); LinkUrlRequiredError = TranslationsService.TranslateErrorByDescriber(ErrorDescriberConstants.StringLength, $"The field 'Url' must contain a minimum of {4} and a maximum of {200} characters.", "Url", 4.ToString(), 200.ToString()); TxtAddedOn = await TranslationsService.TranslateAsync("Toegevoegd op"); ViewData["PageId"] = page.Id; Vm = new LinksViewModel { PageId = page.Id }; if (page.Links.Count > 0) { Vm.Links = page.Links.OrderBy(l => l.UniqueNameIdentifier).Select(l => new LinkDto { Id = l.Id, Name = l?.Name, Url = l?.Url, DateTimeCreated = $"{l.DateTimeCreated?.ToShortDateString()} - ({l.DateTimeCreated?.ToShortTimeString()})" }).ToList(); } return(Page()); }