Exemplo n.º 1
0
        public IHttpActionResult Post(int id, Models.Person personDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


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


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

            person.AAdresses.Add(_unitOfWork.Adress.Get(Int32.Parse(personDto.AdressId)));

            _unitOfWork.Persons.Add(person);
            _unitOfWork.Complete();

            return(StatusCode(HttpStatusCode.Accepted));
        }
Exemplo n.º 2
0
        public IHttpActionResult Put(int id, Models.Person personDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            Handin22.Person person = _unitOfWork.Persons.Get(id);

            if (person == null)
            {
                return(NotFound());
            }

            person.FirstName  = personDto.FirstName;
            person.MiddleName = personDto.MiddleName;
            person.LastName   = personDto.LastName;
            person.PersonId   = personDto.PersonId;
            person.Type       = personDto.Type;

            _unitOfWork.Complete();

            return(StatusCode(HttpStatusCode.NoContent));
        }