Beispiel #1
0
        public ContentSnippetModel GetSnippet(SnippetType snippetType)
        {
            var cacheKey = SnippetCachePrefix + snippetType.ToString();

            if (_memoryCache.TryGetValue(cacheKey, out ContentSnippetModel snippet))
            {
                return(new ContentSnippetModel()
                {
                    Content = snippet.Content,
                    SnippetType = snippet.SnippetType
                });
            }
            else
            {
                var dbModel = _contentSnippetRepository.Get(snippetType);

                if (dbModel == null)
                {
                    return(new ContentSnippetModel());
                }

                var model = new ContentSnippetModel()
                {
                    Content     = dbModel.Content,
                    SnippetType = dbModel.SnippetType
                };

                _memoryCache.Set(cacheKey, model);

                return(model);
            }
        }
Beispiel #2
0
        public IActionResult Edit(ContentSnippetEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var dbModel = _contentSnippetRepository.Get(model.ContentSnippetId);

            dbModel.Content     = model.Content;
            dbModel.SnippetType = model.SnippetType;

            _contentSnippetRepository.Update(dbModel);

            _contentSnippetHelper.ClearSnippetCache(model.SnippetType);

            return(RedirectToAction("index"));
        }