Пример #1
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));
            }

            var val = new ObjectValidator();

            //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));
        }
Пример #2
0
        public Game Add(Game game)
        {
            //Validate input
            if (game == null)
            {
                throw new ArgumentNullException(nameof(game));
            }

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

            // if (!game.Validate())
            //  throw new Exception("Game is invalid.");

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

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

            return(AddCore(game));
        }