private void incarcareTextBoxuriCuUser() { UserMedic user = adminService.GetUserMedicByMedic(listaMedici[bindingSourceMedici.Position]); textBoxUsernameMedic.Text = user.Username; textBoxPasswordMedic.Text = user.Parola; }
public void AddCerere(Cerere cerere, String username, List <Pacient> pacienti) { using (UnitOfWork unitOfWork = new UnitOfWork()) { UserMedic userMedic = unitOfWork.UserMedicRepo.GetBy(um => um.Username.Equals(username)); Medic medic = unitOfWork.MedicRepo.GetBy(m => m.UserMedic.Equals(userMedic)); cerere.Medic = medic; unitOfWork.CerereRepo.Save(cerere); unitOfWork.Save(); Cerere cerereSalvata = unitOfWork.CerereRepo.GetBy(c => c.RH.Equals(cerere.RH) && c.Grupa.Equals(cerere.Grupa) && c.Medic.Equals(cerere.Medic) && c.Data.Equals(cerere.Data)); medic.Cereri.Add(cerereSalvata); List <Pacient> pacientiFromDb = new List <Pacient>(); pacienti.ForEach(p => pacientiFromDb.Add(unitOfWork.PacientRepo.GetBy(pdb => pdb.Id.Equals(p.Id)))); pacientiFromDb.ForEach(p => { CererePacient cp = new CererePacient() { IdCerere = cerereSalvata.Id, Pacient = p, Cerere = cerereSalvata, IdPacient = p.Id }; p.CereriPacienti.Add(cp); cerereSalvata.CererePacienti.Add(cp); }); unitOfWork.Save(); } }
public static void InitializeMedic(CTContext context) { if (context.Medic.Any()) { return; } Medic m1 = new Medic("2770111123456", "Coste", "Claudia", "*****@*****.**", "0742345678"); Medic m2 = new Medic("2661223654321", "Dordai", "Raul", "*****@*****.**", "0785123456"); var medici = new Medic[] { m1, m2 }; foreach (Medic m in medici) { context.Medic.Add(m); } UserMedic um1 = new UserMedic("ioana", "0d20326e6155cae6bb2b510bfc2cc01e"); //parola=medic UserMedic um2 = new UserMedic("raul", "0d20326e6155cae6bb2b510bfc2cc01e"); //parola = medic var usersM = new UserMedic[] { um1, um2 }; foreach (UserMedic um in usersM) { context.UserMedic.Add(um); } context.SaveChanges(); context.UserMedic.Find(1).Medic = context.Medic.Find(1); context.Medic.Find(1).UserMedic = context.UserMedic.Find(1); context.UserMedic.Find(2).Medic = context.Medic.Find(2); context.Medic.Find(2).UserMedic = context.UserMedic.Find(2); context.SaveChanges(); }
public static void Initialize(CTContext context) { context.Database.EnsureCreated(); if (context.UserMedic.Any()) { return; } Medic m1 = new Medic("2770111123456", "Coste", "Claudia", "*****@*****.**", "0742345678"); Medic m2 = new Medic("2661223654321", "Dordai", "Raul", "*****@*****.**", "0785123456"); UserMedic um1 = new UserMedic("ioana", "12345"); UserMedic um2 = new UserMedic("raul", "12345"); var usersM = new UserMedic[] { um1, um2 }; var medici = new Medic[] { m1, m2 }; foreach (UserMedic um in usersM) { context.UserMedic.Add(um); } foreach (Medic m in medici) { context.Medic.Add(m); } context.SaveChanges(); context.UserMedic.Find(1).Medic = context.Medic.Find(1); context.Medic.Find(1).UserMedic = context.UserMedic.Find(1); context.UserMedic.Find(2).Medic = context.Medic.Find(2); context.Medic.Find(2).UserMedic = context.UserMedic.Find(2); context.SaveChanges(); }
public UserMedic GetUserMedicByUsername(String username) { using (UnitOfWork unitOfWork = new UnitOfWork()) { UserMedic user = unitOfWork.UserMedicRepo.GetBy(m => m.Username.Equals(username)); return(user); } }
private void buttonDeleteMedic_Click(object sender, EventArgs e) { //Delete a medic with Usermedic Medic medic = listaMedici[bindingSourceMedici.Position]; UserMedic userMedic = adminService.GetUserMedicByMedic(medic); adminService.DeleteMedicAndUser(medic, userMedic); loadDataGrdViewMedici(); }
public UserMedic GetUserMedicByMedic(Medic medic) { UserMedic user = null; using (UnitOfWork unitOfWork = new UnitOfWork()) { user = unitOfWork.UserMedicRepo.GetBy((u) => u.Medic == medic); unitOfWork.Save(); } return(user); }
public List <Cerere> GetCereriByMedic(string username) { using (UnitOfWork unitOfWork = new UnitOfWork()) { List <Cerere> cereri = new List <Cerere>(); UserMedic userMedic = unitOfWork.UserMedicRepo.GetBy(um => um.Username.Equals(username)); Medic medic = unitOfWork.MedicRepo.GetBy(m => m.UserMedic.Equals(userMedic)); //Console.WriteLine("bd:" + unitOfWork.CerereRepo.GetAll().Where(c => c.Medic.Equals(medic)).Count()); unitOfWork.CerereRepo.GetAll().Where(c => c.Medic.UserMedic.Username.Equals(username)).ToList().ForEach(c => { cereri.Add(c); }); return(cereri); } }
public UserMedic GetUserMedicByUsername(String username) { using (UnitOfWork unitOfWork = new UnitOfWork()) { UserMedic user = unitOfWork.UserMedicRepo.GetBy(m => m.Username.Equals(username)); if (user == null) { throw new ValidationException("nu exista username"); } return(user); } }
public void TestAdminAddMedic() { Medic medic = new Medic("12345678901", "NumeGresit", "PrenumeGresit", "EmailGresit", "0707070707"); UserMedic userMedic = new UserMedic("UserGresit", "ParolaGresita"); List <Spital> list = new List <Spital>(); int count = adminService.GetAllMedici().Count; adminService.AddMedic(medic, userMedic, list); Assert.AreEqual(count + 1, adminService.GetAllMedici().Count); adminService.DeleteMedicAndUser(medic, userMedic); Assert.AreEqual(count, adminService.GetAllMedici().Count); }
public int Login(String username, String password) {// returneaza -1 daca datele sunt gresite, id-ul medicului altfel UserMedic um = GetUserMedicByUsername(username); if (um == null) { return(-1); } if (um.Parola.Equals(Util.EncryptPassword(password))) { return(um.Id); } else { return(-1); } }
public bool Login(String username, String password) { UserMedic um = GetUserMedicByUsername(username); if (um == null) { return(false); } if (um.Parola.Equals(password)) { return(true); } else { return(false); } }
public void DeleteMedicAndUser(Medic medic, UserMedic user) { using (UnitOfWork unitOfWork = new UnitOfWork()) { Medic medicDB = unitOfWork.MedicRepo.GetBy(m => m.Id.Equals(medic.Id)); List <SpitalMedic> spitalMedics = unitOfWork.SpitalMedicRepo.GetAll().ToList(); spitalMedics.ForEach(sm => { if (sm.IdMedic.Equals(medicDB.Id)) { unitOfWork.SpitalMedicRepo.Delete(sm); } }); unitOfWork.MedicRepo.Delete(medicDB); unitOfWork.UserMedicRepo.Delete(user); unitOfWork.Save(); } }
public void AddMedic(Medic medic, UserMedic userMedic, List <Spital> spitals) { using (UnitOfWork unitOfWork = new UnitOfWork()) { userMedic.Parola = Util.EncryptPassword(userMedic.Parola); medic.UserMedic = userMedic; userMedic.Medic = medic; unitOfWork.UserMedicRepo.Save(userMedic); unitOfWork.MedicRepo.Save(medic); unitOfWork.Save(); Medic medicSalvat = unitOfWork.MedicRepo.GetBy(m => m.Cnp.Equals(medic.Cnp)); List <Spital> spitaleFromDb = new List <Spital>(); //spitaleFromDb.Add(unitOfWork.SpitalRepo.GetBy(s => s.Id.Equals(5))); spitals.ForEach(s => spitaleFromDb.Add(unitOfWork.SpitalRepo.GetBy(sdb => sdb.Id.Equals(s.Id)))); spitaleFromDb.ForEach(s => { SpitalMedic sm = new SpitalMedic() { IdMedic = medicSalvat.Id, IdSpital = s.Id, Medic = medicSalvat, Spital = s }; if (s.SpitalMedici == null) { s.SpitalMedici = new List <SpitalMedic>(); } s.SpitalMedici.Add(sm); if (medicSalvat.SpitaleMedic == null) { medicSalvat.SpitaleMedic = new List <SpitalMedic>(); } medicSalvat.SpitaleMedic.Add(sm); }); unitOfWork.Save(); } }
private void buttonAddMedic_Click(object sender, EventArgs e) { String cnp = textBoxCNPMedic.Text; String nume = textBoxNumeMedic.Text; String prenume = textBoxPrenumeMedic.Text; String telefon = textBoxTelefonMedic.Text; String email = textBoxEmailMedic.Text; String parola = textBoxPasswordMedic.Text; String username = textBoxUsernameMedic.Text; bool valid = validareCampuriMedic(cnp, nume, prenume, telefon, email, parola, username); if (!valid) { MessageBox.Show(this, "Campuri necompletate!", "Error!"); return; } Medic medic = new Medic(cnp, nume, prenume, email, telefon); UserMedic user = new UserMedic(username, parola); adminService.AddMedic(medic, user, GetSpitaleSelectate()); loadDataGrdViewMedici(); }