/// <summary>
        /// Updates the resource in the database
        /// </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 static void UpdateResourceString(int id, string key, string value, int languageID, string route, ResourceType type)
        {
            var repo = new ResourceRepository();

            var resource = repo.GetResourceByID(id);
            if (resource.Key != key)
            {
                RouteResourceProviderFactory.RemoveKey(route, key);
            }
            if (resource.LanguageID == languageID)
            {
                repo.UpdateResource(id, key, value, languageID, route, type);
            }
            else
            {
                var lanResource = repo.GetResource(key, route, languageID);
                if (lanResource != null)
                {
                    repo.UpdateResource(lanResource.ID, key, value, languageID, route, type);
                }
                else
                {
                    repo.AddResource(key, value, languageID, route, type);
                }
            }
        }
 /// <summary>
 /// Deletes the resource from the database
 /// </summary>
 /// <param name="id"></param>
 public static void DeleteResourceString(int id)
 {
     var repo = new ResourceRepository();
     var resource = repo.GetResourceByID(id);
     RouteResourceProviderFactory.RemoveKey(resource.Route, resource.Key);
     repo.DeleteResource(id);
 }
 public virtual JsonResult Get(int id)
 {
     var repo = new ResourceRepository();
     var resource = repo.GetResourceByID(id) ?? new Resource { Key = "Missing resource!!!", ResourceType = ResourceType.Text, Route = Resource.ROUTE_SEPARATOR, Value = "" };
     var model = new RouteResourceModel()
         {
             ResourceID = resource.ID,
             ResourceKey = resource.Key,
             ResourceRoute = resource.Route,
             ResourceType = (int) resource.ResourceType,
             Value = resource.Value
         };
     return Json(model, JsonRequestBehavior.AllowGet);
 }
 public virtual JsonResult Get(int id)
 {
     var repo = new ResourceRepository();
     var resource = repo.GetResourceByID(id) ??
                    new Resource { Key = "Missing resource!!!", ResourceType = ResourceType.Text, Route = Resource.ROUTE_SEPARATOR, Value = "" };
     return Json(resource, JsonRequestBehavior.AllowGet);
 }
        public virtual ActionResult Find(int id = 0, string route = Resource.ROUTE_SEPARATOR, int languageID = 0, string saveError = "")
        {
            var repo = new ResourceRepository();
            var pages = repo.GetRoutes();
            var languages = repo.GetLanguages();
            var factory = new RouteResourceProviderFactory();
            var provider = (RouteResourceProvider)factory.CreateGlobalResourceProvider(route);
            Resource resource = null;
            Language selectedLanguage;
            if (id > 0)
            {
                resource = repo.GetResourceByID(id);
                selectedLanguage = resource.Language;
            }
            else
            {
                selectedLanguage =
                    languages.Where(l => l.Value.Default == true || l.Value.ID == languageID).OrderBy(l => l.Value.Default).
                    First().Value;
            }

            var model = new RouteResourceModel
            {
                Routes = new SelectList(pages, Resource.ROUTE_SEPARATOR),
                Route = pages.FirstOrDefault(p => p.ToLowerInvariant() == provider.ResourceRoute) ?? provider.ResourceRoute,
                Languages =
                    new SelectList(languages.Values, "ID", "EnglishName",
                                   selectedLanguage.ID),
                LanguageID = selectedLanguage.ID
            };

            var resources = provider.ResourceReader;
            var names = (from DictionaryEntry key in resources
                         select repo.GetResource(key.Key.ToString(), route, selectedLanguage.ID) ??
                                (provider.FindMissingResource(key.Key.ToString(), selectedLanguage.Name) ??
                                new Resource
                                {
                                    Key = key.Key.ToString(),
                                    ResourceType = ResourceType.Text,
                                    Route = Resource.ROUTE_SEPARATOR,
                                    Value = "Missing resource!!!"
                                })).OrderBy(n => n.Key).ToList();

            model.Resources = names;
            if (resource != null)
            {
                model.ResourceID = resource.ID;
                model.ResourceKey = resource.Key;
                model.ResourceRoute = resource.Route;
                model.Value = resource.Value;
                model.ResourceType = (int)resource.ResourceType;
                model.SaveError = saveError;
            }
            else if (names.Count > 0)
            {
                model.ResourceID = names[0].ID;
                model.ResourceKey = names[0].Key;
                model.ResourceRoute = names[0].Route;
                model.Value = names[0].Value;
                model.ResourceType = (int)names[0].ResourceType;
            }

            return View("Index", model);
        }