Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Update([FromBody] CategoryInfoRequest categoryRequest)
        {
            var(statusCode, category) = await categoryService.UpdateCategory(categoryRequest);

            return(StatusCode((int)statusCode, category));
        }