public int loginMedic(string iusername, string ipassword, string icnp) { datamedic medic = new datamedic(); using (MedicDBEntities3 db = new MedicDBEntities3()) { medic = db.datamedics.Where(x => x.cnp == icnp).FirstOrDefault(); if (medic == null) { return(-1); //medic==null => utilizatorul nu exista in baza de date; } else { if (medic.username == iusername) { if (medic.password == ipassword) { return(1); //medicul exista si parola e buna => access granted; } else { return(-2); //parola gresita } } } return(0);//medicul exista, dar parola si username sunt gresite } }//loginMedic
public int changeMedicData(string username, string password, string cnp, string email, string lastname, string firstname, string address, string dateofbirth, string specializare) { datamedic medic = new datamedic(); MedicDetail detail = new MedicDetail(); using (MedicDBEntities3 db = new MedicDBEntities3()) { try { medic = db.datamedics.Where(x => x.cnp == cnp).FirstOrDefault(); medic.password = password; //changing cnp is prohibited, because this is key information (for identifying) medic.email = email; medic.username = username; db.Entry(medic).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); detail = db.MedicDetails.Where(x => x.cnp == medic.cnp).FirstOrDefault(); detail.lastname = lastname; detail.firstname = firstname; detail.address = address; detail.dateofbirth = dateofbirth; detail.specializare = specializare; db.Entry(detail).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch { return(-1); } return(1); } //using } //changeMedicData()
public int registerMedic(string username, string password, string cnp, string email, string lastname, string firstname, string address, string dateofbirth, string specializare) { datamedic medic1 = new datamedic(); datamedic m1 = new datamedic(); //m1 se foloseste pentru cautare in baza de date //daca medicul nu exista in baza de date, atunci am fi avut un null pointer in medic //si intr-un null pointer nu se pot insera date (throws NullPointerException) MedicDetail detail = new MedicDetail(); detail.lastname = lastname; detail.firstname = firstname; detail.address = address; detail.dateofbirth = dateofbirth; detail.cnp = cnp; detail.specializare = specializare; using (MedicDBEntities3 db = new MedicDBEntities3()) { m1 = db.datamedics.Where(x => x.cnp == cnp).FirstOrDefault(); if (m1 != null) { return(0); //it means that the given CNP already exists, registration is not possible } //otherwise we create the medic object and insert it into the datamedic tabel medic1.username = username; medic1.password = password; medic1.cnp = cnp; medic1.email = email; try { db.datamedics.Add(medic1); db.SaveChanges(); } catch { return(-1); } try { db.MedicDetails.Add(detail); db.SaveChanges(); } catch { return(-2); } return(1); } //using } //registerMedic
public void getMedicData(ref string username, ref string password, string cnp, ref string email, ref string lastname, ref string firstname, ref string address, ref string dateofbirth, ref string specializare) { datamedic medic = new datamedic(); MedicDetail detail = new MedicDetail(); using (MedicDBEntities3 db = new MedicDBEntities3()) { medic = db.datamedics.Where(x => x.cnp == cnp).FirstOrDefault(); password = medic.password; cnp = medic.cnp; email = medic.email; //search in datamedics by cnp detail = db.MedicDetails.Where(x => x.cnp == medic.cnp).FirstOrDefault(); lastname = detail.lastname; firstname = detail.firstname; address = detail.address; dateofbirth = detail.dateofbirth; specializare = detail.specializare; //search in medicdetails based on cnp } }
public int deleteMedicAccount(string username, string cnp) { datamedic medic = new datamedic(); MedicDetail detail = new MedicDetail(); try { using (MedicDBEntities3 db = new MedicDBEntities3()) { medic = db.datamedics.Where(x => x.username == username).FirstOrDefault(); if (medic.cnp != cnp) { return(-1); } detail = db.MedicDetails.Where(x => x.cnp == medic.cnp).FirstOrDefault(); var entry = db.Entry(detail); if (entry.State == System.Data.Entity.EntityState.Detached) { db.MedicDetails.Attach(detail); } db.MedicDetails.Remove(detail); db.SaveChanges(); var entry1 = db.Entry(medic); if (entry1.State == System.Data.Entity.EntityState.Detached) { db.datamedics.Attach(medic); } db.datamedics.Remove(medic); db.SaveChanges(); } //using } //try catch { return(-2); } //catch return(1); } //function