コード例 #1
0
        // GET: Auctions
        public ActionResult Index(string productName, decimal?minPrice, decimal?maxPrice, string state)
        {
            tryCompleted();
            SearchAuction searchAuction = new SearchAuction();

            searchAuction.ProductName = productName;
            searchAuction.MinPrice    = minPrice;
            searchAuction.MaxPrice    = maxPrice;
            searchAuction.State       = state;

            var findAllParameters = from sp in db.SystemParameters
                                    select sp;

            var last = findAllParameters.ToList().Last();

            var auction = from a in db.Auctions
                          select a;

            auction = auction.OrderByDescending(x => x.OpenedOn);
            if (!String.IsNullOrEmpty(productName))
            {
                string[] words     = productName.Split(null);
                var      predicate = PredicateBuilder.False <Auction>();

                foreach (var word in words)
                {
                    string temp = word;
                    predicate = predicate.Or(a => a.Name.ToLower().Contains(temp.ToLower()));
                }
                auction = auction.Where(predicate);
            }

            if (minPrice != null)
            {
                auction = auction.Where(s => s.CurrentPrice != null && s.StartPrice >= minPrice);
            }

            if (maxPrice != null)
            {
                auction = auction.Where(s => s.CurrentPrice != null && s.StartPrice <= maxPrice);
            }

            if (!String.IsNullOrEmpty(state))
            {
                auction = auction.Where(s => s.State == state);
            }

            var AuctionsAndParameters = new SearchAuctionContainer();

            AuctionsAndParameters.searchAuction = searchAuction;
            AuctionsAndParameters.auctionList   = auction.ToList().Take(last.RecentAuction);
            ViewBag.last = last;
            return(View(AuctionsAndParameters));
        }
コード例 #2
0
        public ActionResult AuctionsWon(string productName, decimal?minPrice, decimal?maxPrice, string state)
        {
            if (Session["User"] == null || Session["Admin"] != null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tryCompleted();
            SearchAuction searchAuction = new SearchAuction();

            searchAuction.ProductName = productName;
            searchAuction.MinPrice    = minPrice;
            searchAuction.MaxPrice    = maxPrice;
            searchAuction.State       = state;

            var findAllParameters = from sp in db.SystemParameters
                                    select sp;

            var last = findAllParameters.ToList().Last();

            var auction = from a in db.Auctions
                          select a;

            var id = ((User)Session["User"]).Id;

            auction = auction.Where(predicate: x => x.User == id && x.State == "COMPLETED");

            if (!String.IsNullOrEmpty(productName))
            {
                string[] words     = productName.Split(null);
                var      predicate = PredicateBuilder.False <Auction>();

                foreach (var word in words)
                {
                    string temp = word;
                    predicate = predicate.Or(a => a.Name.ToLower().Contains(temp.ToLower()));
                }
                auction = auction.Where(predicate);
            }

            if (minPrice != null)
            {
                auction = auction.Where(s => s.CurrentPrice != null && s.StartPrice >= minPrice);
            }

            if (maxPrice != null)
            {
                auction = auction.Where(s => s.CurrentPrice != null && s.StartPrice <= maxPrice);
            }

            if (!String.IsNullOrEmpty(state))
            {
                auction = auction.Where(s => s.State == state);
            }

            var AuctionsAndParameters = new SearchAuctionContainer();

            AuctionsAndParameters.searchAuction = searchAuction;
            AuctionsAndParameters.auctionList   = auction.ToList().Take(last.RecentAuction);
            ViewBag.last = last;
            return(View(AuctionsAndParameters));
        }