private async Task <bool> GetData(int id, string token) { try { Data = new CategoriesViewModel { Data = await client.Get(token, id) }; } catch { return(false); } return(true); }
public async Task <IActionResult> OnGetAsync(int?id) { if (!id.HasValue) { IsNew = true; Data = new CategoriesViewModel { Data = new Category { Name = "Untitled-Tag", Color = "grey", } }; PostData = new CategoriesPostModel { Data = Data.Data }; return(Page()); } else { IsNew = false; string token = await idData.GetAccessToken(HttpContext); if (await GetData(id.Value, token)) { PostData = new CategoriesPostModel { Data = Data.Data }; return(Page()); } else { return(NotFound()); } } }
public async Task <IActionResult> OnGetAsync(int id, int?pageIndex) { string token = await idData.GetAccessToken(HttpContext); Token = token; try { Data = new CategoriesViewModel { Data = await client.Get(token, id) }; if (Data.Data.UserId != idData.GetClaimId(User)) { Onwer = await usersClient.Get(token, Data.Data.UserId); } Paging = new PagingSettings { ItemCountPerPage = 8, RouteData = new Dictionary <string, string> { ["id"] = Data.Data.Id.ToString(), } }; IEnumerable <Note> notes; { int count = (await nodesClient.Query(token, categoryId: Data.Data.Id, targets: NoteTargets.Count)).Count(); Paging.MaximumIndex = (count / Paging.ItemCountPerPage) + (count % Paging.ItemCountPerPage > 0 ? 1 : 0); if (!pageIndex.HasValue) { pageIndex = 1; } Paging.CurrentIndex = pageIndex.Value; int offset = (Paging.CurrentIndex - 1) * Paging.ItemCountPerPage; notes = await nodesClient.Query(token, categoryId : Data.Data.Id, offset : offset, count : Paging.ItemCountPerPage); Notes = notes.ToList(); } /*{ * Dictionary<int, Relation> rs = new Dictionary<int, Relation>(); * foreach (Note v in notes) * { * foreach (Relation r in await relationsClient.GetAdjacents(token, v.Id)) * { * if (rs.ContainsKey(r.Id)) * { * continue; * } * * rs.Add(r.Id, r); * } * } * Graph = new GraphViewModel * { * Graph = await RelationHelper.GenerateGraph(nodesClient, client, rs.Values, token) * }; * }*/ } catch { return(NotFound()); } return(Page()); }