💻 Sample C# Web client for the API
App / Misc
๐Ÿ‘ 0 ๐Ÿ‘Ž 0

For developers

Download sample web client code (C# / MVC) to call the API endpoints via the NuGet GeoARIt.Api library (Source code). You'll need your API key.

Try this code out at dotnetfiddle.net

You can generate the GeoARIt.Api code in your preferred development language using these instructions.

The GeoARIt nuget package was generated using editor.swagger.io 

Sample code taken 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://docs.microsoft.com/en-us/aspnet/core/security/app-secrets
            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
        }
    }
}