private async Task <Tuple <Comment, Comment> > AddTransferCommentsAsync( Claim claimFrom, Claim claimTo, ClaimPaymentTransferRequest request) { // Comment to source claim Comment commentFrom = CommentHelper.CreateCommentForDiscussion( claimFrom.CommentDiscussion, CurrentUserId, Now, request.CommentText, true, null); commentFrom.Finance = new FinanceOperation { OperationType = FinanceOperationType.TransferTo, MoneyAmount = -request.Money, OperationDate = request.OperationDate, ProjectId = request.ProjectId, ClaimId = request.ClaimId, LinkedClaimId = request.ToClaimId, Created = Now, Changed = Now, State = FinanceOperationState.Approved, }; UnitOfWork.GetDbSet <Comment>().Add(commentFrom); // Comment to destination claim Comment commentTo = CommentHelper.CreateCommentForDiscussion( claimTo.CommentDiscussion, CurrentUserId, Now, request.CommentText, true, null); commentTo.Finance = new FinanceOperation { OperationType = FinanceOperationType.TransferFrom, MoneyAmount = request.Money, OperationDate = request.OperationDate, ProjectId = request.ProjectId, ClaimId = request.ToClaimId, LinkedClaimId = request.ClaimId, Created = Now, Changed = Now, State = FinanceOperationState.Approved, }; await UnitOfWork.SaveChangesAsync(); return(Tuple.Create(commentFrom, commentTo)); }
/// <inheritdoc /> public async Task TransferPaymentAsync(ClaimPaymentTransferRequest request) { // Loading source claim Claim claimFrom = await ClaimsRepository.GetClaim(request.ProjectId, request.ClaimId); if (claimFrom == null) { throw new JoinRpgEntityNotFoundException(request.ClaimId, nameof(Claim)); } if (!claimFrom.HasMasterAccess(CurrentUserId, acl => acl.CanManageMoney)) { throw new NoAccessToProjectException(claimFrom.Project, CurrentUserId); } // Loading destination claim Claim claimTo = await ClaimsRepository.GetClaim(request.ProjectId, request.ToClaimId); if (claimTo == null) { throw new JoinRpgEntityNotFoundException(request.ToClaimId, nameof(Claim)); } // Checking money amount var availableMoney = claimFrom.GetPaymentSum(); if (availableMoney < request.Money) { throw new PaymentException(claimFrom.Project, $"Not enough money at claim {claimFrom.Name} to perform transfer"); } // Adding comments await AddTransferCommentsAsync( claimFrom, claimTo, request); }