Example #1
0
        protected async Task <FinanceOperationEmail> AcceptFeeImpl(string contents, DateTime operationDate, int feeChange,
                                                                   int money, PaymentType paymentType, Claim claim)
        {
            paymentType.EnsureActive();

            CheckOperationDate(operationDate);

            if (feeChange != 0 || money < 0)
            {
                claim.RequestAccess(CurrentUserId, acl => acl.CanManageMoney);
            }
            var state = FinanceOperationState.Approved;

            if (paymentType.UserId != CurrentUserId)
            {
                if (claim.PlayerUserId == CurrentUserId)
                {
                    //Player mark that he pay fee. Put this to moderation
                    state = FinanceOperationState.Proposed;
                }
                else
                {
                    claim.RequestAccess(CurrentUserId, acl => acl.CanManageMoney);
                }
            }

            var comment = AddCommentImpl(claim, null, contents, isVisibleToPlayer: true);

            var financeOperation = new FinanceOperation()
            {
                Created       = Now,
                FeeChange     = feeChange,
                MoneyAmount   = money,
                Changed       = Now,
                Claim         = claim,
                Comment       = comment,
                PaymentType   = paymentType,
                State         = state,
                ProjectId     = claim.ProjectId,
                OperationDate = operationDate,
            };

            comment.Finance = financeOperation;

            claim.FinanceOperations.Add(financeOperation);

            claim.UpdateClaimFeeIfRequired(operationDate);

            var email = await CreateClaimEmail <FinanceOperationEmail>(claim, contents,
                                                                       s => s.MoneyOperation,
                                                                       commentExtraAction : null,
                                                                       extraRecipients : new[] { paymentType.User });

            email.FeeChange = feeChange;
            email.Money     = money;
            return(email);
        }
Example #2
0
        protected async Task <FinanceOperationEmail> AcceptFeeImpl(string contents, DateTime operationDate, int feeChange,
                                                                   int money, PaymentType paymentType, Claim claim)
        {
            paymentType.EnsureActive();

            if (operationDate > Now.AddDays(1)
                ) //TODO[UTC]: if everyone properly uses UTC, we don't have to do +1
            {
                throw new CannotPerformOperationInFuture();
            }

            if (feeChange != 0 || money < 0)
            {
                claim.RequestMasterAccess(CurrentUserId, acl => acl.CanManageMoney);
            }
            var state = FinanceOperationState.Approved;

            if (paymentType.UserId != CurrentUserId)
            {
                if (claim.PlayerUserId == CurrentUserId)
                {
                    //Player mark that he pay fee. Put this to moderation
                    state = FinanceOperationState.Proposed;
                }
                else
                {
                    claim.RequestMasterAccess(CurrentUserId, acl => acl.CanManageMoney);
                }
            }

            var comment = AddCommentImpl(claim, null, contents, isVisibleToPlayer: true, extraAction: null);

            var financeOperation = new FinanceOperation()
            {
                Created       = Now,
                FeeChange     = feeChange,
                MoneyAmount   = money,
                Changed       = Now,
                Claim         = claim,
                Comment       = comment,
                PaymentType   = paymentType,
                State         = state,
                ProjectId     = claim.ProjectId,
                OperationDate = operationDate
            };

            comment.Finance = financeOperation;

            claim.FinanceOperations.Add(financeOperation);

            claim.UpdateClaimFeeIfRequired(operationDate);

            var email = EmailHelpers.CreateClaimEmail <FinanceOperationEmail>(claim, contents,
                                                                              s => s.MoneyOperation,
                                                                              commentExtraAction: null,
                                                                              initiator: await UserRepository.GetById(CurrentUserId),
                                                                              extraRecipients: new[] { paymentType.User });

            email.FeeChange = feeChange;
            email.Money     = money;
            return(email);
        }