Exemplo n.º 1
0
        public async Task <IActionResult> UpdateCategoryByIdAsync(
            [FromRoute] int categoryId,
            [FromBody] UpdateCategoryRequestDto updateCategoryRequestDto,
            CancellationToken token = default)
        {
            try
            {
                var validationResult = await _updateCategoryRequestValidator.ValidateAsync(updateCategoryRequestDto, token);

                if (!validationResult.IsValid)
                {
                    return(new BadRequestObjectResult(validationResult.Errors.ToValidationErrors()));
                }

                var categoryServiceObject = Mapper.Map <CategoryServiceObject>(updateCategoryRequestDto);
                categoryServiceObject.Id = categoryId;
                var serviceResult = await _categoryService.UpdateCategoryByIdAsync(categoryServiceObject, token);

                return(new OkObjectResult(Mapper.Map <UpdateCategoryResponseDto>(serviceResult)));
            }
            catch (Exception)
            {
                return(new BadRequestResult());
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult UpdateCategory(UpdateCategoryRequestDto updateCategoryRequestDto)
        {
            Category category = _categoryMapper.ToCategory(updateCategoryRequestDto);

            _categoryService.UpdateCategory(category);
            return(new StatusCodeResult(HttpStatusCode.NoContent, this));
        }
Exemplo n.º 3
0
 public Category ToCategory(UpdateCategoryRequestDto updateCategoryRequestDto)
 {
     return(new Category()
     {
         Id = updateCategoryRequestDto.Id,
         Type = updateCategoryRequestDto.Type
     });
 }
Exemplo n.º 4
0
        public async Task <ActionResult <UpdateCategoryResponseDto> > Update(UpdateCategoryRequestDto request)
        {
            try
            {
                var category = await _service.UpdateCategory(request);

                return(Ok(category));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
            }
        }
Exemplo n.º 5
0
        public async Task<UpdateCategoryResponseDto> UpdateCategory(UpdateCategoryRequestDto request)
        {
            try
            {
                Category category;
                category = await _repository.GetCategoryById(request.ID);
                category.Name = request.Name;

                category = await _repository.UpdateAsync(category);

                UpdateCategoryResponseDto response = new UpdateCategoryResponseDto()
                {
                    ID = category.ID,
                    Name = category.Name
                };

                return response;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }