Esempio n. 1
0
        // Get bounding box for this track, for map display in the CMS
        public double[,] GetBoundingBox(WebsiteDataContext ctx)
        {
            ctx.Entry(this).Collection(t => t.Activities).Load();

            if (Activities.Count <= 0)
            {
                return(null);
            }

            double[] xVals = Activities.Select(a => a.CoordX).ToArray();
            double[] yVals = Activities.Select(a => a.CoordY).ToArray();

            return(new double[, ] {
                { xVals.Min(), yVals.Max() }, { xVals.Max(), yVals.Min() }
            });
        }
        public async Task <IActionResult> GetDetails(int id)
        {
            try
            {
                NavItem item = await _Db.NavItems.FindAsync(id);

                if (item == null)
                {
                    return(NotFound(new ResponseHelper("Something went wrong, please try again later")));
                }

                await _Db.Entry(item).Reference(i => i.Page).LoadAsync();

                await _Db.Entry(item).Collection(i => i.NavItemPages).LoadAsync();

                foreach (NavItemPage nip in item.NavItemPages)
                {
                    await _Db.Entry(nip).Reference(n => n.Page).LoadAsync();
                }

                return(Ok(new {
                    item.Id,
                    item.Text,
                    item.Url,
                    pageId = item.Page?.Id,
                    pageName = item.Page?.Name,
                    children = item.NavItemPages.Count > 0 ? item.NavItemPages.OrderBy((nip) => nip.OrderIndex).Select(nip => new
                    {
                        nip.Text,
                        nip.Url,
                        pageId = nip.Page?.Id,
                        pageName = nip.Page?.Name,
                    }) : null
                }));
            }
            catch (Exception ex)
            {
                _Logger.LogError("Error retrieving navbar item details", ex.Message);
                _Logger.LogError(ex.StackTrace);
                return(BadRequest(new ResponseHelper("Something went wrong, please try again later.", ex.Message)));
            }
        }