public async Task <HttpResponseMessage> PostRegisterAsync_fcp([FromBody] registered_fcp register_obj_fcp) { try { using (hcp_apiEntities6 entities = new hcp_apiEntities6()) { entities.registered_fcp.Add(register_obj_fcp); if (await GetValidateAsync(register_obj_fcp.national_id, Convert.ToDateTime(register_obj_fcp.dob), register_obj_fcp.surname) == "1") { entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, register_obj_fcp); message.Headers.Location = new Uri(Request.RequestUri + register_obj_fcp.national_id.ToString()); return(message); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Wrong user")); } } } catch (System.Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); // throw; } }
public IHttpActionResult PostRegister_ChurchAsync_fcp([FromBody] registered_fcp regi_obj_fcp) { try { using (hcp_apiEntities6 entities = new hcp_apiEntities6()) { using (SqlConnection sqlCon = new SqlConnection(obj.locate1)) { sqlCon.Open(); string query = "UPDATE registered set church = '" + regi_obj_fcp.church + "' where phone_number = '" + regi_obj_fcp.phone_number.Trim() + "'"; SqlCommand sqlCmd = new SqlCommand(query, sqlCon); sqlCmd.ExecuteNonQuery(); } var message = Request.CreateResponse(HttpStatusCode.Created, regi_obj_fcp); message.Headers.Location = new Uri(Request.RequestUri + regi_obj_fcp.church.ToString()); return(Ok("Registered")); } } catch (System.Exception ex) { return(Ok(ex.ToString())); // throw; } }