public IActionResult Details(int lotId) { var lot_vm = _lotsService.GetItem(lotId).ToVm(); lot_vm.Bids = _bidsService.GetAllBidsForLotWithUsers(lot_vm.LotId) .OrderByDescending(x => x.DateOfBid).ToVm(); return(View(lot_vm)); }
public async Task MakeBid(int userId, int lotId, decimal bidValue) { var lot = _lotsService.GetItem(lotId); if (lot == null) { _errors.AddError(nameof(lot.LotId), "Lot with id doesnt exist"); } var user = _userService.GetItem(userId); if (lot.Price >= bidValue) { _errors.AddError(nameof(bidValue), "Bid must be greater than value price"); } if (user.Money < bidValue) { _errors.AddError(nameof(bidValue), "Not enough funds"); } if (!_errors.Empty) { var res = JsonConvert.SerializeObject(_errors.Errors, Formatting.Indented); await Clients.Caller.SendAsync( "Error", res); return; } _userService.MakeBid(lot.LotId, userId, bidValue); var lastbid = _bidsService.GetLastBidForLot(lotId); var row_info = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr", lastbid.User.UserName, lastbid.Price, lastbid.DateOfBid.ToString("f")); await Clients.All.SendAsync("BidMade", lotId, row_info, lastbid.Price.ToString("C")); }