コード例 #1
0
        public async Task <DietResponse> AddAsync(DietRequest request)
        {
            var entity = _mapper.Map <Diet>(request);
            var result = await _unitOfWork.DietRepository.Add(entity);

            await _unitOfWork.SaveChanges();

            return(_mapper.Map <DietResponse>(result));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateDiet([FromBody] DietRequest request)
        {
            if (request == null)
            {
                return(NotFound());
            }
            var diet   = _mapper.Map <Diet>(request);
            var result = await _dietService.Update(diet);

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(diet));
        }
コード例 #3
0
        public async Task <DietResponse> UpdateAsync(DietRequest request)
        {
            var existingItem = await _unitOfWork.DietRepository.Get(request.Id);

            if (existingItem == null)
            {
                return(null);
            }


            var entity = _mapper.Map(request, existingItem);
            var result = await _unitOfWork.DietRepository.Update(entity);

            await _unitOfWork.SaveChanges();

            return(_mapper.Map <DietResponse>(result));
        }