public IActionResult Post(string values) { var newEmployee = new EmployeeByState(); JsonConvert.PopulateObject(values, newEmployee); SampleData.DataGridEmployeesByState.Add(newEmployee); return(Ok()); }
private void PopulateModel(EmployeeByState values, EmployeeByState currEmployee) { if (!(values.StateID is null)) { currEmployee.StateID = values.StateID; } if (!(values.CityID is null)) { currEmployee.CityID = values.CityID; } }
public IActionResult Post(string values) { var newEmployee = new EmployeeByState(); JsonConvert.PopulateObject(values, newEmployee); if (!TryValidateModel(newEmployee)) { return(BadRequest("Failed to insert item")); } SampleData.DataGridEmployeesByState.Append(newEmployee); return(Ok()); }
public IActionResult Post(string values) { var newEmployee = new EmployeeByState(); JsonConvert.PopulateObject(values, newEmployee); if (!TryValidateModel(newEmployee)) { return(BadRequest(ModelState.GetFullErrorMessage())); } _data.EmployeesByState.Add(newEmployee); _data.SaveChanges(); return(Ok()); }
public HttpResponseMessage Post(FormDataCollection form) { var values = form.Get("values"); var newEmployee = new EmployeeByState(); JsonConvert.PopulateObject(values, newEmployee); Validate(newEmployee); if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState.GetFullErrorMessage())); } db.EmployeesByState.Add(newEmployee); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created)); }