Exemplo n.º 1
0
        public static int? AddPerson(TestPerson person)
        {
            lock (lockObj)
            {
                var persons = TestPerson.Storage;
                person.Id = TestPerson.NewId;
                persons.Add(person);
                TestPerson.Storage = persons;

                return person.Id;
            }
        }
Exemplo n.º 2
0
        public static void UpdatePerson(TestPerson person)
        {
            lock (lockObj)
            {
                if (person.Id % 2 != 0)
                {
                    throw new Exception("SIMULATED ERROR: ODD-numbered id");
                }

                var persons = TestPerson.Storage;
                TestPerson updatingPerson = null;

                foreach (TestPerson p in persons)
                {
                    if (p.Id == person.Id)
                    {
                        updatingPerson = p;
                        break;
                    }
                }

                if (updatingPerson == null)
                {
                    throw new Exception("TestPerson not found");
                }

                updatingPerson.Email = person.Email;
                updatingPerson.Last = person.Last;
                updatingPerson.First = person.First;

                TestPerson.Storage = persons;
            }
        }