public async Task <IActionResult> OnPost() { if (ModelState.IsValid) { this.NewLink.Author = this.User.Identity.Name; List <string> Roles = new List <string>(); if (UserRole) { Roles.Add("User"); } if (Roles.Count > 0) { this.NewLink.Roles = Roles.ToArray(); } if (!String.IsNullOrEmpty(NewLink.Id)) { CommentedLinkItem existingLink = await repository.GetDocument(NewLink.Id); if (null != existingLink) { NewLink.Infos = existingLink.Infos; } } await this.repository.UpsertDocument(NewLink); string targetPage; switch (NewLink.ListName) { case "Scuderia": targetPage = "/Rad/Scuderia"; break; case "Fotos": targetPage = "/Fotos/Index"; break; default: targetPage = "./Album"; break; } return(RedirectToPage(targetPage)); } else { Categories = await categoryRepository.GetDocuments(d => d.ListName == "Fotos"); ViewData["Message"] = "Da stimmt was nicht."; return(Page()); } }
// only on page level [Authorize(KnownRoles.Admin)] public async Task <IActionResult> OnGetDeleteContentItemAsync(string documentid, string contentitemid) { CommentedLinkItem linktItem = await repository.GetDocument(documentid); if (linktItem == null) { return(new NotFoundResult()); } if (linktItem.Infos != null) { List <ContentItem> infos = new List <ContentItem>(linktItem.Infos); infos.RemoveAll(c => c.UniqueId == contentitemid); linktItem.Infos = infos.ToArray(); await repository.UpsertDocument(linktItem); } ViewData["Message"] = "Eintrag gelöscht"; return(RedirectToPage()); }
public async Task <IActionResult> OnGetAsync(string documentid, string contentitemid) { if (String.IsNullOrEmpty(documentid)) { return(new NotFoundResult()); } CommentedLinkItemId = documentid; CommentedLinkItem linkItem = await _repository.GetDocument(documentid); if (null == linkItem) { return(new NotFoundResult()); } List <ContentItem> contentItems = (linkItem.Infos != null) ? new List <ContentItem>(linkItem.Infos) : new List <ContentItem>(); if (String.IsNullOrEmpty(contentitemid)) { PhotoPageDetail = new ContentItem { ContentType = ContentType.Text, UniqueId = Guid.NewGuid().ToString(), SortOrder = 10 }; if (contentItems.Count > 0) { PhotoPageDetail.SortOrder = contentItems.Last().SortOrder + 10; } } else { if (null == linkItem.Infos) { return(new NotFoundResult()); } PhotoPageDetail = contentItems.Find(c => c.UniqueId == contentitemid); if (null == PhotoPageDetail) { return(new NotFoundResult()); } } return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { CommentedLinkItem linkItem = await _repository.GetDocument(CommentedLinkItemId); if (null == linkItem) { return(new NotFoundResult()); } List <ContentItem> contentItems = (linkItem.Infos != null) ? new List <ContentItem>(linkItem.Infos) : new List <ContentItem>(); contentItems.RemoveAll(c => c.UniqueId == PhotoPageDetail.UniqueId); contentItems.Add(PhotoPageDetail); linkItem.Infos = contentItems.OrderBy(c => c.SortOrder).ToArray(); await _repository.UpsertDocument(linkItem); return(RedirectToPage("Index", new { permalink = linkItem.UrlTitle })); } else { ViewData["Message"] = "Da stimmt was nicht."; return(Page()); } }