コード例 #1
0
        public async Task <IActionResult> PostCropAsync([FromBody] Crop crop)
        {
            _logger.LogInformation("Begin PostCropAsync");

            CropEntity cropEntity = _mapper.Map <CropEntity>(crop);

            cropEntity = await _cropRepository.PostCropAsync(cropEntity);

            crop = _mapper.Map <Crop>(cropEntity);

            return(CreatedAtAction(nameof(GetCropAsync), "Crops", new { id = crop.GardenId }, crop));
        }
コード例 #2
0
        public async Task <IActionResult> PutCropAsync([FromRoute] int id, [FromBody] Crop crop)
        {
            _logger.LogInformation("Begin PutCropAsync");

            if (id != crop.CropId)
            {
                return(BadRequest());
            }

            CropEntity cropEntity = _mapper.Map <CropEntity>(crop);

            cropEntity = await _cropRepository.PutCropAsync(id, cropEntity);

            if (cropEntity != null)
            {
                // Map entity to dto
                crop = _mapper.Map <Crop>(cropEntity);
            }

            return(Ok(crop));
        }
コード例 #3
0
        public async Task <IActionResult> GetCropAsync([FromRoute] int id)
        {
            _logger.LogInformation("Begin GetCropAsync");

            if (id == 0)
            {
                return(BadRequest("The cropId is required."));
            }

            Crop       cropDto;
            CropEntity cropEntity = await _cropRepository.GetCropAsync(id);

            if (cropEntity != null)
            {
                // Map entity to dto
                cropDto = _mapper.Map <Crop>(cropEntity);
            }
            else
            {
                return(NotFound());
            }

            return(Ok(cropDto));
        }