Example #1
0
        public async Task <DataResult <IEnumerable <TicketInformation> > > GetTickets()
        {
            var client = _httpClientFactory.CreateClient();

            HttpResponseMessage response = await client.GetAsync(
                $"{_ticketServiceConfiguration.Endpoint}/GetTickets");

            if (response.IsSuccessStatusCode)
            {
                string result = await response.Content.ReadAsStringAsync();

                var options = new JsonSerializerOptions()
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                };
                var data = JsonSerializer.Deserialize <IEnumerable <TicketInformation> >(result, options);

                return(DataResult <IEnumerable <TicketInformation> > .Success(data));
            }
            else
            {
                // Log error
                return(DataResult <IEnumerable <TicketInformation> > .Failure($"Error: {response.ReasonPhrase}"));
            }
        }
Example #2
0
        public DataResult Delete(int id)
        {
            try
            {
                notebookManager.dataSource.Delete(id);
            }
            catch (DataSourceException e)
            {
                return(DataResult.Failure(e.Message));
            }

            return(DataResult.Success());
        }
Example #3
0
        public DataResult Update(Notebook notebook)
        {
            try
            {
                notebookManager.dataSource.Update(notebook);
            }
            catch (DataSourceException e)
            {
                return(DataResult.Failure(e.Message));
            }

            return(DataResult.Success());
        }
Example #4
0
        public DataResult Authenticate(string username, string password)
        {
            try
            {
                Web.Models.Token response = ChronicyWebApi.Shared.Authenticate(username, password);

                if (response.HasError)
                {
                    return(DataResult.Failure(response.ErrorMessage));
                }
            }
            catch (WebApiException e)
            {
                InformationDispatcher.Default.Dispatch(e, DebugLogContext.Current);
                return(DataResult.Failure("Could not authenticate"));
            }

            return(DataResult.Success());
        }