// GET: WinResults
        public async Task <IActionResult> Index(string bidBatch, string sortOrder, string bankName, string fwdDate)
        {
            IQueryable <string> batchQuery = from b in _context.AuctionBids
                                             orderby b.BatchRef
                                             select b.BatchRef;
            IQueryable <string> bankQuery = from d in _context.WinResults
                                            orderby d.BankName
                                            select d.BankName;

            var wins = from m in _context.WinResults
                       select m;

            if (!string.IsNullOrEmpty(bidBatch))
            {
                wins = wins.Where(x => x.BatchRef == bidBatch);
            }

            if (!string.IsNullOrEmpty(bankName))
            {
                wins = wins.Where(y => y.BankName == bankName);
            }

            if (!string.IsNullOrEmpty(fwdDate))
            {
                wins = wins.Where(z => z.FwdDate == Convert.ToDateTime(fwdDate));
            }

            switch (sortOrder)
            {
            case "sortByBank":
                wins = wins.OrderBy(s => s.BankName).ThenBy(s => s.FwdDate);
                break;

            case "sortByDate":
                wins = wins.OrderBy(s => s.FwdDate).ThenByDescending(s => s.FwdRate);
                break;
            }

            var bidVM = new BidBatchViewModel();

            bidVM.banks   = new SelectList(await bankQuery.Distinct().ToListAsync());
            bidVM.batches = new SelectList(await batchQuery.Distinct().ToListAsync());
            bidVM.wins    = await wins.ToListAsync();

            return(View(bidVM));
        }
Beispiel #2
0
        // GET: Bids
        public async Task <IActionResult> Index(string searchString, string fwdDate, string bidBatch)
        {
            //IQueryable<string> batchQuery = from b in _context.AuctionBids
            //                                orderby b.BatchRef
            //                                select b.BatchRef;

            var batchQ = _context.AuctionBids.OrderBy(u => u.BatchRef).Select(u => u.BatchRef);

            //var bids = from m in _context.AuctionBids
            //           select m;

            var bidQ = _context.AuctionBids.Select(u => u);

            if (!string.IsNullOrEmpty(searchString))
            {
                // bids = bids.Where(s => s.BankName.Contains(searchString));
                bidQ = bidQ.Where(u => u.BankName.Contains(searchString));
            }

            if (!string.IsNullOrEmpty(bidBatch))
            {
                // bids = bids.Where(x => x.BatchRef == bidBatch);
                bidQ = bidQ.Where(u => u.BatchRef == bidBatch);
            }

            if (!string.IsNullOrEmpty(fwdDate))
            {
                //bids = bids.Where(x => x.FwdDate == Convert.ToDateTime(fwdDate));
                bidQ = bidQ.Where(u => u.FwdDate == Convert.ToDateTime(fwdDate));
            }
            var bidVM = new BidBatchViewModel();

            // bidVM.batches = new SelectList(await batchQuery.Distinct().ToListAsync());
            bidVM.batches = new SelectList(await batchQ.Distinct().ToListAsync());
            // bidVM.bids = await bids.OrderBy(b => b.FwdDate).ThenByDescending(b => b.FwdRate).ToListAsync();
            bidVM.bids = await bidQ.OrderBy(b => b.FwdDate).ThenByDescending(b => b.FwdRate).ToListAsync();

            return(View(bidVM));
        }