private async Task AddOneMediumAsync(string title, short year, string mediumType, string location) { var m = new BaseMediumDto(title, year, mediumType, location); var result = await PostAsync <OperationStatus, BaseMediumDto>("Medium", "Add", m); Debug.Assert(result.Value == 0); }
public override async Task <OperationStatus> UpdateAsync(MediumDto dto) { var b = new BaseMediumDto(dto.Title, dto.Year, dto.MediumType, dto.Location); var jsonContent = new StringContent(JsonConvert.SerializeObject(b), Encoding.UTF8, "application/json"); var response = await _client.PutAsync(_route, jsonContent); return(StatusFromResponse(response)); }
public override async Task <OperationStatus> AddAsync(MediumDto dto) { var result = OperationStatus.OK; var b = new BaseMediumDto(dto.Title, dto.Year, dto.MediumType, dto.Location); var jsonContent = new StringContent(JsonConvert.SerializeObject(b), Encoding.UTF8, "application/json"); var response = await _client.PostAsync(_route, jsonContent); result = StatusFromResponse(response); if (result == OperationStatus.OK) { var key = _keyService.ConstructMediumKey(dto.Title, dto.Year, dto.MediumType); var response1 = await _client.GetAsync($"{_route}/{key}"); var stringResponse = await response1.Content.ReadAsStringAsync(); _addResult = JsonConvert.DeserializeObject <MediumDto>(stringResponse); _addResult.Key = _keyService.ConstructMediumKey(dto.Title, dto.Year, dto.MediumType); } else { _addResult = null; } return(result); }
public async Task <OperationStatus> PutAsync([FromBody] BaseMediumDto model) { return(await _service.UpdateAsync(model)); }
public async Task <OperationResult <IKeyedDto> > PostAsync([FromBody] BaseMediumDto model) { return(await _service.AddAsync(model)); }