コード例 #1
0
        protected Task <Response <T> > ExecutePutAsync(T dto)
        {
            var requestBody = JsonConvert.SerializeObject(dto);
            var itemUri     = _resourceUri.AddSegment(dto.Id);

            return(Execute(async httpClient =>
            {
                var response = await httpClient.PutAsync(itemUri, new StringContent(requestBody, Encoding.UTF8, "application/json"));
                return await CreateResponse <T>(response, HttpStatusCode.OK);
            }));
        }
コード例 #2
0
        /// <summary>
        /// Send get request to server to get list of user requets about file changing
        /// </summary>
        /// <param name="userGuid">User's id</param>
        /// <returns>List of user's requests </returns>
        public IEnumerable <UserRequest> GetUserRequests(Guid userGuid)
        {
            var response = _client.GetAsync(_serviceBaseUri.AddSegment(nameof(GetUserRequests)).AddUriParam(nameof(userGuid), userGuid.ToString())).Result;

            if (response.IsSuccessStatusCode)
            {
                return(response.Content.ReadAsAsync <IEnumerable <UserRequest> >().Result);
            }
            else
            {
                throw new InvalidOperationException("Get user requests failed with " + response.StatusCode.ToString());
            }
        }
コード例 #3
0
        public IEnumerable <User> GetAllUsers()
        {
            var response = _client.GetAsync(_serviceBaseUri.AddSegment(nameof(GetAllUsers))).Result;

            if (response.IsSuccessStatusCode)
            {
                return(response.Content.ReadAsAsync <IEnumerable <User> >().Result);
            }
            else if (response.StatusCode != HttpStatusCode.NotFound)
            {
                throw new InvalidOperationException("Get failed with " + response.StatusCode.ToString());
            }

            return(null);
        }
コード例 #4
0
        public T GetById <I>(I Id)
        {
            if (Id == null)
            {
                return(default(T));
            }
            var response = client.GetAsync(ServiceBaseUri.AddSegment(Id.ToString())).Result;

            if (response.IsSuccessStatusCode)
            {
                return(response.Content.ReadAsAsync <T>().Result as T);
            }
            else if (response.StatusCode != HttpStatusCode.NotFound)
            {
                throw new InvalidOperationException("Get failed with " + response.StatusCode.ToString());
            }
            return(null);
        }
コード例 #5
0
        public IEnumerable <Collection> GetCollections()
        {
            IEnumerable <Collection> collections = default(IEnumerable <Collection>);

            try
            {
                using (var response = _client.GetAsync(baseUri.AddSegment("collections")))
                {
                    HttpResponseMessage message = response.Result;
                    message.EnsureSuccessStatusCode();

                    collections = message.Content.ReadAsAsync <IEnumerable <Collection> >().Result;
                }
            }
            catch
            {
                throw;
            }

            return(collections);
        }
コード例 #6
0
        /// <summary>
        /// Sends post request to server to save information about new user
        /// </summary>
        /// <param name="user">User to save</param>
        public void AddUser(User user)
        {
            var response = _client.PostAsJsonAsync(_serviceBaseUri.AddSegment(nameof(AddUser)), user).Result;

            if (!response.IsSuccessStatusCode)
            {
                throw new InvalidOperationException("Create failed with " + response.StatusCode.ToString());
            }
        }