public IActionResult AddPersonValidateAttribute(SimplePersonWithAttributes simplePersonWithAttributes) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok($"{simplePersonWithAttributes.Name} som är {simplePersonWithAttributes.Age} år lades till i databasen.")); }
public IActionResult AddPersonValidateAttribute(SimplePersonWithAttributes person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok($"Du har angett {person.FirstName} som är {person.Age} år")); }
public IActionResult ValidatePersonAttribute(SimplePersonWithAttributes person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok($"{person.Name} som är {person.Age} har lagts till i databasen")); }
public IActionResult ValidatePersonWithAttributes(SimplePersonWithAttributes person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok($"Person med namn: {person.Name} och ålder: {person.Age} har nu lagt till i databasen.")); }
public IActionResult AddPersonValidate(SimplePersonWithAttributes person) { if (ModelState.IsValid) { return(Ok($"{person.Name}, som är {person.Age} år, lades till i databasen")); } else { return(BadRequest(ModelState)); } }
public IActionResult AddPersonValidateAttribute(SimplePersonWithAttributes person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); //var messages = new List<string>(); //if (ModelState["FirstName"].ValidationState != ModelValidationState.Valid) //{ // string err = ModelState["FirstName"].Errors[0].ErrorMessage; // messages.Add(err); //} //if (ModelState["Age"].ValidationState != ModelValidationState.Valid) //{ // string err = ModelState["Age"].Errors[0].ErrorMessage; // messages.Add(err); //} //return BadRequest(string.Join(". ", messages)); } return(Ok($"Du har angett {person.FirstName} som är {person.Age} år")); }