public bool CheckForSale(int sellerid) { DateTime dt = DateTime.Now; List <Auction> activeAuctions = _context.Auctions.Where(x => x.Closingdate <= dt && (x.Notify & 2) != 2 && x.Sellerid == sellerid).Include(y => y.Art).Include(z => z.Bids).ToList(); foreach (Auction ac in activeAuctions) { Bid bidAmount = ac.Bids.Where(z => z.Timeofbid < ac.Closingdate).OrderByDescending(x => x.Amount).FirstOrDefault(); decimal?bidAm = 0.00m; if (bidAmount != null) { bidAm = bidAmount.Amount; } Console.WriteLine($"Congatulations! your art piece {ac.Art.Name} sold for {bidAm} !"); Sellersinventory si = new Sellersinventory(); si.Artid = System.Convert.ToInt32(ac.Artid); si.Sellerid = sellerid; try { _context.Sellersinventories.Remove(_context.Sellersinventories.Where(x => x.Artid == ac.Artid).FirstOrDefault()); } catch { } Bid bd = ac.Bids.Where(z => z.Timeofbid < ac.Closingdate).OrderByDescending(x => x.Amount).FirstOrDefault(); decimal?bm = ac.Art.Currentvalue; if (bd != null) { bm = bd.Amount; } ac.Art.Currentvalue = bm; ac.Notify += 2; _context.SaveChanges(); } return(false); }
public mod.Art GetArt(int id, int sellerid) { Sellersinventory si = _context.Sellersinventories.Where(x => x.Artid == id && x.Sellerid == sellerid).FirstOrDefault(); if (si == null) { return(new mod.Art()); } Art art = _context.Arts.Where(x => x.Id == si.Artid).FirstOrDefault(); if (si == null) { Console.WriteLine("this Art Is not part of your inventory"); } return(_mapper.Parse(art)); }
public void AddInventory(int id, int sellerid) { Sellersinventory SellInv = new Sellersinventory(); if (_context.Sellersinventories.Where(x => x.Artid == id).Count() > 0) { Console.WriteLine("This Art is allready inventoried"); return; } else { SellInv.Artid = id; SellInv.Sellerid = sellerid; _context.Sellersinventories.Add(SellInv); _context.SaveChanges(); } }