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()); } }
public IHttpActionResult UpdateCategory(UpdateCategoryRequestDto updateCategoryRequestDto) { Category category = _categoryMapper.ToCategory(updateCategoryRequestDto); _categoryService.UpdateCategory(category); return(new StatusCodeResult(HttpStatusCode.NoContent, this)); }
public Category ToCategory(UpdateCategoryRequestDto updateCategoryRequestDto) { return(new Category() { Id = updateCategoryRequestDto.Id, Type = updateCategoryRequestDto.Type }); }
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)); } }
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; } }