Exemple #1
0
        public async Task <string> AddEditPlanDetails(PlanViewModel model, string clientIpAddress)
        {
            try
            {
                var progIssuerId = (await _program.FindAsync(new { id = model.programId }))?.JPOS_IssuerId;
                var accounts     = await _programAccounts.GetAccountsDetailsByIds(model.PlanProgramAccount.Select(x => x.programAccountId).ToList());

                var pId = await AddEditPlan(model);

                if (pId > 0)
                {
                    if (model.id == 0)
                    {
                        var id        = model.Jpos_PlanId;
                        var planId    = "P1000-" + pId.ToString();
                        var oPlanJPOS = new PlanJposDto()
                        {
                            clientId    = model.clientId,
                            active      = true,
                            description = model.description,
                            endDate     = model.endDate.Value,
                            issuer      = progIssuerId,
                            startDate   = model.startDate.Value,
                            name        = model.name,
                            accounts    = accounts.Count > 0 ? String.Join(", ", accounts.Select(x => x.accountName).ToList()) : ""
                        };
                        int result = await _sharedJPOSService.PostRespectiveDataJPOS(JPOSAPIURLConstants.Plans, oPlanJPOS, id, clientIpAddress, JPOSAPIConstants.Plans);

                        var chkExist = await FindAsync(new { id = pId });

                        chkExist.planId      = planId;
                        chkExist.Jpos_PlanId = Convert.ToString(result);
                        await UpdateAsync(chkExist, new { id = pId });
                    }
                    var planprogramAccount = _mapper.Map <List <PlanProgramAccountsLinking> >(model.PlanProgramAccount);
                    planprogramAccount.ToList().ForEach(x => x.planId = pId);
                    await _planProgramAccount.AddUpdatePlanProgramAccount(planprogramAccount);

                    return(Cryptography.EncryptPlainToCipher(pId.ToString()));
                }
                return("0");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <string> AddEditProgramAccoutDetails(ProgramAccountViewModel model, string clientIpAddress)
        {
            try
            {
                var Id = await AddEditProgramAccount(model);

                if (Id > 0)
                {
                    if (model.id == 0)
                    {
                        var id           = model.Jpos_ProgramAccountId;
                        var progIssuerId = (await _program.FindAsync(new { id = model.programId }))?.JPOS_IssuerId;
                        var paid         = "PA1000-" + Id.ToString();
                        var oPlanJPOS    = new AccountsJposDto()
                        {
                            dailyLimit     = Convert.ToDouble(model.flexMaxSpendPerDay.Value),
                            weeklyLimit    = Convert.ToDouble(model.flexMaxSpendPerWeek.Value),
                            initialBalance = Convert.ToDouble(model.intialBalanceCount),
                            monthlyLimit   = Convert.ToDouble(model.flexMaxSpendPerMonth),
                            issuer         = progIssuerId,
                            active         = true,
                            name           = model.accountName,
                            layer          = "001",
                            roleOver       = model.isRollOver.HasValue && model.isRollOver.Value ? "Y" : "N"

                                             // accounts = accounts.Count > 0 ? String.Join(", ", accounts.Select(x => x.accountName).ToList()) : ""
                        };
                        int result = await _sharedJPOSService.PostRespectiveDataJPOS(JPOSAPIURLConstants.Accounts, oPlanJPOS, id, clientIpAddress, JPOSAPIConstants.Accounts);

                        var chkExist = await FindAsync(new { id = Id });

                        chkExist.ProgramAccountId = paid;
                        await UpdateAsync(chkExist, new { id = Id });
                    }
                    return(Cryptography.EncryptPlainToCipher(Id.ToString()));
                }
                return("0");
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <int> AddEditMerchantTerminal(List <OrganisationMerchantTerminalModel> model, string clientIpAddress)
        {
            int isSucces = 0;

            try
            {
                var orgid = model.FirstOrDefault().organisationId;
                var org   = await _organisation.FindAsync(new { id = orgid });

                var orgPrg = await _organisationProgram.FindAsync(new { organisationId = orgid });

                var prd = await _program.FindAsync(new { id = orgPrg?.programId });

                var result = await GetMultipleDataByConditionAsync(new { organisationId = orgid });

                var DeletionChk     = result.ToList().Where(x => !model.Select(m => m.id).ToList().Contains(x.id));
                var JposTerminalURL = JPOSAPIURLConstants.Terminals.Replace("{issuer}", prd?.JPOS_IssuerId).Replace("{merchant}", org?.JPOS_MerchantId);
                if (DeletionChk.ToList().Count > 0)
                {
                    foreach (var itemDelete in DeletionChk)
                    {
                        var             jposId        = itemDelete.Jpos_TerminalId;
                        TerminalJposDto oTerminalJpos = new TerminalJposDto()
                        {
                            active = false
                        };
                        await _sharedJPOSService.DeleteRespectiveDataJPOS(JposTerminalURL, oTerminalJpos, jposId, clientIpAddress, JPOSAPIConstants.Terminals);
                        await DeleteEntityAsync(new { itemDelete.id });
                    }
                }
                foreach (var item in model)
                {
                    var merchantExistCheck = await FindAsync(new { item.id });

                    var terminalTypeVal = (await _organisation.GetTerminalTypeList()).FirstOrDefault(x => x.Id == item.terminalType.Value).TerminalType;
                    if (merchantExistCheck != null)
                    {
                        merchantExistCheck.id = item.id;
                        merchantExistCheck.Jpos_TerminalId = item.Jpos_TerminalId;
                        merchantExistCheck.organisationId  = item.organisationId;
                        merchantExistCheck.terminalId      = item.terminalId;
                        merchantExistCheck.terminalName    = item.terminalName;
                        merchantExistCheck.terminalType    = item.terminalType;
                        await UpdateAsync(merchantExistCheck, new { item.id });

                        var             jposId        = item.Jpos_TerminalId;
                        TerminalJposDto oTerminalJpos = new TerminalJposDto()
                        {
                            active      = true,
                            info        = item.terminalName,
                            softVersion = terminalTypeVal,
                            terminalId  = item.terminalId
                        };
                        await _sharedJPOSService.PostRespectiveDataJPOS(JposTerminalURL, oTerminalJpos, jposId, clientIpAddress, JPOSAPIConstants.Terminals);
                    }
                    else
                    {
                        TerminalJposDto oTerminalJpos = new TerminalJposDto()
                        {
                            active      = true,
                            info        = item.terminalName,
                            softVersion = terminalTypeVal,
                            terminalId  = item.terminalId
                        };
                        int resultAdd = await _sharedJPOSService.PostRespectiveDataJPOS(JposTerminalURL, oTerminalJpos, null, clientIpAddress, JPOSAPIConstants.Terminals);

                        var obj = new MerchantTerminal();
                        obj.id              = item.id;
                        obj.organisationId  = item.organisationId;
                        obj.terminalId      = item.terminalId;
                        obj.terminalName    = item.terminalName;
                        obj.terminalType    = item.terminalType;
                        obj.Jpos_TerminalId = resultAdd.ToString();
                        await AddAsync(obj);
                    }
                }
                return(isSucces);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <IActionResult> AddUserTransaction(FiservMainTransactionModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Ok(new ApiBadRequestResponse(ModelState, MessagesConstants.BadRequest))); //400
                }
                var userIdClaim = Convert.ToInt32(User.Claims.FirstOrDefault(x => x.Type.ToLower(CultureInfo.InvariantCulture).Trim() == "userId".ToLower(CultureInfo.InvariantCulture).Trim()).Value);

                if (model.ProgramAccountIdSelected > 0)
                {
                    var planProgram = await _programAccount.GetUserProgramPlanNOrgByProgramAccountId(model.ProgramAccountIdSelected, model.CreditUserId);

                    model.PlanId         = planProgram?.planId;
                    model.ProgramId      = planProgram?.programId;
                    model.OrganizationId = planProgram?.OrganizationId;
                    model.AccountTypeId  = planProgram?.AccountTypeId;
                    model.OrganizationId = planProgram.OrganizationId;
                }
                var objUserTransaction = new UserTransactionInfo()
                {
                    accountTypeId = 3,
                    //accountTypeId = model.AccountTypeId,
                    createdBy   = userIdClaim,
                    createdDate = DateTime.UtcNow,
                    CreditTransactionUserType = TransactionUserEnityType.User,
                    creditUserId             = model.CreditUserId,
                    debitUserId              = userIdClaim,
                    DebitTransactionUserType = TransactionUserEnityType.Benefactor,
                    isActive                  = true,
                    isDeleted                 = false,
                    modifiedBy                = userIdClaim,
                    modifiedDate              = DateTime.UtcNow,
                    organisationId            = model.OrganizationId,
                    transactionAmount         = model.approvedAmount.total,
                    transactionDate           = model.TransactionDateTime,
                    TransactionId             = model.ipgTransactionId,
                    transactionStatus         = 1,
                    TransactionPaymentGateway = model.TransactionPaymentGateway,
                    //   programAccountId = model.ProgramAccountIdSelected,
                    programAccountId = model.ProgramId.Value,
                    programId        = model.ProgramId.Value,
                    planId           = model.PlanId,
                };
                var transactionUserAdd = await _userTransactionService.AddAsync(objUserTransaction);

                if (model.AccountTypeId == 3)
                {
                    var userCardAccountBalance = await _i2cAccountDetail.FindAsync(new { UserId = model.CreditUserId });

                    if (userCardAccountBalance != null)
                    {// That will work only for discretionary for i2c later
                        userCardAccountBalance.Balance = userCardAccountBalance.Balance + objUserTransaction.transactionAmount;
                        await _i2cAccountDetail.UpdateAsync(userCardAccountBalance, new { Id = userCardAccountBalance.Id });
                    }
                }
                var creditUserDetail = await _userRepository.FindAsync(new { Id = model.CreditUserId });

                var debitUserDetail = await _userRepository.FindAsync(new { Id = userIdClaim });

                /*  Notification  */
                var balanceContent = string.Empty;
                if (model.AccountTypeId == 1)
                {
                    balanceContent = string.Concat(objUserTransaction.transactionAmount, " meal passes");
                }
                else if (model.AccountTypeId == 2)
                {
                    balanceContent = string.Concat(objUserTransaction.transactionAmount, " flex points");
                }
                else if (model.AccountTypeId == 3)
                {
                    balanceContent = string.Concat("$", objUserTransaction.transactionAmount);
                }
                string notificationMessage = MessagesConstants.BalanceAddedNotificationMessage.Replace("{Benefactor}", string.Concat(debitUserDetail?.FirstName, " ", debitUserDetail?.LastName)).Replace("{Balance}", balanceContent), notificationTitle = MessagesConstants.BalanceAddedNotifyTitle;
                var    programNotificationSetCheck = await _program.FindAsync(new { id = creditUserDetail?.ProgramId });

                if (programNotificationSetCheck != null && programNotificationSetCheck.IsAllNotificationShow.Value)
                {
                    var serverApiKey       = (await _setting.GetGeneratSettingValueByKeyGroup(Constants.FireBaseConstants.FireBaseServerKey)).FirstOrDefault();
                    PushNotifications push = new PushNotifications();
                    var usrNotify          = await _userNotificationSettingsService.GetUserNotificationSettingByNotificaction(new List <int> {
                        creditUserDetail.Id
                    }, (int)NotificationSettingsEnum.Transaction);

                    if (usrNotify.Count > 0)
                    {
                        await push.SendPushBulk(new List <string> {
                            creditUserDetail?.UserDeviceId
                        }, notificationTitle, notificationMessage, "", userIdClaim.ToString(), "transaction", "icon", "transaction", 1, (serverApiKey != null ? serverApiKey.Value : ""), false, "AddBalance", 0);
                    }
                }
                await _userPushedNotificationService.AddAsync(new UserPushedNotifications()
                {
                    notificationMessage = notificationMessage,
                    notificationTitle   = notificationTitle,
                    notificationType    = (int)NotificationSettingsEnum.Transaction,
                    referenceId         = 1,
                    createdBy           = userIdClaim,
                    modifiedBy          = userIdClaim,
                    ProgramId           = creditUserDetail?.ProgramId,
                    userId              = creditUserDetail.Id,
                    IsRedirect          = true,
                    NotificationSubType = "AddBalance",
                    CustomReferenceId   = 0
                });

                return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, true, MessagesConstants.DataSuccessfullyReturned, transactionUserAdd)));
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(new Exception(string.Concat("API := (UserTransactions := AddUserTransaction)", ex.Message, " Stack Trace : ", ex.StackTrace, " Inner Exception : ", ex.InnerException)));
                return(Ok(new ApiResponse(StatusCodes.Status200OK, false, MessagesConstants.SomeIssueInProcessing)));
            }
        }