Beispiel #1
0
        public JsonResult List(int?id)
        {
            //string to return no data if there are no bids on item
            string nothing = "";

            //new dashboard item created
            BidDashBoardVM bidList = new BidDashBoardVM();

            //item is pulled from database based on item id
            bidList.Item = db.Items.Find(id);
            //its list of bids is pulled also based on its specific id
            bidList.Bids = db.Bids.Where(x => x.ItemID.Equals(1001)).OrderByDescending(i => i.Price).ToList();

            //if the bids list is greater than 0
            if (bidList.Item.Bids.Count > 0)
            {
                //create a new var list of bids allowing me to select and name specific columns
                var list = db.Bids
                           .Select(i => new { Ident = i.ItemID, Name = i.BuyerFullName, Amount = i.Price, CreateDate = i.TimeStamp })
                           .OrderByDescending(i => i.Amount)
                           .Where(i => i.Ident == id)
                           .ToList();
                //return this list in json format for processing
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            //return an empty string if there are no bids
            return(Json(nothing, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index()
        {
            //create a VM item that has the top 10 most recent bids to the home index page
            BidDashBoardVM vm   = new BidDashBoardVM();
            var            bids = db.Bids.OrderByDescending(i => i.TimeStamp).Take(10).ToList();

            //return the list
            return(View(bids));
        }
        // GET: Items/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BidDashBoardVM item = new BidDashBoardVM()
            {
                Item = db.Items.Find(id)
            };

            if (item == null)
            {
                return(HttpNotFound());
            }
            return(View(item));
        }