public TreatmentRoomBO ConvertTrmtRmRecToBO(TreatmentRoom_Record treatmentRoom)
        {
            TreatmentRoomBO treatmentRoomBO = new TreatmentRoomBO(treatmentRoom.Room_ID, Convert.ToString(treatmentRoom.Timings),
                                                                  treatmentRoom.DateOfJoin, treatmentRoom.IsBooked, treatmentRoom.Patient_ID);

            return(treatmentRoomBO);
        }
        public TreatmentRoom_Record ConvertBOToTreatmentRoomRec(TreatmentRoom_Record treatmentRoom, TreatmentRoomBO treatmentRoomBO)
        {
            if (treatmentRoomBO.room_ID != null)
            {
                treatmentRoom.Room_ID = treatmentRoomBO.room_ID;
            }

            if (!string.IsNullOrEmpty(treatmentRoomBO.timings))
            {
                treatmentRoom.Timings = TimeSpan.Parse(treatmentRoomBO.timings);
            }

            if (treatmentRoomBO.date != DateTime.MinValue)
            {
                treatmentRoom.DateOfJoin = treatmentRoomBO.date;
            }
            if (treatmentRoomBO.patient_ID != 0)
            {
                treatmentRoom.Patient_ID = treatmentRoomBO.patient_ID;
            }
            if (treatmentRoomBO.appointment_ID != 0)
            {
                treatmentRoom.Appointment_ID = treatmentRoomBO.appointment_ID;
            }
            treatmentRoom.IsBooked = treatmentRoomBO.isBooked;

            return(treatmentRoom);
        }
        public IEnumerable <TreatmentRoomBO> UpdateTreatmentRoomRecord(TreatmentRoom_Record treatmentRoomRec)
        {
            try
            {
                using (HospitalManagementSystemDataContext objHmsDataContext = new HospitalManagementSystemDataContext(Utils.ConnectionString))
                {
                    if (objHmsDataContext.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        objHmsDataContext.Connection.Open();
                    }

                    var treatmentRmRec = objHmsDataContext.TreatmentRoom_Records.Where(trmntRooms => (trmntRooms.Room_ID == treatmentRoomRec.Room_ID && trmntRooms.Appointment_ID == treatmentRoomRec.Appointment_ID)).FirstOrDefault();

                    treatmentRmRec.IsBooked = treatmentRoomRec.IsBooked;
                    objHmsDataContext.SubmitChanges();

                    return(GetAllTreatmentRooms());
                }
            }
            catch (Exception e)
            {
                IEnumerable <TreatmentRoomBO> room = null;
                return(room);
            }
        }
        public TreatmentRoomBO InsertTreatmentRoomRec(TreatmentRoomBO treatmentRoomBO)
        {
            try
            {
                using (HospitalManagementSystemDataContext objHmsDataContext = new HospitalManagementSystemDataContext(Utils.ConnectionString))
                {
                    if (objHmsDataContext.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        objHmsDataContext.Connection.Open();
                    }

                    TreatmentRoom_Record trmntRoom = new TreatmentRoom_Record();

                    objHmsDataContext.TreatmentRoom_Records.InsertOnSubmit(ConvertBOToTreatmentRoomRec(trmntRoom, treatmentRoomBO));
                    objHmsDataContext.SubmitChanges();

                    TreatmentRoom_Record newtrmntRoom = objHmsDataContext.TreatmentRoom_Records.SingleOrDefault(trmntroom => (trmntroom.Room_ID == treatmentRoomBO.room_ID && trmntroom.DateOfJoin == treatmentRoomBO.date));

                    return(ConvertTrmtRmRecToBO(newtrmntRoom));
                }
            }
            catch (Exception e)
            {
                TreatmentRoomBO treatmentRoom_BO = new TreatmentRoomBO();
                return(treatmentRoom_BO);
            }
        }
        //Method to update TreatmentRoom details, with string as return type and treatment business object as parameter
        public IEnumerable <TreatmentRoomBO> UpdateTreatmentRoom(TreatmentRoomBO treatmentRoomBO)
        {
            try
            {
                using (HospitalManagementSystemDataContext objHmsDataContext = new HospitalManagementSystemDataContext(Utils.ConnectionString))
                {
                    if (objHmsDataContext.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        objHmsDataContext.Connection.Open();
                    }

                    Treatment_Room treatmentRoom = objHmsDataContext.Treatment_Rooms.Where(trmntRooms => (trmntRooms.Room_ID == treatmentRoomBO.room_ID && trmntRooms.Appointment_ID == treatmentRoomBO.appointment_ID)).FirstOrDefault();

                    if (treatmentRoom != null)
                    {
                        Treatment_Room updateTrmntRoom = ConvertBOToTreatmentRoom(treatmentRoom, treatmentRoomBO);
                    }
                    objHmsDataContext.SubmitChanges();


                    TreatmentRoom_Record tr = new TreatmentRoom_Record();
                    tr.Appointment_ID = treatmentRoomBO.appointment_ID;
                    tr.DateOfJoin     = treatmentRoomBO.date;
                    tr.Patient_ID     = treatmentRoomBO.patient_ID;
                    tr.Room_ID        = treatmentRoomBO.room_ID;
                    //tr.Timings = treatmentRoomBO.timings;
                    if (treatmentRoomBO.isBooked != false)
                    {
                        tr.IsBooked = true;
                    }
                    else
                    {
                        tr.IsBooked = false;
                    }
                    //objHmsDataContext.TreatmentRoom_Records.InsertOnSubmit(tr);
                    objHmsDataContext.SubmitChanges();
                    UpdateTreatmentRoomRecord(tr);
                    return(GetAllTreatmentRooms());
                }
            }
            catch (Exception e)
            {
                IEnumerable <TreatmentRoomBO> room = null;
                return(room);
            }
        }