Exemple #1
0
        public IActionResult Put(int id, PersonJsonViewModel person)
        {
            Contract.Requires(id > 0);
            Contract.Requires(person == null);
            if (id <= 0)
            {
                return(BadRequest("Id must be an integer greater than zero"));
            }
            if (person == null)
            {
                return(BadRequest("Invalid person"));
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState.GetJsonValidationErrors()));
            }

            var updatedPerson = _personRepository.UpdatePerson(id, person.ToDomainObject());

            if (updatedPerson != null)
            {
                return(Ok(person));
            }

            return(NotFound(id));
        }
Exemple #2
0
        public IActionResult Post([FromBody] PersonJsonViewModel person)
        {
            Contract.Requires(person != null);
            if (person == null)
            {
                return(BadRequest("Invalid person"));
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState.GetJsonValidationErrors()));
            }

            var id = _personRepository.AddPerson(person.ToDomainObject());

            return(CreatedAtAction("Get", new { id }, id));
        }