コード例 #1
0
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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
ファイル: AuctionRepo.cs プロジェクト: Randomania/May26Troop
        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;
        }