public int AddProfessional(Professional professional) { using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(AddProfessionalSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@ProfessionalTypeId", SqlDbType.Int).Value = professional.ProfessionalTypeId; cmd.Parameters.Add("@CompanyId", SqlDbType.Int).Value = professional.CompanyId; cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = professional.FirstName; cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = professional.LastName; cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = professional.Phone; cmd.Parameters.Add("@ProfessionalIdentificationNumber", SqlDbType.VarChar).Value = professional.ProfessionalIdentificationNumber; cmd.Parameters.Add("@CreatedBy", SqlDbType.Int).Value = professional.CreatedBy; //cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = DateTime.UtcNow; return Convert.ToInt16(cmd.ExecuteScalar()); } } }
public Professional GetProfessional(int professionalId) { Professional professional = null; using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(GetProfessionalByIdSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@ProfessionalId", SqlDbType.Int); cmd.Parameters["@ProfessionalId"].Value = professionalId; using (var myReader = cmd.ExecuteReader()) { try { if (myReader.HasRows) { myReader.Read(); professional = new Professional(myReader); if (myReader.NextResult()) { professional.ProfessionalSchedules = new List<ProfessionalSchedule>(); while (myReader.Read()) { professional.ProfessionalSchedules.Add(new ProfessionalSchedule(myReader)); } } if (myReader.NextResult()) { professional.ProfessionalAppointmentses = new List<Appointment>(); while (myReader.Read()) { professional.ProfessionalAppointmentses.Add(new Appointment(myReader)); } } } } catch (Exception ex) { // TODO Logg Error here } } } } return professional; }
public bool UpdateProfessional(Professional professional) { using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(UpdateProfessionalSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@ProfessionalId", SqlDbType.Int).Value = professional.ProfessionalId; cmd.Parameters.Add("@ProfessionalTypeId", SqlDbType.Int).Value = professional.ProfessionalTypeId; cmd.Parameters.Add("@CompanyId", SqlDbType.Int).Value = professional.CompanyId; cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = professional.FirstName; cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = professional.LastName; cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = professional.Phone; cmd.Parameters.Add("@ProfessionalIdentificationNumber", SqlDbType.VarChar).Value = professional.ProfessionalIdentificationNumber; cmd.Parameters.Add("@IsActive", SqlDbType.Bit).Value = professional.IsActive; cmd.Parameters.Add("@UpdatedBy", SqlDbType.Int).Value = professional.UpdatedBy; //cmd.Parameters.Add("@UpdatedDate", SqlDbType.DateTime).Value = DateTime.UtcNow; return cmd.ExecuteNonQuery() > 0; } } }