public async Task <IActionResult> Bet(LotDetailtViewModel model) { CarLot lot = carLotsRepository.GetDetailLot(model.BetId); User currentUser = await _userManager.GetUserAsync(HttpContext.User); if (lot.Price > model.BetPrice || lot.StartPrice > model.BetPrice) { return(RedirectToAction("Detail", new { id = lot.Id })); } if (ModelState.IsValid) { User user = await _userManager.GetUserAsync(HttpContext.User); Bet bet = new Bet { User = user, NewPrice = model.BetPrice, CarLot = lot, Time = DateTime.UtcNow }; lot.WinnerName = user.UserName; if (lot.Bets.Count > 1) { currentUser = lot.Bets.Last().User; } betRep.AddBet(bet); lot.Price = model.BetPrice; carLotsRepository.UpdateLot(lot); await updateHub.Clients.Group(lot.Id.ToString()).SendAsync("UpdateTable", lot.Id, bet.User.Id, bet.User.UserName, bet.NewPrice, bet.Time); if (lot.Bets.Count >= 1 && currentUser.Email != user.Email) { await Email.SendEmailAsync(currentUser.Email, "CarLots", $"Ваша ставка на товар {lot.Name} была перебита ставкой в {lot.Price} пользователем {user.UserName}"); } return(RedirectToAction("Detail", new { id = lot.Id })); } return(RedirectToAction("Detail", new { id = lot.Id })); }
public IActionResult Detail(int?id) { if (id != null) { CarLot lot = carLotsRepository.GetDetailLot(id); if (lot != null) { LotDetailtViewModel lot2 = new LotDetailtViewModel { Lot = lot, BetPrice = lot.Price + 50, BetId = (int)id }; return(View(lot2)); } logger.LogError("Doesn't exist lot. Controller:Lots. Action:Details"); } logger.LogError("Doesn't exist id. Controller:Lots. Action:Details"); return(RedirectPermanent("~/Error/Index?statusCode=404")); }