예제 #1
0
파일: Program.cs 프로젝트: Katborg/DAB
        private async Task GetStarted()
        {
            City oldmantown = new City()
            {
                Name = "Old Man Town", ZipCode = 9090
            };
            City Youngmantown = new City()
            {
                Name = "yuong Man Town", ZipCode = 1090
            };

            Person per = new Person("per", "Persen", "old man")
            {
                PersonId = "9", PAdress =
                    new Adress()
                {
                    City = oldmantown, Number = "5", Street = "theStreet"
                }
            };
            Person Jasper = new Person("Jasper", "Man", "middel man")
            {
                PersonId = "7",
                PAdress  =
                    new Adress()
                {
                    City = oldmantown, Number = "5", Street = "theStreet"
                }
            };
            Person chris = new Person("Chris", "toffer", "young man")
            {
                PersonId = "1", PAdress = new Adress()
                {
                    City = Youngmantown, Number = "105", Street = "anotherStreet"
                }
            };

            DocumentClient client = new DocumentClient(new Uri(EndpointUri), PrimaryKey);

            PersonRepositry personRepository = new PersonRepositry(client, "PersonDB_oa", "PersonCol");

            personRepository.Add(chris);
            personRepository.Add(per);
            personRepository.Add(Jasper);

            Person person1 = personRepository.Get(1);

            Console.WriteLine(person1);
        }
예제 #2
0
        public IHttpActionResult Post(int id, REST_API.Models.Person personDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            if (_personRepository.Get(id) != null)
            {
                return(StatusCode(HttpStatusCode.NotAcceptable));
            }


            Person person = new Person(personDto.FirstName, personDto.LastName, personDto.Type)
            {
                MiddleName = personDto.MiddleName,
                LastName   = personDto.LastName,
                PersonId   = personDto.PersonId,
                Type       = personDto.Type
            };

            _personRepository.Add(person);
            return(StatusCode(HttpStatusCode.Accepted));
        }