예제 #1
0
        public ItemQuery ByQuery(string query)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentNullException(nameof(query));
            }
            var response = _folioRepository.ByQuery($"{path}?query=({query})");

            return(_jsonService.DeserializeObject <ItemQuery>(response));
        }
        public async Task <T> DeleteAsync <T>(string resource, Dictionary <string, string> additioalHeaders = null)
        {
            using (var client = CreateHttpClient(DefaultHeaders(additioalHeaders)))
            {
                using (var response = await client.DeleteAsync(GetRequestUrl(BaseUrl, resource)))
                {
                    ThrowIfNotSuccess(response);

                    var data = await response.Content.ReadAsStringAsync();

                    return(_jsonService.DeserializeObject <T>(data));
                }
            }
        }
        private async Task <string> GetToken()
        {
            var requestToken = HttpRequestToken.Build(_spotifySettings.TokenUrl, _spotifySettings.ClientId, _spotifySettings.ClientSecret);

            var response = await _httpService.GetTokenBasic(requestToken);

            if (!response.IsSuccess())
            {
                Response.BuildInternalServerError();
            }

            var valueToken = _jsonService.DeserializeObject <SpotifyToken>(response.GetDataString());

            return(valueToken.access_token);
        }
예제 #4
0
        public async Task <Result <LocationSiteModel> > GetLocation(GetLocationFromBody getLocationFromBody)
        {
            var filter   = _filterBuildService.BuildLocationFilter(getLocationFromBody);
            var response = await _eccSetupRestApi.GetLocation($"{UrlsConfig.EccSetup}{UrlsConfig.EccSetupOperations.GetLocation(_apiVersion, filter)}");

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var contentAsString = await response.Content.ReadAsStringAsync();

                var locationsModel = _jsonService.DeserializeObject <LocationsModel>(contentAsString);
                var locationModel  = _locationBuildService.BuildLocation(locationsModel);

                return(Result.Ok(locationModel));
            }
            else
            {
                return(Result.Fail <LocationSiteModel>("Error on getting location"));
            }
        }
        public Instance Post(InstanceBasic item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }
            var response = _folioRepository.Post(path, _jsonService.SerializeObject(item));

            return(_jsonService.DeserializeObject <Instance>(response));
        }
예제 #6
0
        public FolioUser ByUserName(string userName)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException(nameof(userName));
            }

            var response = _folioRepository.ByQuery($"{path}?query=(username={userName})");
            var users    = _jsonService.DeserializeObject <FolioUserNameQuery>(response);

            if (users.TotalRecords == 1)
            {
                return(users.Users[0]);
            }
            else if (users.TotalRecords > 1)
            {
                throw new FolioUserException($"Hittade flera användare med användarnamnet {userName}");
            }
            else
            {
                throw new FolioUserException($"Hittade ingen användare med användarnamnet {userName}");
            }
        }
        public ActionResult Save(string id, string chillinText)
        {
            var json    = new ResultResponse();
            var chillin = _jsonService.DeserializeObject <ChillinText>(chillinText);

            try
            {
                _chillinTextRepository.Put(id, new ChillinText
                {
                    CheckInNote       = chillin.CheckInNote,
                    CheckOutNote      = chillin.CheckOutNote,
                    StandardTitleText = chillin.StandardTitleText
                });
                json.Success = true;
                json.Message = "Sparade ny text.";
            }
            catch (Exception e)
            {
                json.Success = false;
                json.Message = "Error: " + e.Message;
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }