コード例 #1
0
        public IActionResult LendGame(LendViewModel lendViewModel)
        {
            var      game = _gameRepository.getById(lendViewModel.Game.GameId);
            Customer c    = FindCustomerByName(_customerRepository.GetAll().ToList());
            var      sum  = c.Money - game.Price;

            if (sum <= 0)
            {
                return(View("Error"));
            }
            else
            {
                c.Money = sum;

                game.Customer = c;

                _gameRepository.Update(game);

                _customerRepository.Update(c);

                var model = new LendViewModel
                {
                    Customers = c,
                    Game      = game,
                    Date      = DateTime.Now
                };

                _lendDataProvider.AddData(model);

                return(RedirectToAction("List"));
            }
        }