public Account CreateAccount(Patient patient) { AccountDAO accountDAO = new AccountDAO(); Account account = new Account(); account.password = CreateRandomPassword(5); account.userID = CreateRegistrationnumber(5); using (TransactionScope scope = new TransactionScope()) { patient = accountDAO.SavePatient(patient); accountDAO.SaveRegisteration(account, patient.patientid); scope.Complete(); } return account; }
public Account SaveRegisteration(Account account, string patientid) { string myConn = "Data Source=ANANTH-PC\\HEGDE;Initial Catalog=EMR;Integrated Security=True"; SqlConnection myConnection = new SqlConnection(myConn); SqlCommand command = myConnection.CreateCommand(); command.CommandText = "INSERT INTO Registration(patientRegistrationNumber,password,registrationDate,patientID)" + "VALUES(@patientRegistrationNumber,@password,@registrationDate,@patientID)"; command.Parameters.AddWithValue("@patientRegistrationNumber",account.userID); command.Parameters.AddWithValue("@password",account.password); command.Parameters.AddWithValue("@registrationDate", DateTime.Now); command.Parameters.AddWithValue("@patientID", patientid); command.Connection = myConnection; command.Connection.Open(); command.ExecuteNonQuery(); return account; }