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); })); }
/// <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()); } }
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); }
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); }
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); }
/// <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()); } }