public PatientsViewModel UpdatePatients(int _id_patient, PatientsEditViewModel _patient) { PatientsEntity upd_patient = new PatientsEntity(); upd_patient.Person.Name = _patient.Name; upd_patient.Person.Surname = _patient.Surname; upd_patient.Person.Address = _patient.Address; upd_patient.Person.Phone = _patient.Phone; upd_patient.IdDoctor = _patient.IdDoctor; new PatientsRepository().Update(_id_patient, upd_patient); return(this.ReadOnePatient(_id_patient)); }
public PatientsViewModel InsertPatients(PatientsEditViewModel _patient) { PatientsEntity new_patient = new PatientsEntity(); new_patient.Person.Name = _patient.Name; new_patient.Person.Surname = _patient.Surname; new_patient.Person.Address = _patient.Address; new_patient.Person.Phone = _patient.Phone; new_patient.IdDoctor = _patient.IdDoctor; new PatientsRepository().Insert(new_patient); return(this.ReadOnePatient(0)); }
//--------------------------------------------------------------------- public PatientsEntity Insert(PatientsEntity _patient) { string _procedure = "CRT_Patients"; var(_connection, _command, _transaction) = new ConnectionManager().CreateConnection(_procedure); _command.Parameters.Add(new SqlParameter("@_name", _patient.Person.Name)); _command.Parameters.Add(new SqlParameter("@_surname", _patient.Person.Surname)); _command.Parameters.Add(new SqlParameter("@_address", _patient.Person.Address)); _command.Parameters.Add(new SqlParameter("@_phone", _patient.Person.Phone)); _command.Parameters.Add(new SqlParameter("@_id_doctor", _patient.IdDoctor)); new ConnectionManager().ExecuteNonQuery(_connection, _command, _transaction); return(_patient); }
//--------------------------------------------------------------------- public PatientsEntity ReadOne(int _id) { PatientsEntity patient = new PatientsEntity(); const string _procedure = "READ_Patients_one"; var(_connection, _command, _transaction) = new ConnectionManager().CreateConnection(_procedure); _command.Parameters.Add(new SqlParameter("@_id", _id)); using (_connection) { try { using (SqlDataReader _dataReader = _command.ExecuteReader()) { while (_dataReader.Read()) { PatientsEntity _patient = new PatientsEntity { Id = _dataReader.GetInt32("id"), IdPerson = _dataReader.GetInt32("id_person"), IdDoctor = _dataReader.GetInt32("id_doctor"), Removed = _dataReader.GetBoolean("removed"), }; _patient.Doctor = new DoctorsRepository().ReadOne(_patient.IdDoctor); _patient.Person = new PersonsRepository().ReadOne(_patient.IdPerson); patient = _patient; } _dataReader.Close(); //_transaction.Commit(); } } catch (Exception ex) { Debug.Write(ex.Message); //_transaction.Rollback(); } } return(patient); }