示例#1
0
        public bool CheckForWin(int collectorid)
        {
            DateTime dt = DateTime.Now;

            List <Auction> activeAuctions = _context.Auctions.Where(x => x.Closingdate <= dt && (x.Notify & 1) != 1).Include(y => y.Art).Include(z => z.Bids).ToList();

            foreach (Auction ac in activeAuctions)
            {
                Bid bid = ac.Bids.Where(z => z.Timeofbid < ac.Closingdate).OrderByDescending(x => x.Amount).FirstOrDefault();

                if (bid != null && bid.Collectorid == collectorid)
                {
                    Console.WriteLine($"Congatulations! You had the winning bid of {bid.Amount} on the art piece {ac.Art.Name} ! Enjoy your art!");

                    Collectorsinventory ci = new Collectorsinventory();
                    int id = System.Convert.ToInt32(ac.Artid);
                    ci.Artid       = id;
                    ci.Collectorid = collectorid;
                    if (_context.Collectorsinventories.Where(x => x.Artid == ci.Artid).Count() < 1)
                    {
                        _context.Collectorsinventories.Add(ci);
                    }
                    ac.Art.Currentvalue = bid.Amount;
                    ac.Notify          += 1;
                    _context.SaveChanges();
                }
            }
            return(false);
        }
示例#2
0
        public void ShowArtByPrice()
        {
            Console.Clear();

            List <Art> arts = _context.Arts.Include(x => x.Artist).OrderByDescending(y => y.Currentvalue).ToList();

            Console.ForegroundColor = ConsoleColor.Green;

            foreach (Art a in arts)
            {
                Console.WriteLine("--------------------");
                Collectorsinventory ci = _context.Collectorsinventories.Where(x => a.Id == x.Artid).Include(y => y.Collector).FirstOrDefault();
                if (ci != null)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("This art belongs to " + ci.Collector.Name);
                }
                Auction auc = _context.Auctions.Where(x => x.Artid == a.Id && x.Closingdate > DateTime.Now).Include(y => y.Bids).FirstOrDefault();

                if (auc != null)
                {
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine($"This art is currently being Auctioned off with a high bid of {auc.Bids.OrderByDescending(x => x.Amount).FirstOrDefault().Amount}");
                }
                ArtDetails(a);
                Console.WriteLine($"Current Value : {a.Currentvalue}");
                Console.WriteLine($"Art by {a.Artist.Name}");
            }
            Console.WriteLine("--------------------");
            Console.ForegroundColor = ConsoleColor.Yellow;
        }