public async Task EditTransactionAsync(EditTransactionRequest request) { var entity = await GetTransactionEntityByIdAsync(request.TransactionId); entity.Description = request.Description; entity.Amount = request.Amount; entity.WalletId = request.WalletId; entity.LastUpdatedOn = request.UpdatedOn; await DbContext.SaveChangesAsync(); }
public async Task <IHttpActionResult> Update(EditTransactionRequest request, CancellationToken cancellationToken) { try { var command = mapper.Map <UpdateTransactionCommand>(request); var response = await mediator.Send(command, cancellationToken); return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Edit([FromBody] EditTransactionRequest request, [FromRoute] int accountId) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var response = await _transactionService.EditAsync(request, accountId); if (!response.IsValid) { return(BadRequest(response.Message)); } return(Ok(response)); }
public async Task <BaseResponse> EditAsync(EditTransactionRequest request, int accountId) { var transaction = await _transactionRepository.GetAsync(transaction => transaction.Id == request.Id); if (transaction == null) { return(new BaseResponse("Transaction is not found")); } var category = await _categoryRepository.GetAsync(category => category.Id == request.CategoryId && category.AccountId == accountId); if (category == null) { return(new ResultResponse <TransactionDto>("Category is not found")); } if (request.TagId.HasValue) { var tag = await _tagRepository.GetAsync(tag => tag.Id == request.TagId); if (tag == null) { return(new ResultResponse <TransactionDto>("Tag is not found")); } } if (request.SpentById.HasValue) { var spentBy = await _accountUserRepository.GetAsync(accountUser => accountUser.Id == request.SpentById); if (spentBy == null) { return(new ResultResponse <TransactionDto>("Account user is not found")); } } _transactionRepository.Update(transaction); await _unitOfWork.SaveChangesAsync(); return(new BaseResponse()); }