コード例 #1
0
 public SuccessResponse Update(TipRequest request)
 {
     try
     {
         var currentTip = _tipRepository.FindBy(request.Id);
         currentTip.ThrowExceptionIfRecordIsNull();
         var tipToCopy = TypeAdapter.Adapt <Tip>(request);
         TypeAdapter.Adapt(tipToCopy, currentTip);
         _tipValidator.ValidateAndThrowException(currentTip, "Base");
         _tipRepository.Update(currentTip);
         return(new SuccessResponse {
             IsSuccess = true
         });
     }
     catch (DataAccessException)
     {
         throw new ApplicationException();
     }
 }
コード例 #2
0
        public async Task <TipResponse> UpdateAsync(int tipId, Tip tip)
        {
            var existingTip = await _tipRepository.FindById(tipId);

            if (existingTip == null)
            {
                return(new TipResponse("Tip not found"));
            }
            existingTip.Text = tip.Text;

            try
            {
                _tipRepository.Update(existingTip);
                await _unitOfWork.CompleteAsync();

                return(new TipResponse(existingTip));
            }
            catch (Exception ex)
            {
                return(new TipResponse($"An error ocurred while updating the tip: {ex.Message}"));
            }
        }
コード例 #3
0
 public void UpdateTip(Tip tip) => tipRepository.Update(tip);