public async Task <IActionResult> GetAllWallets([FromQuery] WalletsParameter walletsParameter)
        {
            var getAllWalletsQuery = new GetAllWalletsQuery(walletsParameter);

            var result = await mediator.Send(getAllWalletsQuery);

            return(StatusCode((int)result.Code, result.Value));
        }
        public async Task <IActionResult> GetWaallets([FromQuery] WalletsParameter walletsParameter)
        {
            var getAllWalletsQuery = new GetAllWalletsQuery(walletsParameter);
            var result             = await mediator.Send(getAllWalletsQuery);

            if (result.Code == HttpStatusCode.OK)
            {
                Response.Headers.Add("X-Pagination", PagedList <Entity> .ToJson(result.Value as PagedList <Entity>));
            }

            return(StatusCode((int)result.Code, result.Value));
        }
Esempio n. 3
0
        public async Task <List <WalletResponse> > GetAllWallet(WalletsParameter walletsParameter)
        {
            var wallets = FindByCondition(x => x.Active == Convert.ToInt16(true)).ProjectTo <WalletResponse>(mapper.ConfigurationProvider);

            SearchByWallet(ref wallets, walletsParameter);
            FilterByDate(ref wallets, walletsParameter.FromDate, walletsParameter.ToDate);
            var sortedWallets = sortHelper.ApplySort(wallets, walletsParameter.OrderBy);
            var pagedWallets  = sortedWallets
                                .Skip((walletsParameter.PageNumber - 1) * walletsParameter.PageSize)
                                .Take(walletsParameter.PageSize);

            return(await pagedWallets.ToListAsync());
        }
        /// <summary>
        /// Gets all Wallet.
        /// </summary>
        /// <param name="walletsParameter">The Wallet parameters.</param>
        /// <returns></returns>
        public async Task <PagedList <Entity> > GetAllWallets(WalletsParameter walletsParameter)
        {
            {
                var getWalletsParams = new object[] {
                    new MySqlParameter("@p_IsForSingleTransaction", walletsParameter.IsForSingleTransaction),
                    new MySqlParameter("@p_IsForVendor", walletsParameter.IsForVendor),
                    new MySqlParameter("@p_IsForTransactionType", walletsParameter.IsForTransactionType),
                    new MySqlParameter("@p_Value", walletsParameter.Value),
                };
                var wallets = await FindAll("CALL SpSelectActiveWalletTransaction(@p_IsForSingleTransaction, @p_IsForVendor,@p_IsForTransactionType,@p_Value)", getWalletsParams).ToListAsync();

                var mappedSubscriptions = wallets.AsQueryable().ProjectTo <WalletResponse>(mapper.ConfigurationProvider);
                var sortedSubscriptions = sortHelper.ApplySort(mappedSubscriptions, walletsParameter.OrderBy);
                var shapedSubscriptions = dataShaper.ShapeData(sortedSubscriptions, walletsParameter.Fields);

                return(await PagedList <Entity> .ToPagedList(shapedSubscriptions, walletsParameter.PageNumber, walletsParameter.PageSize));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets all Wallet.
        /// </summary>
        /// <param name="walletsParameter">The Wallet parameters.</param>
        /// <returns></returns>
        public async Task <List <Wallets> > GetAllWallets(WalletsParameter walletsParameter)
        {
            var getWalletsParams = new object[]
            {
                new MySqlParameter("@p_Limit", walletsParameter.PageSize),
                new MySqlParameter("@p_Offset", (walletsParameter.PageNumber - 1) * walletsParameter.PageSize),
                new MySqlParameter("@p_VendorId", walletsParameter.VendorId),
                new MySqlParameter("@p_StatusId", walletsParameter.StatusId),
                new MySqlParameter("@p_Balance", walletsParameter.Balance),
                new MySqlParameter("@p_IsForCutoff", walletsParameter.IsForCutoff),
                new MySqlParameter("@p_IsForBalance", walletsParameter.IsForBalance),
                new MySqlParameter("@p_FromDate", walletsParameter.FromDate),
                new MySqlParameter("@p_ToDate", walletsParameter.ToDate)
            };

            var wallets = await FindAll("CALL SpSearchWallet(@p_Limit,@p_Offset,@p_VendorId,@p_StatusId,@p_Balance,@p_IsForCutoff,@p_IsForBalance,@p_FromDate,@p_ToDate)", getWalletsParams).ToListAsync();

            return(wallets);
        }
Esempio n. 6
0
 private void SearchByWallet(ref IQueryable <WalletResponse> wallets, WalletsParameter walletsParameter)
 {
     if (walletsParameter.VendorId > 0)
     {
         wallets = wallets.Where(x => x.VendorId.Equals(walletsParameter.VendorId));
     }
     if (walletsParameter.StatusId > 0)
     {
         wallets = wallets.Where(x => x.Status.Equals(walletsParameter.StatusId));
     }
     if (walletsParameter.IsForCutoff == true)
     {
         wallets = wallets.Where(x => x.Balance < walletsParameter.Balance);
     }
     else if (walletsParameter.IsForBalance == true)
     {
         wallets = wallets.Where(x => x.Balance == walletsParameter.Balance);
     }
 }
        /// <summary>
        /// Handles a request
        /// </summary>
        /// <param name="request">The request</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>
        /// Response from the request
        /// </returns>
        public async Task <APIResponse> Handle(CreateWalletDeductionCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var walletDeductionRequest = mapper.Map <Walletdeduction>(request.Request);

                var Category = await repository.MultiDetails.GetMultiDetailsByCode("CATEGORY");

                if (Category != null && Category.Count > 0)
                {
                    foreach (var item in Category)
                    {
                        if (item.Value.Trim().ToUpper() == request.Request.CategoryValue.Trim().ToUpper())
                        {
                            walletDeductionRequest.CategoryId = item.Id;
                            break;
                        }
                    }
                }

                bool IsCPL = false, IsCommission = false;

                if (walletDeductionRequest.DeductedAmount == 0 && walletDeductionRequest.CategoryId > 0)
                {
                    Core.DTO.Requests.WalletRule.WalletRuleParameter Parameter = new Core.DTO.Requests.WalletRule.WalletRuleParameter();
                    Parameter.Value = walletDeductionRequest.CategoryId;
                    Parameter.IsForServiceCategory = true;

                    var rule = await repository.WalletRule.GetAllWalletRule(Parameter);

                    if (rule != null && rule.Count > 0)
                    {
                        if (rule[0].Cplamount > 0)
                        {
                            walletDeductionRequest.DeductedAmount = (decimal)rule[0].Cplamount;
                            IsCPL = true;
                        }
                        else if (rule[0].CommissionAmount > 0)
                        {
                            walletDeductionRequest.DeductedAmount = (decimal)rule[0].CommissionAmount;
                            IsCommission = true;
                        }
                    }
                }
                else
                {
                    if (request.Request.LeadMode.Trim().ToUpper() == "CPL")
                    {
                        IsCPL = true;
                    }
                    else if (request.Request.LeadMode.Trim().ToUpper() == "COMMISSION")
                    {
                        IsCommission = true;
                    }
                    //else if(request.Request.LeadMode.Trim().ToUpper() == "BOTH")
                    //{

                    //}
                }

                WalletsParameter WP = new WalletsParameter();
                WP.VendorId = walletDeductionRequest.VendorId;
                var walletResponse = await repository.Wallets.GetAllWallets(WP);

                if (walletResponse != null && walletResponse.Count > 0)
                {
                    var Status = await repository.MultiDetails.GetMultiDetailByMultiDetailId(walletResponse[0].Status);

                    if (Status != null && Status.Value.Trim().ToUpper() != "DEDUCT")
                    {
                        return(new APIResponse(walletDeductionRequest, HttpStatusCode.NoContent));
                    }

                    decimal deductedBalance = ((walletResponse[0].Balance) - (walletDeductionRequest.DeductedAmount));

                    walletResponse[0].Balance = deductedBalance;
                    repository.Wallets.UpdateWallet(walletResponse[0]);

                    walletDeductionRequest.WalletBalance = deductedBalance;
                    repository.WalletDeduction.CreateWalletDeduction(walletDeductionRequest);

                    Core.Entity.Transactions transaction = new Core.Entity.Transactions();

                    transaction.WalletId = walletResponse[0].Id;

                    if (IsCPL)
                    {
                        transaction.Particulars = request.Request.LeadIdNumber + "-CPL deducted";
                    }
                    else if (IsCommission)
                    {
                        transaction.Particulars = request.Request.LeadIdNumber + "Commission deducted";
                    }
                    else
                    {
                        transaction.Particulars = "Wallet deducted";
                    }

                    transaction.TransactionDate = DateTime.UtcNow;

                    var StatusData = await repository.MultiDetails.GetMultiDetailsByCode("PAYMENT TYPE");

                    if (StatusData != null && StatusData.Count > 0)
                    {
                        foreach (var item in StatusData)
                        {
                            if (item.Value.Trim().ToUpper() == "DEBIT")
                            {
                                transaction.TransactionType = item.Id;
                                break;
                            }
                        }
                    }

                    transaction.Amount        = walletDeductionRequest.DeductedAmount;
                    transaction.WalletBalance = deductedBalance;
                    transaction.CreatedBy     = walletDeductionRequest.CreatedBy;
                    transaction.CreatedAt     = DateTime.UtcNow;

                    repository.Transactions.CreateTransactions(transaction);

                    await repository.SaveAsync();
                }

                return(new APIResponse(walletDeductionRequest, HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateWalletDeductionHandler()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetAllWalletsQuery"/> class.
 /// </summary>
 /// <param name="walletsParameter">The Wallet parameters.</param>
 public GetAllWalletsQuery(WalletsParameter walletsParameter)
 {
     WalletsParameter = walletsParameter;
 }