Ejemplo n.º 1
0
        public async Task <ActionResult> MakeBid(LotDetailViewModel model)
        {
            Lot lot = db.Lots.Include(l => l.User).Include(l => l.Bids).ThenInclude(b => b.User).FirstOrDefault(l => l.Id == model.BidId);

            if (ModelState.IsValid && lot.IsActual())
            {
                User user = await _userManager.GetUserAsync(HttpContext.User);

                Bid bid = new Bid
                {
                    User     = user,
                    NewPrice = model.BidPrice,
                    Lot      = lot,
                    Time     = DateTime.Now
                };
                db.Bids.Add(bid);
                lot.Price = model.BidPrice;
                db.Lots.Update(lot);
                db.SaveChanges();

                if (lot.Bids.Count() >= 2)
                {
                    User reciever = lot.Bids.ElementAt(lot.Bids.Count() - 2).User;
                    await _hubContext.Clients.User(reciever.Id).SendAsync("Notify", user.UserName + " has broken your bid on the " + lot.Name);
                }
                await _updateHubContext.Clients.AllExcept(user.Id).SendAsync("UpdateTable", lot.Id, bid.User.Id, bid.User.UserName, bid.NewPrice,
                                                                             Convert.ToInt64(bid.Time.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds));

                return(RedirectToAction("Detail", new { id = lot.Id }));
            }
            return(RedirectToAction("Detail", new { id = lot.Id }));
        }
Ejemplo n.º 2
0
 public ActionResult Detail(int?id)
 {
     if (id != null)
     {
         Lot lot = db.Lots.Include(l => l.User).Include(l => l.Bids).ThenInclude(b => b.User).FirstOrDefault(l => l.Id == id);
         if (lot != null)
         {
             LotDetailViewModel obj = new LotDetailViewModel
             {
                 Lot      = lot,
                 BidPrice = lot.Price + 100,
                 BidId    = (int)id
             };
             return(View(obj));
         }
     }
     return(NotFound());
 }