public ActionResult Order(int id) { BoardGame b = _context.BoardGames.Single(m => m.Id == id); string clientId = User.Identity.GetUserId(); //readerId is same as userId Client r = _context.Clients.First(m => m.Id == clientId); if (b == null) { Alert("Użyto niewłaściwego id gry."); } else { if (b.Amount <= 0) { Alert("Gra jest niedostępna."); } else { List <BoardGameCopy> boardGameCopies = _context.BoardGameCopies.Where(m => m.ClientRefId == clientId).ToList(); BoardGameCopy temp = boardGameCopies.Find(m => m.BoardGameRefId == id); if (temp == null) { b.Amount -= 1; BoardGameCopy copy = _context.BoardGameCopies.First( m => (m.BoardGameRefId == id && m.ClientRefId == null) ); copy.ClientRefId = clientId; _context.SaveChanges(); Success("Zarezerwowano grę."); } else { Alert("Już wypożyczyłeś tą grę, można wypożyczyć tylko jeden egzemplarz danej gry."); return(RedirectToAction("Details/" + id, "BoardGame")); } } } return(RedirectToAction("Index", "BoardGame")); }
public ActionResult Save(BoardGame boardGame) { if (!ModelState.IsValid) { Alert("Nie udało się dodać nowej gry."); return(View("Add", boardGame)); } else { _context.BoardGames.Add(boardGame); for (int i = 0; i < boardGame.Amount; i++) { BoardGameCopy c = new BoardGameCopy { BoardGameRefId = boardGame.Id }; _context.BoardGameCopies.Add(c); } _context.SaveChanges(); Info("Nowa gra dodana."); return(RedirectToAction("Index", "BoardGame")); } }