Exemplo n.º 1
0
        public Contact Update(string name, Contact contact)
        {
            //Validate
            if (name.Length <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(name), "Name is required");
            }
            if (contact == null)
            {
                throw new ArgumentNullException(nameof(contact));
            }

            ObjectValidator.Validate(contact);

            var existing = GetCore(name);

            if (existing == null)
            {
                throw new Exception("Contact does not exist.");
            }

            //Game names must be unique
            var sameName = FindByName(Contact.Name);

            if (sameName != null && sameName.Name != name)
            {
                throw new Exception("Contact must be unique.");
            }

            return(UpdateCore(name, contact));
        }
Exemplo n.º 2
0
        public void Edit(string name, Contact contact)
        {
            ObjectValidator.Validate(contact);
            var existingContact = FindByName(name);

            EditContact(existingContact, contact);
        }
Exemplo n.º 3
0
        public Contact Add(Contact contact)
        {
            if (contact == null)
            {
                throw new ArgumentNullException(nameof(contact));
            }

            ObjectValidator.Validate(contact);

            var existing = FindByName(contact.name);

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

            return(AddCore(contact));
        }
        public Contact Update(int id, Contact contact)
        {
            //Validate
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id), "Id must be > 0.");
            }
            if (contact == null)
            {
                throw new ArgumentNullException(nameof(contact));
            }


            ObjectValidator.Validate(contact);

            var sameName = FindByName(contact.Name);

            if (sameName != null && sameName.Id != id)
            {
                throw new Exception("Contact info must be unique.");
            }

            return(UpdateCore(id, contact));
        }