/// <summary> /// This method adds clinic to DbSet and save changes to database. /// </summary> /// <param name="clinic">Clinic to be added.</param> /// <returns>true if added, false if not.</returns> public bool CreateClinic(vwClinic clinic) { try { using (ClinicEntities context = new ClinicEntities()) { tblClinic newClinic = new tblClinic { Address = clinic.Address, DateOfConstruction = clinic.DateOfConstruction.Date, Name = clinic.Name, NumberOfAccessPointsForAmbulanceCars = clinic.NumberOfAccessPointsForAmbulanceCars, NumberOfAccessPointsForInvalids = clinic.NumberOfAccessPointsForInvalids, NumberOfFloors = clinic.NumberOfFloors, NumberOfRoomsPerFloor = clinic.NumberOfRoomsPerFloor, Owner = clinic.Owner, Terrace = clinic.Terrace, Yard = clinic.Yard }; context.tblClinics.Add(newClinic); context.SaveChanges(); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
/// <summary> /// This method edits data about clinic. /// </summary> /// <param name="clinic">Clinic to be edited.</param> /// <returns>True if edited, false if not.</returns> public bool EditClinic(vwClinic clinic) { try { using (ClinicEntities context = new ClinicEntities()) { tblClinic clinicToEdit = context.tblClinics.Where(x => x.ClinicId == clinic.ClinicId).FirstOrDefault(); clinicToEdit.Owner = clinic.Owner; clinicToEdit.NumberOfAccessPointsForAmbulanceCars = clinic.NumberOfAccessPointsForAmbulanceCars; clinicToEdit.NumberOfAccessPointsForInvalids = clinic.NumberOfAccessPointsForInvalids; context.SaveChanges(); return(true); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }