Ejemplo n.º 1
0
        public ActionResult CreatePage(PageContentViewModel pageContent)
        {
            try {
                if (ModelState.IsValid)
                {
                    var pageSeoModel = new PageSeoModel {
                        Title        = pageContent.Title,
                        KeyWords     = pageContent.KeyWords,
                        Descriptions = pageContent.Descriptions
                    };

                    var htmlContentModel = new HtmlContentModel {
                        HtmlContent = pageContent.HtmlContent,
                        UniqueCode  = System.Guid.NewGuid().ToString()
                    };

                    var pageContentModel = new PageContentModel {
                        Header           = pageContent.Header,
                        Url              = pageContent.Url,
                        IsPublished      = false,
                        PageSeoModel     = pageSeoModel,
                        HtmlContentModel = htmlContentModel
                    };
                    _pageContentEssenceManager.CreatePage(pageContentModel);

                    return(RedirectToAction("ManagementPage"));
                }
            }
            catch (ValidationException ex) {
                ModelState.AddModelError(ex.Property, ex.Message);
            }

            return(View(pageContent));
        }
Ejemplo n.º 2
0
 public TopicsControllerDocumentsTest()
 {
     _tester          = new ControllerTester <TopicsController>();
     HtmlContentModel = new HtmlContentModel
     {
         HtmlContent = "Hello"
     };
 }
        public HtmlContentModel Get([FromBody] HtmlContentModel model)
        {
            HtmlContent content = string.IsNullOrEmpty(model.Id) ? new HtmlContent() : HtmlContentQueries.GetHtmlContent(this.DbContext, model.Id);

            Mapper.Initialize(cfg => { cfg.CreateMap <HtmlContentModel, HtmlContent>(); });
            Mapper.Map(model, content);
            content.Id = string.IsNullOrEmpty(content.Id) ? Guid.NewGuid().ToString() : content.Id;
            HtmlContentQueries.SaveHtmlContent(content, this.DbContext);
            Mapper.Initialize(cfg => { cfg.CreateMap <HtmlContent, HtmlContentModel>(); });
            return(Mapper.Map <HtmlContentModel>(content));
        }
        public void SaveHtmlContent(HtmlContentModel htmlContentModel)
        {
            if (htmlContentModel == null) {
                throw new ValidationException("Пустые данные HTML", "");
            }

            var htmlContentEssence = new HtmlContentEssence {
                HtmlContent = htmlContentModel.HtmlContent,
                UniqueCode = htmlContentModel.UniqueCode
            };

            using (EntitiesContext context = new EntitiesContext()) {
                context.HtmlContentEssences.Add(htmlContentEssence);

                context.SaveChanges();
            }
        }
        public HtmlContentModel Get(int id)
        {
            using (EntitiesContext context = new EntitiesContext()) {
                var item = context.HtmlContentEssences.Find(id);

                if (item == null) {
                    throw new ValidationException("Html-content не найден", "");
                }

                var htmlContentModel = new HtmlContentModel {
                    Id = item.Id,
                    HtmlContent = item.HtmlContent,
                    UniqueCode = item.UniqueCode
                };

                return htmlContentModel;
            }
        }
        public void EditHtmlContent(HtmlContentModel htmlContentModel)
        {
            if (htmlContentModel == null) {
                throw new ValidationException("SEO не найдено", "");
            }

            var htmlContentEssence = new HtmlContentEssence {
                Id = htmlContentModel.Id,
                HtmlContent = htmlContentModel.HtmlContent,
                UniqueCode = htmlContentModel.UniqueCode
            };

            using (EntitiesContext context = new EntitiesContext()) {
                context.Entry(htmlContentEssence).State = EntityState.Modified;

                context.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        public IActionResult PostDocument([FromRoute] int topicId, [FromBody] HtmlContentModel htmlContent)
        {
            if (!_topicPermissions.IsAssociatedTo(User.Identity.GetUserId(), topicId))
            {
                return(Forbidden());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = _documentManager.UpdateDocument(topicId, User.Identity.GetUserId(), htmlContent.HtmlContent);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Ejemplo n.º 8
0
        public ActionResult EditPage(PageContentViewModel pageContent)
        {
            try {
                if (ModelState.IsValid)
                {
                    var htmlContentModel = new HtmlContentModel {
                        HtmlContent = pageContent.HtmlContent,
                        UniqueCode  = System.Guid.NewGuid().ToString()
                    };
                    _htmlContentEssenceManager.SaveHtmlContent(htmlContentModel);
                    int htmlContentId = _htmlContentEssenceManager.GetId(htmlContentModel.UniqueCode);

                    var pageSeoModel = new PageSeoModel {
                        Id           = pageContent.SeoID.Value,
                        Title        = pageContent.Title,
                        KeyWords     = pageContent.KeyWords,
                        Descriptions = pageContent.Descriptions
                    };
                    _pageSeoEssenceManager.EditSeo(pageSeoModel);

                    var pageContentModel = new PageContentModel {
                        Id            = pageContent.Id,
                        Header        = pageContent.Header,
                        Url           = pageContent.Url,
                        IsPublished   = false,
                        SeoID         = pageSeoModel.Id,
                        HtmlContentID = htmlContentId
                    };
                    _pageContentEssenceManager.EditPage(pageContentModel);

                    return(RedirectToAction("ManagementPage"));
                }
            }
            catch (ValidationException ex) {
                ModelState.AddModelError(ex.Property, ex.Message);
            }

            return(View(pageContent));
        }