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)); }
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)); }
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)); }