Example #1
0
        public async Task <IActionResult> SearchAsync(string term = "*")
        {
            var queryModel = new GetSearchQueryModel
            {
                Term = term
            };
            GetSearchResultModel resultModel;

            try
            {
                resultModel = await _queryHandler.HandleAsync(queryModel);
            }
            catch (QueryModelException ex)
            {
                // When Query model validation fails.
                _logger.LogError(ex.Message, ex);
                throw;
            }
            catch (FailedApiRequestException ex)
            {
                // When Panviva API results in a error.
                _logger.LogError(ex.Message, ex);
                throw;
            }

            return(Ok(resultModel));
        }
Example #2
0
        private static void Main(string[] args)
        {
            // In this region we setup manual Dependency Injection and Host Build for Panviva .Net Sdk
            #region SetupDI

            var builder = new ConfigurationBuilder();
            BuildConfig(builder);

            var host = Host.CreateDefaultBuilder()
                       .ConfigureServices((context, services) => { services.AddPanvivaApis(); })
                       .Build();

            var queryHandler = ActivatorUtilities.CreateInstance <QueryHandler>(host.Services);
            #endregion

            // Get this month start
            var fromDate = $"{DateTime.Now.Year}-{DateTime.Now.Month.ToString().PadLeft(2, '0')}-01";

            // Construct Query string
            var queryModel = new GetSearchQueryModel {
                Term = $"data.attributes.updatedDate:{{{fromDate} TO *}}"
            };

            object searchResult;

            try
            {
                // Call the Panviva SDK and get responses,
                searchResult = queryHandler.HandleAsync(queryModel).Result;
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception occurred when calling Panviva APIs : {e.Message}");
                throw;
            }

            var searchResultAsJson = JsonConvert.SerializeObject(searchResult);
            Console.WriteLine(searchResultAsJson);
        }