๐Ÿ–ฅ๏ธ - Sample ASP.NET Core MVC Web Application (C#) Utilizing the GeoARit.API NuGet Package
 
 

Download the sample ASP.NET Core MVC Web Application in C#. This application integrates with the GeoAR.it API endpoints via the GeoARIt.Api NuGet package (source code). Please ensure you have your API key ready for access.

You can generate the GeoARIt.API client code in your preferred development language by following these instructions. The GeoARIt.API NuGet package was generated using editor.swagger.io

Sample code from the project:


using GeoARIt.Api;
using GeoARIt.Client.Web.Models;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Diagnostics;

namespace GeoARIt.Client.Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly IOptions _options;
        private HttpClient httpClient;
        private swaggerClient api;
        private string apiVersion = "1";

        public HomeController(ILogger logger, IOptions options)
        {
            _options = options ?? throw new Exception($"Parameter {nameof(options)} is null");

            httpClient = new HttpClient();
            api = new swaggerClient(_options.Value.BaseAddress, httpClient);
        }

        public async Task Index()
        {
            #region Setup
            // https://geoar.it/Help/Details/32/Where-do-I-find-my-API-Key-(bearer-token)
            var apiBearerToken = _options.Value.ApiKey; // Picks ApiKey up from appsettings.{environment}.json. launchSettings.json contains all environments. Visual Studio play button โ–ถ๏ธ picks the environment)

            httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue($"Bearer", $"{apiBearerToken}");
            #endregion

            #region Get demo Venues and my Venues
            var myVenuesAndDemoVenues = await api.GetVenuesAsync(true, apiVersion);
            if (myVenuesAndDemoVenues.Count == 0)
            {
                throw new Exception("Can't find demo Venues or my Venues");
            }
            #endregion

            var noughtiesFestival = myVenuesAndDemoVenues.Where(x => x.Guid == Guid.Parse("11111111-1111-1111-1111-05ecb3f6ea4c")).First().Guid;
            var hotspots = await api.GetHotspotsForVenueAsync(noughtiesFestival, int.MaxValue, apiVersion);
            if (hotspots.Count() == 0)
            {
                throw new Exception($"Can't find hotspots for Venue {myVenuesAndDemoVenues.First().Guid}");
            }

            var viewModel = new VenueHotspotsViewModel()
            {
                Venue = myVenuesAndDemoVenues.First(),
                Hotspots = hotspots,
            };

            // MoreExamples();

            return View(viewModel);
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel
            {
                ExceptionHandlerPathFeature = HttpContext.Features.Get(),
                RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
            });
        }

        private async void MoreExamples()
        {
            #region Get Venues
            var allMyVenuesAndDemoVenues = await api.GetVenuesAsync(true, apiVersion);
            Thread.Sleep(1000);

            var justMyVenues = await api.GetVenuesAsync(false, apiVersion);

            Thread.Sleep(1000);
            var venue = await api.GetVenueAsync(allMyVenuesAndDemoVenues.First().Guid, apiVersion);
            Thread.Sleep(1000);
            #endregion

            #region Get Hotspots for Venue
            var hotspots = await api.GetHotspotsForVenueAsync(venue.Guid, 99, apiVersion);
            Thread.Sleep(1000);
            #endregion

            #region API testing hotspot // https://geoarit.azurewebsites.net/Hotspot/Edit/ed7d67f0-1a52-4b94-9bbe-110036911793       
            Guid apiTestingHotspot = default;
            Guid.TryParse("ed7d67f0-1a52-4b94-9bbe-1100369117931", out apiTestingHotspot);

            // Will raise a forbidden exception if you don't own the hotspot
            var hotspot = await api.GetHotspotAsync(apiTestingHotspot, apiVersion);
            if (hotspot == null)
            {
                throw new Exception($"Can't find hotspots for Venue {apiTestingHotspot}");
            }
            Thread.Sleep(1000);

            # region Delete all properties for Hotspot
            // Will raise a forbidden exception if you don't own the hotspot
            await api.DeleteHotspotPropertyAsync(hotspot.Guid, apiVersion, new DeleteHotspotProperty() { Name = "*" });
            Thread.Sleep(1000);
            #endregion

            #region Add properties for Hotspot    
            // Will raise a forbidden exception if you don't own the hotspot
            await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() { Name = "HelpLine", PropertyType = HotspotPropertyType.PhoneNumber, ExpiresInSeconds = 0, Value = "0191 1234567", SortOrder = 1 });
            Thread.Sleep(1000);

            await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() { Name = "Next on stage", PropertyType = HotspotPropertyType.Text, ExpiresInSeconds = 0, Value = "Kings of Leon. Rocking since 1999 with brothers Celeb, Nathan and Jared along with cousin Matthew", SortOrder = 3 });
            Thread.Sleep(1000);

            await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() { Name = "On at", PropertyType = HotspotPropertyType.Time, ExpiresInSeconds = 0, Value = "22:55", SortOrder = 2 });
            Thread.Sleep(1000);

            await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() { Name = "Band website", PropertyType = HotspotPropertyType.Url, ExpiresInSeconds = 0, Value = "https://kingsofleon.com", SortOrder = 3 });
            Thread.Sleep(1000);

            await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() { Name = "Spotify", PropertyType = HotspotPropertyType.Url, ExpiresInSeconds = 0, Value = "https://open.spotify.com/artist/2qk9voo8llSGYcZ6xrBzKx", SortOrder = 4 });
            Thread.Sleep(1000);

            await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() { Name = "Sex on Fire lyrics", PropertyType = HotspotPropertyType.Url, ExpiresInSeconds = 0, Value = "https://www.google.com/search?q=kings+of+leon+sex+on+fire", SortOrder = 5 });
            Thread.Sleep(1000);
            #endregion

            // Delete specific hotspot Property
            // Will raise a forbidden exception if you don't own the hotspot
            //await api.DeleteHotspotPropertyAsync(hotspot.Guid, apiVersion, new DeleteHotspotProperty() { Name = "To be deleted" });
            Thread.Sleep(1000);

            #region Update GEO position
            // Will raise a forbidden exception if you don't own the hotspot
            var updateHotspotGeoLocation = await api.UpdateHotspotGeolocationPositionAsync(hotspot.Guid, 54.90277, -1.5652084, 0, apiVersion);
            Thread.Sleep(1000);
            #endregion
            #endregion

            #region Prefabs
            var getPrefab = await api.GetPrefabAsync(hotspot.Prefab.Guid, "1");
            #endregion
        }
    }
}

This code is from an ASP.NET Core MVC application, specifically in a HomeController class. The controller interacts with the GeoAR.it API to fetch venues and hotspots, manage their properties, and render the information on the web page. The API is used to retrieve data about augmented reality venues and hotspots, which can be displayed to users. Let's break down the code in detail:


#region Setup:

This region configures the HTTP client to authenticate API requests using a Bearer token. The token is fetched from the app's configuration (e.g., appsettings.json) and is then added to the HTTP client's headers for all subsequent API requests.


#region Setup
var apiBearerToken = _options.Value.ApiKey;
httpClient.DefaultRequestHeaders.Authorization = 
    new System.Net.Http.Headers.AuthenticationHeaderValue($"Bearer", $"{apiBearerToken}");
#endregion

#region Get demo Venues and my Venues:

This region retrieves both demo venues and the user's venues by calling GetVenuesAsync. The true argument includes demo venues. If no venues are found, the method throws an exception.


#region Get demo Venues and my Venues
var myVenuesAndDemoVenues = await api.GetVenuesAsync(true, apiVersion);
if (myVenuesAndDemoVenues.Count == 0)
{
    throw new Exception("Can't find demo Venues or my Venues");
}
#endregion

#region Get Hotspots for Venue:

This region fetches all hotspots associated with a specific venue (identified by its GUID). If no hotspots are found, an exception is thrown to handle this case.


#region Get Hotspots for Venue
var noughtiesFestival = myVenuesAndDemoVenues
    .Where(x => x.Guid == Guid.Parse("11111111-1111-1111-1111-05ecb3f6ea4c"))
    .First().Guid;
var hotspots = await api.GetHotspotsForVenueAsync(noughtiesFestival, int.MaxValue, apiVersion);
if (hotspots.Count() == 0)
{
    throw new Exception($"Can't find hotspots for Venue {myVenuesAndDemoVenues.First().Guid}");
}
#endregion

#region Get Venues:

This region demonstrates fetching all venues (including demo venues), only the user's venues, and then retrieving the details of a specific venue using the venue's GUID.


#region Get Venues
var allMyVenuesAndDemoVenues = await api.GetVenuesAsync(true, apiVersion);
Thread.Sleep(1000);

var justMyVenues = await api.GetVenuesAsync(false, apiVersion);
Thread.Sleep(1000);

var venue = await api.GetVenueAsync(allMyVenuesAndDemoVenues.First().Guid, apiVersion);
Thread.Sleep(1000);
#endregion

#region Get Hotspots for Venue:

This region retrieves up to 99 hotspots for a specific venue. The GetHotspotsForVenueAsync method is used, and the number of returned hotspots is limited to 99 for performance reasons.


#region Get Hotspots for Venue
var hotspots = await api.GetHotspotsForVenueAsync(venue.Guid, 99, apiVersion);
Thread.Sleep(1000);
#endregion

#region API testing hotspot:

This region retrieves a specific hotspot for testing purposes using a hardcoded GUID. If the hotspot isn't found, it throws an exception to handle the error.


#region API testing hotspot
Guid apiTestingHotspot = default;
Guid.TryParse("ed7d67f0-1a52-4b94-9bbe-1100369117931", out apiTestingHotspot);

var hotspot = await api.GetHotspotAsync(apiTestingHotspot, apiVersion);
if (hotspot == null)
{
    throw new Exception($"Can't find hotspots for Venue {apiTestingHotspot}");
}
Thread.Sleep(1000);
#endregion

#region Delete all properties for Hotspot:

This region deletes all properties for a specific hotspot using the wildcard * to indicate that all properties should be removed.


#region Delete all properties for Hotspot
await api.DeleteHotspotPropertyAsync(hotspot.Guid, apiVersion, new DeleteHotspotProperty() { Name = "*" });
Thread.Sleep(1000);
#endregion

#region Add properties for Hotspot:

This region adds several properties to a hotspot, such as phone numbers, event information, and URLs. Each property is associated with a name and type (e.g., phone number, text, URL).


#region Add properties for Hotspot    
await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() 
{ 
    Name = "HelpLine", 
    PropertyType = HotspotPropertyType.PhoneNumber, 
    ExpiresInSeconds = 0, 
    Value = "0191 1234567", 
    SortOrder = 1 
});
Thread.Sleep(1000);

await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() 
{ 
    Name = "Next on stage", 
    PropertyType = HotspotPropertyType.Text, 
    ExpiresInSeconds = 0, 
    Value = "Kings of Leon. Rocking since 1999 with brothers Celeb, Nathan and Jared along with cousin Matthew", 
    SortOrder = 3 
});
Thread.Sleep(1000);

await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() 
{ 
    Name = "On at", 
    PropertyType = HotspotPropertyType.Time, 
    ExpiresInSeconds = 0, 
    Value = "22:55", 
    SortOrder = 2 
});
Thread.Sleep(1000);

await api.AddOrUpdateHotspotPropertyAsync(hotspot.Guid, apiVersion, new AddUpdateHotspotProperty() 
{ 
    Name = "Band website", 
    PropertyType = HotspotPropertyType.Url, 
    ExpiresInSeconds = 0, 
    Value = "https://kingsofleon.com", 
    SortOrder = 3 
});
Thread.Sleep(1000);
#endregion

#region Update GEO position:

This region updates the geolocation of a specific hotspot using latitude, longitude, and altitude values. The API method UpdateHotspotGeolocationPositionAsync is used to update the position.


#region Update GEO position
var updateHotspotGeoLocation = await api.UpdateHotspotGeolocationPositionAsync(hotspot.Guid, 54.90277, -1.5652084, 0, apiVersion);
Thread.Sleep(1000);
#endregion

#region Prefabs:

This region fetches a prefab (a 3D object template) that is associated with the hotspot. Prefabs are often used in augmented reality or game development environments.


#region Prefabs
var getPrefab = await api