コード例 #1
0
        /// <summary>
        /// Record that quiz has been completed.  Mark Citation as Closed.
        /// </summary>
        /// <param name="payload"></param>
        /// <returns></returns>
        public async Task CompleteWarningQuiz(string payload)
        {
            var warningQuizReponse = JsonConvert.DeserializeObject <TypeFormPayload>(payload);

            var accountDetail = await _commonCtx.CommonAccounts
                                .Include(m => m.Partition)
                                .Where(account => account.Id == warningQuizReponse.AccountId)
                                .SingleOrDefaultAsync();

            var _accountCtx = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(accountDetail.Partition.ConnectionString));


            var citation = await _accountCtx.Citations.ForAccount(accountDetail.Id)
                           .Where(m => m.Id == warningQuizReponse.CitatoinId)
                           .OrderByDescending(m => m.CreateUtc)
                           .FirstOrDefaultAsync();

            //Close Citation
            citation.Status       = Data.Enums.CitationStatus.Closed;
            citation.ClosedReason = "Warning Quiz Complete";

            //Add warning quiz record
            var warningQuiz = new WarningQuizResponse {
                AccountId = accountDetail.Id, CitationId = citation.Id, Payload = payload, CreateUserId = citation.CreateUserId, UpdateUserId = citation.CreateUserId
            };

            _accountCtx.WarningEventRespones.Add(warningQuiz);
            await _accountCtx.SaveChangesAsync();

            //Create Audit event
            _citationSvc.CreateAuditEvent(accountDetail.Id, citation.Id, "Quiz Completed", citation.CreateUserId, Data.Enums.CitationAuditEvent.QuizComplete);
        }
コード例 #2
0
        /// <summary>
        /// Refunds the payment.  Adds a negative payment record to the Payments table against this citation
        /// </summary>
        /// <param name="paymentId"></param>
        /// <param name="accountNumber"></param>
        /// <param name="amountRefunded"></param>
        /// <returns></returns>
        public async Task RefundPayment(string paymentId, long accountNumber, int amountRefunded)
        {
            //Get Account Record
            var commonAccount = _commonCtx.CommonAccounts.Include(m => m.Partition).AsNoTracking().Where(m => m.Number == accountNumber).SingleOrDefault();

            if (commonAccount != null)
            {
                var accountContext = ContextsUtility.CreateAccountContext(Cryptography.Decrypt(commonAccount.Partition.ConnectionString));

                var payment = await accountContext.CitationPayments.Include(m => m.Citation).Where(m => m.ChargeId.Contains(paymentId)).FirstOrDefaultAsync();

                if (payment != null)
                {
                    payment.ChargeAmount = payment.ChargeAmount - amountRefunded;

                    var fineAmountRefunded = amountRefunded.PenniesToDollarAmount() - payment.ProcessingFee;

                    payment.Citation.Balance = payment.Citation.Balance - fineAmountRefunded;

                    await _citationSvc.CreateAuditEvent(commonAccount.Id, payment.CitationId, $"{string.Format("{0:C}",amountRefunded.PenniesToDollarAmount())} payment refunded", payment.CreateUserId, Data.Enums.CitationAuditEvent.CitationRefundPayment);
                }

                try
                {
                    accountContext.SaveChanges();
                }
                catch (Exception ex)

                {
                    _logger.Error(ex, $"Error trying to create Citation Refund Payment");
                }
            }
        }