public IActionResult CreatePresc(PrescriptionsRequest presc) { var res = _dbService.CreatePrescription(presc); if (res == null) { return(BadRequest()); } return(Created("", res)); }
public PrescriptionsRequest CreatePrescription(PrescriptionsRequest request) { using (SqlConnection con = new SqlConnection(connectionStr)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; con.Open(); SqlTransaction transaction = con.BeginTransaction(); com.Transaction = transaction; com.CommandText = "Insert Into Prescription (Date, DueDate,IdPatient,IdDoctor)" + "Values(@Date,@DueDate,@IdPatient,@IdDoctor)"; com.Parameters.AddWithValue("Date", request.Date); com.Parameters.AddWithValue("DueDate", request.DueDate); com.Parameters.AddWithValue("IdPatient", request.IdPatient); com.Parameters.AddWithValue("IdDoctor", request.IdDoctor); com.ExecuteNonQuery(); transaction.Commit(); } return(request); }