public vwRequest AddRequest(vwRequest request) { try { using (HospitalEntities5 context = new HospitalEntities5()) { if (request.RequestId == 0) { Request newRequest = new Request(); newRequest.Date = request.Date; newRequest.Reason = request.Reason; newRequest.Company = request.Company; newRequest.IsUrgent = request.IsUrgent; newRequest.IsApproved = request.IsApproved; newRequest.PatientId = request.PatientId; newRequest.DoctorId = request.DoctorId; context.Requests.Add(newRequest); context.SaveChanges(); request.RequestId = newRequest.RequestId; return(request); } else { Request editRequest = (from p in context.Requests where p.RequestId == request.RequestId select p).First(); editRequest.Date = request.Date; editRequest.Reason = request.Reason; editRequest.Company = request.Company; editRequest.IsUrgent = request.IsUrgent; editRequest.IsApproved = request.IsApproved; editRequest.PatientId = request.PatientId; editRequest.DoctorId = request.DoctorId; editRequest.RequestId = request.RequestId; context.SaveChanges(); return(request); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public Patient AddPatient(Patient patient) { bool uniqueUser = CheckUserName(patient.Username); try { using (HospitalEntities5 context = new HospitalEntities5()) { if (patient.PatientId == 0) { if (uniqueUser) { Patient newPatient = new Patient(); newPatient.Fullname = patient.Fullname; newPatient.PatientJMBG = patient.PatientJMBG; newPatient.NumInsurce = patient.NumInsurce; newPatient.Username = patient.Username; newPatient.PatientPassword = HashPasswordHelper.HashPassword(patient.PatientPassword); context.Patients.Add(newPatient); context.SaveChanges(); patient.PatientId = newPatient.PatientId; } return(patient); } else { Patient editPatient = (from p in context.Patients where p.PatientId == patient.PatientId select p).First(); editPatient.Fullname = patient.Fullname; editPatient.PatientJMBG = patient.PatientJMBG; editPatient.NumInsurce = patient.NumInsurce; editPatient.Username = patient.Username; editPatient.DoctorId = patient.DoctorId; editPatient.PatientId = patient.PatientId; context.SaveChanges(); return(patient); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public Doctor AddDoctor(Doctor doctor) { bool uniqueUser = CheckUserName(doctor.Username); try { using (HospitalEntities5 context = new HospitalEntities5()) { if (doctor.DoctorId == 0) { if (uniqueUser) { Doctor newDoctor = new Doctor(); newDoctor.FullName = doctor.FullName; newDoctor.DoctorJMBG = doctor.DoctorJMBG; newDoctor.BankAccount = doctor.BankAccount; newDoctor.Username = doctor.Username; newDoctor.DoctorPassword = HashPasswordHelper.HashPassword(doctor.DoctorPassword); context.Doctors.Add(newDoctor); context.SaveChanges(); doctor.DoctorId = newDoctor.DoctorId; } return(doctor); } else { Doctor editDoctor = (from p in context.Doctors where p.DoctorId == doctor.DoctorId select p).First(); editDoctor.FullName = doctor.FullName; editDoctor.DoctorJMBG = doctor.DoctorJMBG; editDoctor.BankAccount = doctor.BankAccount; editDoctor.Username = doctor.Username; editDoctor.DoctorPassword = doctor.DoctorPassword; editDoctor.DoctorId = doctor.DoctorId; context.SaveChanges(); return(doctor); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public void DeleteRequest(int requestId) { try { using (HospitalEntities5 context = new HospitalEntities5()) { Request resultToDelete = (from r in context.Requests where r.RequestId == requestId select r).First(); if (resultToDelete.IsApproved != null) { context.Requests.Remove(resultToDelete); context.SaveChanges(); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } }