public RestResult Update(TestPerson person)
        {
            try
            {
                TestPerson.UpdatePerson(person);

                return new RestResult
                {
                    Success = true,
                    Message = "Person has been updated"
                };
            }
            catch (Exception e)
            {
                return new RestResult
                {
                    Success = false,
                    Message = e.Message
                };
            }
        }
        public RestResult Create(TestPerson person)
        {
            try
            {
                TestPerson.AddPerson(person);

                return new RestResult
                {
                    Success = true,
                    Message = "New person is added",
                    Data = person
                };
            }
            catch (Exception e)
            {
                return new RestResult
                {
                    Success = false,
                    Message = e.Message
                };
            }
        }
Exemplo n.º 3
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.º 4
0
        public static void UpdatePerson(TestPerson person)
        {
            lock (lockObj)
            {                
                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;
            }
        }