コード例 #1
0
ファイル: GameDataBase.cs プロジェクト: matthewMtcc/ITSE1430
        public Game Add(Game game)
        {
            //Validate input
            if (game == null)
            {
                throw new ArgumentNullException(nameof(game));
            }

            //Game must be valid
            ObjectValidator.Validate(game);

            //Game names must be unique
            var existing = FindByName(game.Name);

            if (existing != null)
            {
                throw new Exception("Game must be unique.");
            }

            return(AddCore(game));
        }
コード例 #2
0
        public Game Update( int id, Game game )
        {
            //Validate
            if (id <= 0)
                throw new ArgumentOutOfRangeException(nameof(id), "Id must be > 0.");
            if (game == null)
                throw new ArgumentNullException(nameof(game));

            //new ObjectValidator().Validate(game);
            ObjectValidator.Validate(game);

            var existing = GetCore(id);
            if (existing == null)
                throw new Exception("Game does not exist.");

            //Game names must be unique            
            var sameName = FindByName(game.Name);
            if (sameName != null && sameName.Id != id)
                throw new Exception("Game must be unique.");

            return UpdateCore(id, game);
        }