public static bool ClearRecords()
 {
     bool returnVal = true;
     try
     {
         RootObject[] tmp = null;
         using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
         {
             do
             {
                 //Delete in chunks of 10 records each
                 tmp = context.CrisisItems.Take(10).ToArray();
                 if (tmp.Length > 0)
                 {
                     context.CrisisItems.DeleteAllOnSubmit(tmp);
                     context.SubmitChanges();
                 }
             } while (tmp.Length > 0);
         }
     }
     catch (Exception ex)
     {
         returnVal = false;
     }
     return returnVal;
 }
        public static void AddCrisis(RootObject earthquakeEvent)
        {
            using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
            {
                context.CrisisItems.InsertOnSubmit(earthquakeEvent);

                // save changes to the database
                context.SubmitChanges();
            }
        }
        public static void DeleteMessage(string id)
        {
            using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
            {
                IQueryable<RootObject> messageQuery = from c in context.CrisisItems where c._id == id select c;
                RootObject earthquakeItemToDelete = messageQuery.FirstOrDefault();

                context.CrisisItems.DeleteOnSubmit(earthquakeItemToDelete);

                // save changes to the database
                context.SubmitChanges();
            }
        }
        public static bool CrisisExists(string id)
        {
            RootObject earthquakeItemViewModel = null;
            using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
            {
                IQueryable<RootObject> query = from s in context.CrisisItems where s._id == id select s;
                earthquakeItemViewModel = query.FirstOrDefault();

                if (earthquakeItemViewModel != null)
                {
                    return true;
                }
            }
            return false;
        }
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            TiltEffect.SetIsTiltEnabled(this, true);
            using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
            {
                if (context.DatabaseExists())
                {
                    successfullyLoaded = true;
                }
                else
                {
                    // create database if it does not exist
                    context.CreateDatabase();

                    successfullyLoaded = true;
                }
            }
            // Set the data context of the listbox control to the sample data
            this.DataContext = App.CrisisViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
 /// <summary>
 /// Creates and adds a few ItemViewModel objects into the Items collection.
 /// </summary>
 public static List<RootObject> GetCrisis(int elemntsCountToRetrieve)
 {
     List<RootObject> lstCategories = new List<RootObject>();
     using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
     {
         IQueryable<RootObject> query = from s in context.CrisisItems select s;
         lstCategories = query.Take(elemntsCountToRetrieve).ToList();
     }
     return lstCategories;
 }
 /// <summary>
 /// Creates and adds a few ItemViewModel objects into the Items collection.
 /// </summary>
 public static IQueryable<RootObject> LoadCrisis(int numberOfEvents)
 {
     using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
     {
         IQueryable<RootObject> query = from s in context.CrisisItems select s;
         return query;
     }
 }
 /// <summary>
 /// Creates and adds a few ItemViewModel objects into the Items collection.
 /// </summary>
 public static RootObject GetSingleCrisis(int crisisId)
 {
     using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
     {
         IQueryable<RootObject> query = from s in context.CrisisItems where s.CrisisId == crisisId select s;
         return query.First();
     }
 }
 public static RootObject GetCrisis(string id)
 {
     RootObject earthquakeItemViewModel = null;
     using (SigimeraDataContext context = new SigimeraDataContext(Shared.CONNECTION_STRING))
     {
         IQueryable<RootObject> query = from s in context.CrisisItems where s._id == id select s;
         earthquakeItemViewModel = query.FirstOrDefault();
     }
     return earthquakeItemViewModel;
 }