/// <summary>
        /// retrieves the list of languages from the database, if this list is empty inserts the default language 'en' 
        /// </summary>
        /// <returns></returns>
        public Language GetDefaultLanguage()
        {
            using (var entities = new ResourceDB())
            {
                var language = (from l in entities.Languages
                                where l.Default == true
                                select l).FirstOrDefault();

                if (language == null)
                {
                    var en = new Language
                    {
                        Name = "en",
                        EnglishName = "English",
                        NativeName = "English",
                        Default = true
                    };
                    entities.Languages.Add(en);
                    entities.SaveChanges();

                    return en;
                }
                return language;
            }
        }
 public void DeleteResource(int id)
 {
     using (var entities = new ResourceDB())
     {
         var res = (from r in entities.Resources
                    where r.ID == id
                    select r).FirstOrDefault();
         entities.Resources.Remove(res);
         entities.SaveChanges();
     }
 }
        /// <summary>
        /// Adds a resource to the Localization Table
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="languageID"></param>
        /// <param name="route"></param>
        /// <param name="type"></param>
        public int AddResource(string key, string value, int languageID, string route, ResourceType type)
        {
            using (var entities = new ResourceDB())
            {
                var lan = (from l in entities.Languages where l.ID == languageID select l).FirstOrDefault();

                var res = new Resource
                              {
                                  Key = key,
                                  Route = route,
                                  Value = value,
                                  Language = lan,
                                  ResourceType = type,
                                  CreationDate = DateTime.Now
                              };

                entities.Resources.Add(res);
                return entities.SaveChanges();
            }
        }
        /// <summary>
        /// retrieves the dictionary of languages, with key culturecode, from the database, if this list is empty inserts the default language 'en' 
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, Language> GetLanguages()
        {
            using (var entities = new ResourceDB())
            {
                var list = (from l in entities.Languages
                            orderby l.Name ascending
                            select l).ToDictionary(l => l.Name);

                if (list.Count == 0)
                {
                    var en = new Language
                                 {
                                     Name = "en",
                                     EnglishName = "English",
                                     NativeName = "English",
                                     Default = true
                                 };
                    entities.Languages.Add(en);
                    entities.SaveChanges();

                    list = (from l in entities.Languages
                            orderby l.Name ascending
                            select l).ToDictionary(l => l.Name);
                }
                return list;
            }
        }
        /// <summary>
        /// Updates a resource in the Localization Table
        /// </summary>
        /// <param name="id"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="languageID"></param>
        /// <param name="route"></param>
        /// <param name="type"></param>
        public int UpdateResource(int id, string key, string value, int languageID, string route, ResourceType type)
        {
            using (var entities = new ResourceDB())
            {
                var res = (from r in entities.Resources.Include("Language")
                           where r.ID == id
                           select r).First();

                res.Value = value;
                res.Key = key;
                res.ResourceType = type;
                res.LanguageID = languageID;
                res.Route = route;

                try
                {
                    return entities.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.Write(e.Message);
                    throw;
                }
            }
        }