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));
        }
示例#2
0
        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);
        }
示例#3
0
 public CategoryEntity Create(CategoryCreation creation)
 {
     return(_autoMapper.Map <CategoryEntity>(creation));
 }