Exemple #1
0
        public Todo CreateTodo(string description)
        {
            bool idIsNotAvailable = true;
            int  nextAvailableId  = 0;
            int  newTodoArrIndex  = 0;
            Todo newTodo          = null;

            if (todoArr.Length == 0)
            {
                TodoSequencer.reset();
                nextAvailableId = TodoSequencer.nextTodoId();
                newTodo         = new Todo(nextAvailableId, description);
            }
            else
            {
                while (idIsNotAvailable)
                {
                    nextAvailableId = PersonSequencer.nextPersonId();

                    foreach (Todo todo in todoArr)
                    {
                        if (todo.todoId == nextAvailableId)
                        {
                            idIsNotAvailable = true;
                            break;
                        }
                        else
                        {
                            idIsNotAvailable = false;
                        }
                    }
                }

                newTodo = new Todo(nextAvailableId, description);
            }

            Array.Resize(ref todoArr, todoArr.Length + 1);
            newTodoArrIndex          = todoArr.Length - 1;
            todoArr[newTodoArrIndex] = newTodo;
            return(newTodo);
        }
Exemple #2
0
        public Person CreatePerson(string firstName, string lastName)
        {
            bool   idIsNotAvailable  = true;
            int    nextAvailableId   = 0;
            int    newPersonArrIndex = 0;
            Person newPerson         = null;

            if (persons.Length == 0)
            {
                PersonSequencer.reset();
                nextAvailableId = PersonSequencer.nextPersonId();
                newPerson       = new Person(nextAvailableId, firstName, lastName);
            }
            else
            {
                while (idIsNotAvailable)
                {
                    nextAvailableId = PersonSequencer.nextPersonId();

                    foreach (Person person in persons)
                    {
                        if (person.personId == nextAvailableId)
                        {
                            idIsNotAvailable = true;
                            break;
                        }
                        else
                        {
                            idIsNotAvailable = false;
                        }
                    }
                }

                newPerson = new Person(nextAvailableId, firstName, lastName);
            }

            Array.Resize(ref persons, persons.Length + 1);
            newPersonArrIndex          = persons.Length - 1;
            persons[newPersonArrIndex] = newPerson;
            return(newPerson);
        }