示例#1
0
        public IList <DisplayAuctionViewModel> GetAuctionViewModels(bool?open = null)
        {
            List <DisplayAuctionViewModel> models = null;

            using (AuctionDbContext db = new AuctionDbContext())
            {
                var q = db.AuctionItems.AsQueryable();

                if (open.HasValue)
                {
                    if (open.Value)
                    {
                        q = q.Where(a => a.Bids.Count() < a.NumberOfBids);
                    }
                    else
                    {
                        q = q.Where(a => a.Bids.Count() == a.NumberOfBids);
                    }
                }

                models = q.Select(a => new DisplayAuctionViewModel
                {
                    AuctionId   = a.AuctionItemId,
                    Description = a.Description,
                    IsOpen      = a.Bids.Count() < a.NumberOfBids,
                    MinimumBid  = a.MinimumBid,
                    Name        = a.Name
                }).ToList();
            }

            return(models);
        }
示例#2
0
        public IList<DisplayAuctionViewModel> GetAuctionViewModels(bool? open = null)
        {
            List<DisplayAuctionViewModel> models = null;

            using (AuctionDbContext db = new AuctionDbContext())
            {
                var q = db.AuctionItems.AsQueryable();

                if (open.HasValue)
                {
                    if (open.Value)
                        q = q.Where(a => a.Bids.Count() < a.NumberOfBids);
                    else
                        q = q.Where(a => a.Bids.Count() == a.NumberOfBids);
                }

                models = q.Select(a => new DisplayAuctionViewModel
                {
                    AuctionId = a.AuctionItemId,
                    Description = a.Description,
                    IsOpen = a.Bids.Count() < a.NumberOfBids,
                    MinimumBid = a.MinimumBid,
                    Name = a.Name
                }).ToList();
            }

            return models;
        }
示例#3
0
        public void AddBid(CreateBidViewModel model)
        {
            using (AuctionDbContext db = new AuctionDbContext())
            {
                Bid dbBid = new Bid
                {
                    AuctionItemId = model.AuctionItemId,
                    BidAmount = model.BidAmount,
                    Name = model.Name
                };

                db.Bids.Add(dbBid);
                db.SaveChanges();
            }
        }
示例#4
0
        public void AddBid(CreateBidViewModel model)
        {
            using (AuctionDbContext db = new AuctionDbContext())
            {
                Bid dbBid = new Bid
                {
                    AuctionItemId = model.AuctionItemId,
                    BidAmount     = model.BidAmount,
                    Name          = model.Name
                };

                db.Bids.Add(dbBid);
                db.SaveChanges();
            }
        }
示例#5
0
        public void CreateAuction(CreateAuctionViewModel model)
        {
            using (AuctionDbContext db = new AuctionDbContext())
            {
                AuctionItem dbAuction = new AuctionItem
                {
                    Description = model.Description,
                    MinimumBid = model.MinimumBid,
                    Name = model.Name,
                    NumberOfBids = model.NumberOfBids
                };

                db.AuctionItems.Add(dbAuction);
                db.SaveChanges();
            }
        }
示例#6
0
        public void CreateAuction(CreateAuctionViewModel model)
        {
            using (AuctionDbContext db = new AuctionDbContext())
            {
                AuctionItem dbAuction = new AuctionItem
                {
                    Description  = model.Description,
                    MinimumBid   = model.MinimumBid,
                    Name         = model.Name,
                    NumberOfBids = model.NumberOfBids
                };

                db.AuctionItems.Add(dbAuction);
                db.SaveChanges();
            }
        }
示例#7
0
        public CreateBidViewModel GetCreateBidViewModel(int auctionItemId)
        {
            CreateBidViewModel model = null;

            using (AuctionDbContext db = new AuctionDbContext())
            {
                model = db.AuctionItems.Where(a => a.AuctionItemId == auctionItemId).Select(a => new CreateBidViewModel
                {
                    AuctionItemId   = a.AuctionItemId,
                    AuctionItemName = a.Name,
                    MinimumBid      = a.MinimumBid,
                    HighestBid      = a.Bids.OrderByDescending(b => b.BidAmount).Select(b => b.BidAmount).FirstOrDefault()
                }).FirstOrDefault();
            }

            return(model);
        }
示例#8
0
        public DisplayAuctionViewModel GetAuctionDetailsViewModel(int auctionItemId)
        {
            DisplayAuctionViewModel model = null;

            using (AuctionDbContext db = new AuctionDbContext())
            {
                model = db.AuctionItems.Where(a => a.AuctionItemId == auctionItemId).Select(a => new DisplayAuctionViewModel
                {
                    AuctionId = a.AuctionItemId,
                    Bids = a.Bids.Select(b => new BidViewModel
                    {
                        BidAmount = b.BidAmount,
                        Name = b.Name
                    }).ToList(),
                    Description = a.Description,
                    MinimumBid = a.MinimumBid,
                    Name = a.Name
                }).FirstOrDefault();
            }

            return model;
        }
示例#9
0
        public DisplayAuctionViewModel GetAuctionDetailsViewModel(int auctionItemId)
        {
            DisplayAuctionViewModel model = null;

            using (AuctionDbContext db = new AuctionDbContext())
            {
                model = db.AuctionItems.Where(a => a.AuctionItemId == auctionItemId).Select(a => new DisplayAuctionViewModel
                {
                    AuctionId = a.AuctionItemId,
                    Bids      = a.Bids.Select(b => new BidViewModel
                    {
                        BidAmount = b.BidAmount,
                        Name      = b.Name
                    }).ToList(),
                    Description = a.Description,
                    MinimumBid  = a.MinimumBid,
                    Name        = a.Name
                }).FirstOrDefault();
            }

            return(model);
        }
示例#10
0
        public CreateBidViewModel GetCreateBidViewModel(int auctionItemId)
        {
            CreateBidViewModel model = null;

            using (AuctionDbContext db = new AuctionDbContext())
            {
                model = db.AuctionItems.Where(a => a.AuctionItemId == auctionItemId).Select(a => new CreateBidViewModel
                {
                    AuctionItemId = a.AuctionItemId,
                    AuctionItemName = a.Name,
                    MinimumBid = a.MinimumBid,
                    HighestBid = a.Bids.OrderByDescending(b => b.BidAmount).Select(b => b.BidAmount).FirstOrDefault()
                }).FirstOrDefault();
            }

            return model;
        }