//Delete An Existing User public void DeleteUser(User user) { //MyDoctorDBContext DoctorDB = new MyDoctorDBContext(); //User deletedUser = DoctorDB.Users.Where(u => u.ID == user.ID).FirstOrDefault(); //DoctorDB.Users.Remove(deletedUser); //DoctorDB.SaveChanges(); try { MyDoctorDBContext DoctorDB = new MyDoctorDBContext(); User deletedUser = DoctorDB.Users.Where(u => u.ID == user.ID).FirstOrDefault(); DoctorDB.Users.Remove(deletedUser); DoctorDB.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
//Get All Appointments public List <Appointment> GetAppointments() { MyDoctorDBContext doctorDB = new MyDoctorDBContext(); List <Appointment> appointments = doctorDB.Appointments.ToList(); return(appointments); }
//Update An Existing User public void UpdateUser(User newUser) { //MyDoctorDBContext DoctorDB = new MyDoctorDBContext(); //DoctorDB.Entry(newUser).State = EntityState.Modified; //DoctorDB.SaveChanges(); try { MyDoctorDBContext DoctorDB = new MyDoctorDBContext(); DoctorDB.Entry(newUser).State = EntityState.Modified; DoctorDB.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
//set Patient public void SetPatient(Patient patient) { //MyDoctorDBContext doctorDB = new MyDoctorDBContext(); //doctorDB.Patients.Add(patient); //doctorDB.SaveChanges(); try { MyDoctorDBContext DoctorDBContext = new MyDoctorDBContext(); DoctorDBContext.Patients.Add(patient); DoctorDBContext.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
protected void Application_Start() { //Generate Database MyDoctorDB.MyDoctorDBContext db = new MyDoctorDB.MyDoctorDBContext(); db.Database.CreateIfNotExists(); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
//Search For a User public bool Search(User user) { MyDoctorDBContext DoctorDBContext = new MyDoctorDBContext(); if (DoctorDBContext.Users.Find(user.ID) == null) { return(true); } else { return(false); } }
//Delete An Existing Patient public void DeletePatient(int UserID) { //MyDoctorDBContext DoctorDB = new MyDoctorDBContext(); //Patient deletedPatient = DoctorDB.Patients.Where(p => p.PatientID == PatientID).FirstOrDefault(); //DoctorDB.Patients.Remove(deletedPatient); //DoctorDB.SaveChanges(); try { MyDoctorDBContext DoctorDB = new MyDoctorDBContext(); //get the patient Patient deletedPatient = DoctorDB.Patients.Where(p => p.PatientID == UserID).FirstOrDefault(); if (deletedPatient != null) { //delete the patient DoctorDB.Patients.Remove(deletedPatient); DoctorDB.SaveChanges(); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
//Get All Users public List <User> GetUsers() { MyDoctorDBContext DoctorDBContext = new MyDoctorDBContext(); return(DoctorDBContext.Users.ToList()); }