public IActionResult Post(string values) { var newEmployee = new EmployeeValidation(); JsonConvert.PopulateObject(values, newEmployee); if (!TryValidateModel(newEmployee)) { return(BadRequest(ModelState.GetFullErrorMessage())); } _data.Employees.Add(newEmployee); _data.SaveChanges(); return(Ok()); }
public HttpResponseMessage Post(FormDataCollection form) { var values = form.Get("values"); var newEmployee = new EmployeeValidation(); JsonConvert.PopulateObject(values, newEmployee); Validate(newEmployee); if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState.GetFullErrorMessage())); } db.Employees.Add(newEmployee); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created)); }