public bool SaveAllEmotionGems(  GemsEmotionsObject gemsEmotions )
		{
			try
			{
				if (gemsEmotions == null || gemsEmotions.resultarray == null)
				{
					return false;
				}

				List<EventTitle> listEventTitle = new List<EventTitle>();
				List<EventDetail> listEventDetails = new List<EventDetail>();
				List<EventMedia> listEventMedia = new List<EventMedia>();
				List<EventDatetime> listEventDatetime = new List<EventDatetime>();
				List<GemsEmotionsDetailsDB> listEmotions = new List<GemsEmotionsDetailsDB>();
				foreach (var item in gemsEmotions.resultarray )
				{
					listEventTitle.Clear();
					listEventDetails.Clear();
					listEventMedia.Clear();
					listEventDatetime.Clear();
					listEmotions.Clear();

					// Emotion details
					GemsEmotionsDetailsDB emotion = new GemsEmotionsDetailsDB(){ code = gemsEmotions.code, emotion_id = item.emotion_id, emotion_title = item.emotion_title,
						mediapath = gemsEmotions.mediapath, mediathumbpath = gemsEmotions.mediathumbpath, noimageurl = gemsEmotions.noimageurl, user_id = item.user_id};
					listEmotions.Add(emotion);
					Connection.InsertAll(listEmotions);

					// event title
					foreach (var eventTitleItem in item.event_title)
					{
						eventTitleItem.emotion_id = item.emotion_id;
						listEventTitle.Add(eventTitleItem);

					}
					Connection.InsertAll(listEventTitle);

					// event details
					foreach (var eventDetailItem in item.event_details)
					{
						eventDetailItem.emotion_id = item.emotion_id;
						listEventDetails.Add(eventDetailItem);
					}
					Connection.InsertAll(listEventDetails);

					// event media
					foreach (var eventMediaItem in item.event_media)
					{
						eventMediaItem.emotion_id = item.emotion_id;
						listEventMedia.Add(eventMediaItem);
					}
					Connection.InsertAll(listEventMedia);


					// event date and time
					foreach (var eventDateItem in item.event_datetime)
					{
						eventDateItem.emotion_id = item.emotion_id;
						listEventDatetime.Add(eventDateItem);
					}
					Connection.InsertAll(listEventDatetime);

				}

				listEmotions.Clear();


				listEmotions = null;
				listEventDatetime = null;
				listEventDetails = null;
				listEventMedia = null;
				listEventTitle = null;
				return true;
			}
			catch (Exception ex)
			{

				return false;
			}

		}
		public GemsEmotionsObject GetGemsEmotionsObject()
		{
            try
            {
                GemsEmotionsObject masterObject = new GemsEmotionsObject();

                List<EventTitle> listEventTitle = new List<EventTitle>();
                List<EventDetail> listEventDetails = new List<EventDetail>();
                List<EventMedia> listEventMedia = new List<EventMedia>();
                List<EventDatetime> listEventDatetime = new List<EventDatetime>();
                List<GemsEmotionsDetailsDB> listEmotions = new List<GemsEmotionsDetailsDB>();
                List<GemsEmotionsDetails> gemsEmotions = new List<GemsEmotionsDetails>();

                listEventTitle = (from t in Connection.Table<EventTitle>() select t).ToList();
                listEventDetails = (from t in Connection.Table<EventDetail>() select t).ToList();
                listEventMedia = (from t in Connection.Table<EventMedia>() select t).ToList();
                listEventDatetime = (from t in Connection.Table<EventDatetime>() select t).ToList();
                listEmotions = (from t in Connection.Table<GemsEmotionsDetailsDB>() select t).ToList();

                masterObject.resultarray = new List<GemsEmotionsDetails>();
                foreach (var item in listEmotions)
                {
                    GemsEmotionsDetails resultArray = new GemsEmotionsDetails();

                    resultArray.user_id = item.user_id;
                    resultArray.emotion_id = item.emotion_id;
                    resultArray.emotion_title = item.emotion_title;

                    resultArray.event_title = new List<EventTitle>();
                    resultArray.event_details = new List<EventDetail>();
                    resultArray.event_datetime = new List<EventDatetime>();
                    resultArray.event_media = new List<EventMedia>();

                    // Title
                    foreach (var titeObject in listEventTitle)
                    {
                        if (titeObject.emotion_id == item.emotion_id)
                            resultArray.event_title.Add(titeObject);
                    }

                    // Details
                    foreach (var detailsObject in listEventDetails)
                    {
                        if (detailsObject.emotion_id == item.emotion_id)
                            resultArray.event_details.Add(detailsObject);
                    }

                    // date and time
                    foreach (var dateObject in listEventDatetime)
                    {
                        if (dateObject.emotion_id == item.emotion_id)
                            resultArray.event_datetime.Add(dateObject);
                    }

                    // media
                    foreach (var mediaObject in listEventMedia)
                    {
                        if (mediaObject.emotion_id == item.emotion_id)
                            resultArray.event_media.Add(mediaObject);
                    }

                    masterObject.resultarray.Add(resultArray);
                }


                masterObject.code = (listEmotions != null && listEmotions.Count > 0) ? listEmotions[0].code : "";
                masterObject.noimageurl = (listEmotions != null && listEmotions.Count > 0) ? listEmotions[0].noimageurl : "";
                masterObject.mediapath = (listEmotions != null && listEmotions.Count > 0) ? listEmotions[0].mediapath : "";
                masterObject.mediathumbpath = (listEmotions != null && listEmotions.Count > 0) ? listEmotions[0].mediathumbpath : "";
                return masterObject;
            }
            catch (Exception)
            {
                
                return null;
            }

		}