Example #1
0
        public PartialViewResult GetBidsList(int lotId)
        {
            IEnumerable <BidViewModel> bids  = _bidService.GetAllBidEntitiesByLotId(lotId).Select(b => b.ToMvcBid()).OrderByDescending(b => b.Price);
            BidListViewModel           model = new BidListViewModel {
                Bids = bids, LotId = lotId, Price = _lotService.GetLotEntity(lotId).ToMvcLot().CurrentPrice + 1
            };

            return(PartialView(model));
        }
Example #2
0
        public ActionResult GetBidsList(BidListViewModel model)
        {
            LotEntity currentLot       = _lotService.GetLotEntity((int)model.LotId);
            string    currentUserEmail = currentLot.User.Email;
            decimal   currentPrice     = currentLot.LastPrice ?? currentLot.StartPrice;

            if (currentUserEmail == User.Identity.Name)
            {
                ModelState.AddModelError("", "You can not add bid for your own lot");
            }
            else if ((model.Price <= currentPrice))
            {
                ModelState.AddModelError("", string.Format("Your bid must be higher than the last bet {0} byn ", currentPrice));
            }
            else if (ModelState.IsValid)
            {
                BidEntity newBid = new BidEntity {
                    Price = model.Price, LotId = model.LotId, UserId = _userService.GetUserByEmail(User.Identity.Name).Id, Date = DateTime.Now
                };
                if (_bidService.TryCreateBid(newBid, currentLot))
                {
                    currentLot.LastPrice = newBid.Price;
                    _lotService.UpdateLot(currentLot);
                }
                if (!Request.IsAjaxRequest())
                {
                    return(RedirectToAction("LotDetails", new { id = model.LotId }));
                }
                else
                {
                    model.Bids = _bidService.GetAllBidEntitiesByLotId(model.LotId).Select(b => b.ToMvcBid()).OrderByDescending(b => b.Price);
                    return(PartialView(model));
                }
            }
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("LotDetails", new { id = model.LotId }));
            }
            else
            {
                model.Bids = _bidService.GetAllBidEntitiesByLotId(model.LotId).Select(b => b.ToMvcBid()).OrderByDescending(b => b.Price);
                return(PartialView(model));
            }
        }
        public async Task <IActionResult> Bids()
        {
            var user = await _userManager.GetUserAsync(User);

            var userID = user.Id.ToString();
            IEnumerable <Bidding>   model   = _bidRepo.GetBidsByCompany(user);
            List <BidListViewModel> bidList = new List <BidListViewModel>();

            foreach (Bidding b in model)
            {
                BidListViewModel bl = new BidListViewModel();
                bl.amount      = b.amount;
                bl.companyName = user.UserName;
                Tender t = _tenderRepo.GetTender(b.tender_id);
                bl.tenderName = t.Tender_name;
                bl.status     = t.status;
                bl.tenderId   = t.Tender_Id;
                bidList.Add(bl);
            }
            IEnumerable <BidListViewModel> model1 = bidList;

            return(View(model1));
        }