public IActionResult Create()
        {
            var model = new ContentSnippetEditModel()
            {
            };

            return(this.View());
        }
        public IActionResult Edit(int contentSnippetId)
        {
            var dbModel = this.contentSnippetRepository.Get(contentSnippetId);

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

            return(this.View(model));
        }
예제 #3
0
        public IActionResult Create(ContentSnippetEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _contentSnippetRepository.Create(new ContentSnippet()
            {
                Content          = model.Content,
                ContentSnippetId = model.ContentSnippetId,
                SnippetType      = model.SnippetType
            });

            return(RedirectToAction("index"));
        }
        public IActionResult Edit(ContentSnippetEditModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var dbModel = this.contentSnippetRepository.Get(model.ContentSnippetId);

            dbModel.Content     = model.Content.Trim();
            dbModel.SnippetType = model.SnippetType;

            this.contentSnippetRepository.Update(dbModel);

            this.contentSnippetHelper.ClearSnippetCache(model.SnippetType);

            return(this.RedirectToAction("index"));
        }
        public IActionResult Create(ContentSnippetEditModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var dbModel = this.contentSnippetRepository.Get(model.ContentSnippetId);

            if (dbModel != null)
            {
                throw new System.Exception("type already exists");
            }

            this.contentSnippetRepository.Create(new ContentSnippet()
            {
                Content          = model.Content.Trim(),
                ContentSnippetId = model.ContentSnippetId,
                SnippetType      = model.SnippetType
            });

            return(this.RedirectToAction("index"));
        }