public async Task <IActionResult> Add([FromBody] AddOperationRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var response = await _operationService.AddAsync(request);

            if (!response.IsValid)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response));
        }
Example #2
0
        public async Task <BaseResponse> AddAsync(AddOperationRequest request)
        {
            var category = await _categoryRepository.GetAsync(category => category.Id == request.CategoryId);

            if (category == null)
            {
                return(new BaseResponse("Category is not found"));
            }

            var operation = _mapper.Map <AddOperationRequest, Operation>(request);
            await _operationRepository.AddAsync(operation);

            await _unitOfWork.SaveChangesAsync();

            return(new BaseResponse());
        }