public async Task <IActionResult> OnGetAsync(int id) { Resource = await _context.GetResourceAsync(id); if (Resource == null) { TempData["Message"] = $"Resource not found. Id = {id}."; return(RedirectToPage("./Index")); } return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var resource = await _context.GetResourceAsync(BookmarkEntity.ResourceId); if (resource == null) { ModelState.AddModelError("ResourceId", "Resource does not exist."); } var user = await _context.GetUserAsync(BookmarkEntity.UserId); if (user == null) { ModelState.AddModelError("UserId", "User does not exist."); } if (!ModelState.IsValid) { return(Page()); } var bookmark = new Bookmark(); bookmark.Title = BookmarkEntity.Title; bookmark.Description = BookmarkEntity.Description; bookmark.IsPublic = BookmarkEntity.IsPublic; bookmark.Favorited = BookmarkEntity.IsFavorite; bookmark.Resource = resource; bookmark.User = user; bookmark.CreateDate = DateTime.UtcNow; if (!string.IsNullOrWhiteSpace(BookmarkEntity.Tags)) { // TODO: Check for uniqueness var tags = BookmarkEntity.Tags.Split(','); foreach (var tag in tags) { if (!string.IsNullOrWhiteSpace(tag)) { bookmark.Tags.Add(new Tag { TagName = tag }); } } } _context.AddBookmark(bookmark); await _context.SaveChangesAsync(); TempData["Message"] = "Bookmark successfully added."; return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int id) { var resource = await _context.GetResourceAsync(id); if (resource == null) { TempData["Message"] = $"Resource not found. Id = {id}."; return(RedirectToPage("./Index")); } Resource = new EditResourceModel { Title = resource.Metadata.ContainsKey("Title") ? resource.Metadata["Title"] : "", Location = resource.Location, MediaType = resource.Metadata.ContainsKey("MediaType") ? resource.Metadata["MediaType"] : "", Image = resource.Metadata.ContainsKey("ImageURL") ? resource.Metadata["ImageURL"] : "", Description = resource.Metadata.ContainsKey("Description") ? resource.Metadata["Description"] : "" }; return(Page()); }