Beispiel #1
0
        public Character Update(int id, Character character)
        {
            //Validate
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id), "Id must be > 0.");
            }
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }
            if (!character.Validate())
            {
                throw new Exception("Invalid.");
            }


            var index = GetIndex(id);

            if (index < 0)
            {
                throw new Exception("Character does not exist.");
            }

            // names must be unique
            var existingIndex = GetIndex(character.Name);

            if (existingIndex >= 0 && existingIndex != index)
            {
                throw new Exception("Name is already being used.");
            }

            character.Id = id;
            var existing = _items[index];

            Clone(existing, character);


            return(character);
        }
        public Character Update(int id, Character kaiju)
        {
            //Validate
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id), "Id must be > 0.");
            }
            if (kaiju == null)
            {
                throw new ArgumentNullException(nameof(kaiju));
            }
            if (!kaiju.Validate())
            {
                throw new Exception("Kaiju is not valid.");
            }

            var index = GetIndex(id);

            if (index < 0)
            {
                throw new Exception("Kaiju does not exist.");
            }

            //Game names must be unique
            var existingIndex = GetIndex(kaiju.Name);

            if (existingIndex >= 0 && existingIndex != index)
            {
                throw new Exception("The kaiju's name must be unique.");
            }

            kaiju.Id = id;
            var existing = _items[index];

            Clone(existing, kaiju);

            return(kaiju);
        }
Beispiel #3
0
        public Character Add(Character character)
        {
            //Validate input
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }

            //character must be valid
            if (!character.Validate())
            {
                throw new Exception("Invalid");
            }


            //Character names must be unique
            var existing = GetIndex(character.Name);

            if (existing >= 0)
            {
                throw new Exception("Name is already being used.");
            }


            for (var index = 0; index < _items.Length; ++index)
            {
                if (_items[index] == null)
                {
                    character.Id  = ++_nextId;
                    _items[index] = Clone(character);
                    break;
                }
                ;
            }
            ;

            return(character);
        }
        public Character Add(Character kaiju)
        {
            //Validate input
            if (kaiju == null)
            {
                throw new ArgumentNullException(nameof(kaiju));
            }

            //Character must be valid
            if (!kaiju.Validate())
            {
                throw new Exception("Kaiju is invalid.");
            }

            //Character names must be unique
            var existing = GetIndex(kaiju.Name);

            if (existing >= 0)
            {
                throw new Exception("Kaiju must be unique.");
            }

            for (var index = 0; index < _items.Length; ++index)
            {
                if (_items[index] == null)
                {
                    kaiju.Id      = ++_nextId;
                    _items[index] = Clone(kaiju);
                    break;
                }
                ;
            }
            ;

            return(kaiju);
        }
Beispiel #5
0
        public Character Update(int id, Character character)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id), "Id must be >0.");
            }
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }
            if (!character.Validate())
            {
                throw new Exception("Character is invalid");
            }

            var index = GetIndex(id);

            if (index < 0)
            {
                throw new Exception("Character unavailable.");
            }

            var existingIndex = GetIndex(character.Name);

            if (existingIndex >= 0 && existingIndex != index)
            {
                throw new Exception("Character must be unique.");
            }

            character.Id = id;
            var existing = _items[index];

            Clone(existing, character);

            return(character);
        }
Beispiel #6
0
        public Character Add(Character character)
        {
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }

            if (!character.Validate())
            {
                throw new Exception("Character is invalid.");
            }

            var existing = GetIndex(character.Name);

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

            character.Id = ++_nextId;
            _items.Add(Clone(character));

            return(character);
        }