コード例 #1
0
ファイル: HistoryController.cs プロジェクト: vadalex/ibank
        public ActionResult Index(FormCollection collection)
        {
            List <HistoryItemModel>       HistoryItems = new List <HistoryItemModel>();
            Dictionary <int, CardAccount> CardAccounts = new Dictionary <int, CardAccount>();
            RouteValueDictionary          RouteValues  = new RouteValueDictionary();

            #region parsing

            List <string> cardIds = new List <string>();
            if (collection["item.CardAccount.CardAccountID"] == null)
            {
                return(View("Index", (object)"Не найдена информация о платежных картах"));
            }
            cardIds = collection["item.CardAccount.CardAccountID"].Split(',').Where(id => id != "false").ToList();

            if (cardIds.Any() == false)
            {
                return(View("Index", (object)"Не выбрана ни одна из карт"));
            }
            RouteValues.Add("item.CardAccount.CardAccountID", collection["item.CardAccount.CardAccountID"]);


            var      dateFrom = collection["datepicker-from"];
            var      dateTo   = collection["datepicker-to"];
            DateTime DateFrom;
            DateTime DateTo;
            try
            {
                DateFrom = String.IsNullOrEmpty(dateFrom) ? DateTime.MinValue : DateTime.Parse(dateFrom);
                DateTo   = String.IsNullOrEmpty(dateTo) ? DateTime.MaxValue : DateTime.Parse(dateTo);
            }
            catch (Exception ex)
            {
                return(View("Index", (object)ex.Message));
            }
            RouteValues.Add("datepicker-from", collection["datepicker-from"]);
            RouteValues.Add("datepicker-to", collection["datepicker-to"]);

            var arbitraryPaymentsParam = collection["arbitrary_payments"];
            var ssispPaymentsParam     = collection["ssisp_payments"];
            var mobilePaymentsParam    = collection["mobile_payments"];
            var transferPaymentsParam  = collection["transfer_payments"];
            if ((arbitraryPaymentsParam == null) && (ssispPaymentsParam == null) && (mobilePaymentsParam == null) &&
                (transferPaymentsParam == null))
            {
                return(View("Index", (object)"Ни один из типов платежей не выбран"));
            }

            RouteValues.Add("arbitrary_payments", collection["arbitrary_payments"]);
            RouteValues.Add("ssisp_payments", collection["ssisp_payments"]);
            RouteValues.Add("mobile_payments", collection["mobile_payments"]);
            RouteValues.Add("transfer_payments", collection["transfer_payments"]);
            #endregion parsing

            #region fill

            foreach (var cardId in cardIds)
            {
                var id = Int32.Parse(cardId);
                CardAccounts.Add(id, service.GetCardAccountById(id));
            }

            if (arbitraryPaymentsParam != null)
            {
                foreach (var cardId in cardIds)
                {
                    var payments = service.GetArbitraryTransactionsByCardId(Int32.Parse(cardId), DateFrom, DateTo);
                    if (payments != null && payments.Any())
                    {
                        foreach (var payment in payments)
                        {
                            HistoryItems.Add(new HistoryItemModel()
                            {
                                Amount        = payment.Amount,
                                CardNumber    = CardAccountModule.ConvertCardNumberString(CardAccounts[payment.CardAccountID].CardNumber),
                                Currency      = service.GetBankAccountCurrencyShortString(CardAccounts[payment.CardAccountID].BankAccountID),
                                Date          = payment.Date,
                                Recipient     = payment.Recipient,
                                TransactionId = payment.ArbitraryTransactionID,
                                Type          = payment.Type
                            });
                        }
                    }
                }
            }
            if (ssispPaymentsParam != null)
            {
                foreach (var cardId in cardIds)
                {
                    var payments = service.GetSSISTransactionsByCardId(Int32.Parse(cardId), DateFrom, DateTo);
                    if (payments != null && payments.Any())
                    {
                        foreach (var payment in payments)
                        {
                            HistoryItems.Add(new HistoryItemModel()
                            {
                                Amount        = payment.Amount,
                                CardNumber    = CardAccountModule.ConvertCardNumberString(CardAccounts[payment.CardAccountID].CardNumber),
                                Currency      = service.GetBankAccountCurrencyShortString(CardAccounts[payment.CardAccountID].BankAccountID),
                                Date          = payment.Date,
                                Recipient     = rep.SSISPayments.GetSingle(payment.SSISPaymentID).Name,
                                TransactionId = payment.SSISTransactionID,
                                Type          = payment.Type
                            });
                        }
                    }
                }
            }
            if (mobilePaymentsParam != null)
            {
                foreach (var cardId in cardIds)
                {
                    var payments = service.GetMobileTransactionsByCardId(Int32.Parse(cardId), DateFrom, DateTo);
                    if (payments != null && payments.Any())
                    {
                        foreach (var payment in payments)
                        {
                            HistoryItems.Add(new HistoryItemModel()
                            {
                                Amount        = payment.Amount,
                                CardNumber    = CardAccountModule.ConvertCardNumberString(CardAccounts[payment.CardAccountID].CardNumber),
                                Currency      = service.GetBankAccountCurrencyShortString(CardAccounts[payment.CardAccountID].BankAccountID),
                                Date          = payment.Date,
                                Recipient     = payment.MobileProvider,
                                TransactionId = payment.MobileTransactionID,
                                Type          = payment.Type
                            });
                        }
                    }
                }
            }
            if (transferPaymentsParam != null)
            {
                foreach (var cardId in cardIds)
                {
                    var payments = service.GetTransferTransactionsByCardId(Int32.Parse(cardId), DateFrom, DateTo);
                    if (payments != null && payments.Any())
                    {
                        foreach (var payment in payments)
                        {
                            HistoryItems.Add(new HistoryItemModel()
                            {
                                Amount        = payment.Amount,
                                CardNumber    = CardAccountModule.ConvertCardNumberString(CardAccounts[payment.CardAccountID].CardNumber),
                                Currency      = service.GetBankAccountCurrencyShortString(CardAccounts[payment.CardAccountID].BankAccountID),
                                Date          = payment.Date,
                                Recipient     = payment.Number,
                                TransactionId = payment.TransferTransactionID,
                                Type          = payment.Type
                            });
                        }
                    }
                }
            }
            #endregion fill

            HistoryListModel model = new HistoryListModel()
            {
                BackRouteValues = RouteValues,
                Items           = HistoryItems.OrderBy(x => x.Date).ToList()
            };

            return(View("HistoryList", model));
        }
コード例 #2
0
        public async Task <(IEnumerable <HistoryModel> HistoryModelList, int totalCount)> PrepareHistoryListModel(HistoryListModel model, int pageIndex, int pageSize)
        {
            string strHStatus = string.Empty;
            int    usrType    = (int)_workContext.CurrentCustomer.UserType;

            switch (model.Status)
            {
            case 1:
                strHStatus = "%";
                break;

            case 2:
                strHStatus = "O";
                break;

            case 3:
                strHStatus = "B";
                break;

            case 4:
                strHStatus = "C";
                break;

            case 5:
                strHStatus = "R";
                break;

            case 6:
                strHStatus = "I";
                break;

            case 7:
                strHStatus = "X";
                break;
            }

            var query = from h in _historyRepository.Table
                        select h;

            if (usrType == 1 || usrType == 3 || usrType == 4 || usrType == 90)
            {
                query = query.Where(h => h.HclientId == (int)_workContext.CurrentCustomer.ClientId);
            }
            else if (usrType == 2 || usrType == 6 || usrType == 7 || usrType == 8 || usrType == 10)
            {
                var costcenters = (from s in _shipRepository.Table.Where(c => c.ClientId == (int)_workContext.CurrentCustomer.ClientId && c.LogonId == (int)_workContext.CurrentCustomer.LogonId)
                                   select s).ToList();

                foreach (var c in costcenters)
                {
                    query = query.Where(h => h.HshipId.Contains(c.ShipId));
                }

                query = query.Where(h => h.HclientId == (int)_workContext.CurrentCustomer.ClientId);
            }
            else if (usrType == 15)
            {
                query = query.Where(h => h.HclientId == (int)_workContext.CurrentCustomer.ClientId);
            }

            if (strHStatus != "%")
            {
                query = query.Where(h => h.Hstatus.ToUpper() == strHStatus.ToUpper());
            }

            if (!string.IsNullOrEmpty(model.PO))
            {
                query = query.Where(h => h.Hpo.Contains(model.PO));
            }

            if (!string.IsNullOrEmpty(model.Dept))
            {
                query = query.Where(h => h.HshipId.Contains(model.Dept));
            }

            if (!string.IsNullOrEmpty(model.Item))
            {
                query = query.Where(h => h.Hoitem.Contains(model.Item));
            }

            if (!string.IsNullOrEmpty(model.Vendor))
            {
                query = query.Where(h => h.HvendorName.Contains(model.Vendor));
            }

            if (!string.IsNullOrEmpty(model.DateStart) && string.IsNullOrEmpty(model.DateEnd))
            {
                query = query.Where(c => c.Hdate >= Convert.ToDateTime(model.DateStart) && c.Hdate <= Convert.ToDateTime(model.DateStart).AddDays(1).AddTicks(-1));
            }

            if (!string.IsNullOrEmpty(model.DateStart) && !string.IsNullOrEmpty(model.DateEnd))
            {
                query = query.Where(c => c.Hdate >= Convert.ToDateTime(model.DateStart) && c.Hdate <= Convert.ToDateTime(model.DateEnd));
            }

            if (!string.IsNullOrEmpty(model.GL))
            {
                query = query.Where(h => h.Hgl.Contains(model.GL));
            }


            if (!string.IsNullOrEmpty(model.Invoice))
            {
                query = query.Where(h => h.Hinvoice.Contains(model.Invoice));
            }

            query = query.OrderByDescending(h => h.Hdate);

            var historyListModel = _mapper.Map <List <HistoryModel> >(query);

            int totalCount = historyListModel.Count;
            int pageOffSet = (Convert.ToInt32(pageIndex) - 1) * 10;

            historyListModel = historyListModel.Skip(pageOffSet).Take(Convert.ToInt32(pageSize)).ToList();

            return(historyListModel, totalCount);
        }