public async Task <IActionResult> AddCategory([FromBody] CategoryInfoRequest categoryRequest) { Category newCategory = _mapper.Map <Category>(categoryRequest); var result = await _category.AddCategoryAsync(newCategory); return(CreatedAtAction(nameof(GetCategory), new { id = result.Id }, result)); }
public async Task <IActionResult> UpdateCategory(int id, [FromBody] CategoryInfoRequest categoryRequest) { Category updatedCategory = _mapper.Map <Category>(categoryRequest); var result = await _category.UpdateCategoryAsync(id, updatedCategory); return(Ok(result)); }
public async Task <(HttpStatusCode, CategoryViewModel)> UpdateCategory(CategoryInfoRequest categoryRequest) { var uri = API.Category.UpdateCategory(categoryRequest.Id); StringContent putData = new StringContent(JsonSerializer.Serialize(categoryRequest), Encoding.UTF8, "application/json"); var response = await _httpClient.PutAsync(uri, putData); if (!response.IsSuccessStatusCode) { return(response.StatusCode, null); } using var streamRead = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializer.DeserializeAsync <CategoryViewModel>(streamRead); return(response.StatusCode, result); }
public async Task <IActionResult> Update([FromBody] CategoryInfoRequest categoryRequest) { var(statusCode, category) = await categoryService.UpdateCategory(categoryRequest); return(StatusCode((int)statusCode, category)); }