public async Task <Response> SaveVoucher(VoucherRequest voucherRequest)
        {
            var existResident = _securityPaymentContext.ResidentInformation.ToList().FirstOrDefault(c => c.ResidentInformationId == voucherRequest.ResidentId);

            var paymentCalendarConfigurationExist = _securityPaymentContext.PaymentCalendar.ToList()
                                                    .Where(x => x.PaymentDate.Year == voucherRequest.PaymentCalendarDate.Year &&
                                                           x.PaymentDate.Month == voucherRequest.PaymentCalendarDate.Month &&
                                                           x.PaymentDate.Day == voucherRequest.PaymentCalendarDate.Day).ToList();

            if (paymentCalendarConfigurationExist != null && existResident.ResidentInformationId == voucherRequest.ResidentId)
            {
                ControlTransactionFields transactionInfo = TransactionInfo.GetTransactionInfo();

                IDbContextTransaction transaction = _securityPaymentContext.Database.BeginTransaction();

                Voucher paymentCalendarConfiguration = MaterializeVoucherByResident(voucherRequest, transactionInfo);

                await _securityPaymentContext.AddAsync <Voucher>(paymentCalendarConfiguration);

                await _securityPaymentContext.SaveChangesAsync();

                transaction.Commit();
                return(new Response {
                    Data = paymentCalendarConfiguration
                });
            }
            return(new Response {
                Message = "Failed, the payment configuration already exist!"
            });
        }
 private Voucher MaterializeVoucherByResident(VoucherRequest voucherRequest, ControlTransactionFields transactionInfo)
 {
     return(new Voucher
     {
         ResidentId = voucherRequest.ResidentId,
         PaymentCalendarDate = voucherRequest.PaymentCalendarDate,
         PaymentDate = voucherRequest.PaymentDate,
         PaymentAmmount = voucherRequest.PaymentAmmount,
         PendingAmmount = voucherRequest.PendingAmmount,
         TransactionDate = transactionInfo.TransactionDate,
         ComputerName = transactionInfo.ComputerName,
         UserTransaction = transactionInfo.UserTransaction
     });
 }
Exemplo n.º 3
0
        public async Task <IActionResult> SaveVoucher([FromBody] VoucherRequest voucherRequest)
        {
            var message = await _voucherService.SaveVoucher(voucherRequest);

            return(Ok(message));
        }