public async Task <ActionResult <People> > PostPeople(People people) { people.PhoneNumber = PeopleDataValidation.ParseNumber(people.PhoneNumber); if (!PeopleDataValidation.IsPersonInfoValid(people)) // Best case scenario would be custom errors for all individual fields { return(Problem("Person data is invalid")); } if (PhoneNumberExists(people.PhoneNumber)) { return(Problem("This phone number already exists.")); } _context.People.Add(people); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPeople", new { id = people.UserId }, people)); }
public async Task <IActionResult> PutPeople(int id, People people) { if (id != people.UserId) { return(BadRequest()); } if (!PeopleDataValidation.IsPersonInfoValid(people)) { return(Problem("Person data is invalid")); } if (PhoneNumberExists(people.PhoneNumber)) { return(Problem("This phone number already exists.")); } _context.Entry(people).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PeopleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }