public static tblInstitute AddInstitute(tblInstitute clinic) { try { using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4()) { if (clinic.instituteId == 0) { //add tblInstitute newInstitute = new tblInstitute(); newInstitute.instituteOwner = clinic.instituteOwner; newInstitute.name = clinic.name; newInstitute.numberOfAccessPointsForInvalids = clinic.numberOfAccessPointsForInvalids; newInstitute.numberOfAmbulanceAccessPoints = clinic.numberOfAmbulanceAccessPoints; newInstitute.numberOfFloors = clinic.numberOfFloors; newInstitute.numberOfRooms = clinic.numberOfRooms; newInstitute.terrace = clinic.terrace; newInstitute.yard = clinic.yard; newInstitute.address = clinic.address; newInstitute.constructionDate = clinic.constructionDate; context.tblInstitutes.Add(newInstitute); context.SaveChanges(); clinic.instituteId = newInstitute.instituteId; return(clinic); } else { tblInstitute instituteToEdit = (from x in context.tblInstitutes where x.instituteId == clinic.instituteId select x).FirstOrDefault(); instituteToEdit.address = clinic.address; instituteToEdit.constructionDate = clinic.constructionDate; instituteToEdit.instituteOwner = clinic.instituteOwner; instituteToEdit.name = clinic.name; instituteToEdit.numberOfAccessPointsForInvalids = clinic.numberOfAccessPointsForInvalids; instituteToEdit.numberOfAmbulanceAccessPoints = clinic.numberOfAmbulanceAccessPoints; instituteToEdit.numberOfFloors = clinic.numberOfFloors; instituteToEdit.numberOfRooms = clinic.numberOfRooms; instituteToEdit.terrace = clinic.terrace; instituteToEdit.yard = clinic.yard; instituteToEdit.instituteOwner = clinic.instituteOwner; context.SaveChanges(); return(clinic); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString()); return(null); } }
public static tblInstitute GetInstitute() { try { using (MedicalInstitutionEntities4 context = new MedicalInstitutionEntities4()) { tblInstitute result = (from x in context.tblInstitutes select x).FirstOrDefault(); return(result); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception " + ex.Message.ToString()); return(null); } }