public void addnewdoctor() { string name = Request.Form["name"]; string address = Request.Form["address"]; string phones = Request.Form["phones"]; string products = Request.Form["products"]; bool active = bool.Parse(Request.Form["activate"]); if (name == "" || name == null || address == "" || address == null || products == "" || products == null ) { return; } string action = Request.Form["action"]; teethLabEntities db = new teethLabEntities(); doctor newdoc = null; if (action == "add") { newdoc = new teethLab.doctor(); } else if (action == "edit") { int id = int.Parse(Request.Form["doctorid"]); newdoc = db.doctors.Find(id); } newdoc.name = name; newdoc.address = address; newdoc.isActive = active; doctormodel dm = new doctormodel(); if (action == "add") { dm.addnewdoctor(newdoc); } if (action == "edit") { dm.deletealldoctorphones(newdoc.id); db.Entry(newdoc).State = System.Data.EntityState.Modified; db.SaveChanges(); } string[] allphones = phones.Split(','); for (int i = 0; i < allphones.Length - 1; i++) { doctorPhone dp = new doctorPhone(); dp.phone = allphones[i]; dp.doctorId = newdoc.id; if (!dm.addnewdoctorphone(dp)) { return; } } if (action == "add") { string[] allproducts = products.Split('^'); for (int i = 0; i < allproducts.Length - 1; i++) { caseDoctorPrice cp = new caseDoctorPrice(); cp.caseId = int.Parse(allproducts[i].Split(',')[0]); cp.doctorId = newdoc.id; cp.price = int.Parse(allproducts[i].Split(',')[1]); dm.addnewcaseprice(cp); } } else if (action == "edit") { string[] allproducts = products.Split('^'); db = new teethLabEntities(); for (int i = 0; i < allproducts.Length - 1; i++) { int id=int.Parse(allproducts[i].Split(',')[0]); caseDoctorPrice cp =db.caseDoctorPrices.Find(id); cp.price = int.Parse(allproducts[i].Split(',')[1]); db.Entry(cp).State = System.Data.EntityState.Modified; } db.SaveChanges(); } Response.Write("success"); }
public bool addnewdoctorphone(doctorPhone dp) { this.context.doctorPhones.Add(dp); this.context.SaveChanges(); this.context = new teethLabEntities(); return true; }