public async Task <Result <int> > Handle(UpdateExpenseClaimLineItemCommand command, CancellationToken cancellationToken) { var expenseClaimLineItem = await _repository.GetByIdAsync(command.Id); if (expenseClaimLineItem == null) { return(Result <int> .Fail($"Product Not Found.")); } else { expenseClaimLineItem.ExpenseCategoryID = (command.ExpenseCategoryID == 0) ? expenseClaimLineItem.ExpenseCategoryID : command.ExpenseCategoryID; expenseClaimLineItem.Payee = command.Payee ?? expenseClaimLineItem.Payee; expenseClaimLineItem.Date = (command.Date == DateTime.MinValue) ? expenseClaimLineItem.Date : command.Date; expenseClaimLineItem.Description = command.Description ?? expenseClaimLineItem.Description; expenseClaimLineItem.Amount = (command.Amount == 0) ? expenseClaimLineItem.Amount : command.Amount; expenseClaimLineItem.CurrencyCode = command.CurrencyCode ?? expenseClaimLineItem.CurrencyCode; expenseClaimLineItem.CurrencyID = (command.CurrencyID == 0) ? expenseClaimLineItem.CurrencyID : command.CurrencyID; expenseClaimLineItem.UsdAmount = (command.UsdAmount == 0) ? expenseClaimLineItem.UsdAmount : command.UsdAmount; expenseClaimLineItem.Receipt = command.Receipt ?? expenseClaimLineItem.Receipt; await _repository.UpdateAsync(expenseClaimLineItem); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(expenseClaimLineItem.Id)); } }
public async Task <Result <GetExpenseClaimLineItemByIdResponse> > Handle(GetExpenseClaimLineItemByIdQuery query, CancellationToken cancellationToken) { var expenseClaimLineItem = await _repository.GetByIdAsync(query.Id); var mappedExpenseClaimLineItem = _mapper.Map <GetExpenseClaimLineItemByIdResponse>(expenseClaimLineItem); return(Result <GetExpenseClaimLineItemByIdResponse> .Success(mappedExpenseClaimLineItem)); }
public async Task <Result <int> > Handle(DeleteExpenseClaimLineItemCommand command, CancellationToken cancellationToken) { var expenseClaimLineItem = await _repository.GetByIdAsync(command.Id); await _repository.DeleteAsync(expenseClaimLineItem); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(expenseClaimLineItem.Id)); }