public async Task <ActionResult <int> > CreateAsync(CategoryCreation categoryCreation) { int categoryId; try { categoryId = await _categoryService.CreateAsync(categoryCreation); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok(categoryId)); }
public async Task <int> CreateAsync(CategoryCreation categoryCreation) { var result = new ValidationResult(); await _validator.CategoryLabelDoesNotExistAsync(categoryCreation.Label, result); if (!result.IsValid) { throw new Exception(result.Message); } var entity = _mapper.Map <CategoryEntity>(categoryCreation); await _repository.CreateAsync(entity); await _unitOfWork.SaveChangesAsync(); return(entity.Id); }
public CategoryEntity Create(CategoryCreation creation) { return(_autoMapper.Map <CategoryEntity>(creation)); }