public async Task <IActionResult> Post(CropCategoryRequest request) { try { CropCategory cropCategory = _mapper.Map(request); cropCategory = await _repository.AddAsync(cropCategory); return(CreatedAtAction(nameof(GetById), new { id = cropCategory.Id }, _mapper.Map(cropCategory))); } catch (DataStoreException e) { _logger.LogError(e.Message, e, request); return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async Task <IActionResult> Put(Guid id, CropCategoryRequest request) { try { CropCategory cropCategory = await _repository.GetByIdAsync(id); if (cropCategory == null) { return(NotFound()); } _mapper.Map(cropCategory, request); await _repository.UpdateAsync(cropCategory); return(Ok()); } catch (DataStoreException e) { _logger.LogError(e.Message, e, request); return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }