Exemplo n.º 1
0
        public ActionResult <List <PublicCategoryModel> > PublicList()
        {
            try
            {
                List <PublicCategoryModel> model;
                const string cacheKey = "AnkaCMS.WebApi.Controllers.CategoryController.PublicList";
                if (_cacheService.Exists(cacheKey))
                {
                    model = _cacheService.Get <List <PublicCategoryModel> >(cacheKey);
                }
                else
                {
                    model = _serviceCategory.PublicList();
                    _cacheService.Add(cacheKey, model);
                    _cacheService.AddToKeyList(cacheKey);
                }
                return(Ok(model));
            }

            catch (NotFoundException)
            {
                ModelState.AddModelError("ErrorMessage", Messages.DangerRecordNotFound);
                return(BadRequest(ModelState));
            }

            catch (Exception exception)
            {
                ModelState.AddModelError("ErrorMessage", Messages.DangerRecordNotFound + " " + exception);
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 2
0
        public ActionResult <PublicPartModel> GetPublicPartContents(string partCode, string languageCode)
        {
            try
            {
                PublicPartModel model;
                var             cacheKey = "AnkaCMS.WebApi.Controllers.PartController.GetPublicPartContents-" + partCode + "-" + languageCode;
                if (_cacheService.Exists(cacheKey))
                {
                    model = _cacheService.Get <PublicPartModel>(cacheKey);
                }
                else
                {
                    model = _servicePart.GetPublicPartContents(partCode, languageCode);
                    _cacheService.Add(cacheKey, model);
                    _cacheService.AddToKeyList(cacheKey);
                }
                return(Ok(model));
            }

            catch (NotFoundException)
            {
                ModelState.AddModelError("ErrorMessage", Messages.DangerRecordNotFound);
                return(BadRequest(ModelState));
            }

            catch (Exception exception)
            {
                ModelState.AddModelError("ErrorMessage", Messages.DangerRecordNotFound + " " + exception);
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 3
0
        public ActionResult <PublicContentModel> PublicDetail(string code)
        {
            try
            {
                PublicContentModel model;
                var cacheKey = "AnkaCMS.WebApi.Controllers.ContentController.PublicDetail-" + code;
                if (_cacheService.Exists(cacheKey))
                {
                    model = _cacheService.Get <PublicContentModel>(cacheKey);
                }
                else
                {
                    model = _serviceContent.PublicDetail(code);
                    _cacheService.Add(cacheKey, model);
                    _cacheService.AddToKeyList(cacheKey);
                }
                return(Ok(model));
            }

            catch (NotFoundException)
            {
                ModelState.AddModelError("ErrorMessage", Messages.DangerRecordNotFound);
                return(BadRequest(ModelState));
            }

            catch (Exception exception)
            {
                ModelState.AddModelError("ErrorMessage", Messages.DangerRecordNotFound + " " + exception);
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 4
0
        public ActionResult <List <string> > GlobalizationKeys()
        {
            var model    = new List <string>();
            var cacheKey = "AnkaCMS.WebApi.Controllers.HomeController.GlobalizationKeys";

            if (_cacheService.Exists(cacheKey))
            {
                model = _cacheService.Get <List <string> >(cacheKey);
            }
            else
            {
                var resourceManagerDictionary = new ResourceManager(typeof(Dictionary));
                var resourceSetDictionary     = resourceManagerDictionary.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
                foreach (DictionaryEntry entry in resourceSetDictionary)
                {
                    model.Add("glb-dict-" + entry.Key);
                }
                var resourceManagerMessages = new ResourceManager(typeof(Messages));
                var resourceSetMessages     = resourceManagerMessages.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
                foreach (DictionaryEntry entry in resourceSetMessages)
                {
                    model.Add("glb-msg-" + entry.Key);
                }
                _cacheService.Add(cacheKey, model);
                _cacheService.AddToKeyList(cacheKey);
            }
            return(Ok(model));
        }