Beispiel #1
0
 public void InitGroups(ArticleDto article)
 {
     if (IocHelper.CurrentToggle == "xml")
     {
         var @group = GetGroup(article.Group);
         if (@group.Groups == null)
         {
             @group.Groups = new List<string>();
         }
         @group.Groups.Add(article.ArticleName);
         var helper = new IocHelper();
         helper.GroupService.UpdateGroup(@group);
     }
 }
 public ActionResult UpdateArticle(ArticleDto dto)
 {
     try
     {
         var article = dto.Convert();
         GroupHelper.Instance.InitGroups(dto);
         var helper = new IocHelper();
         helper.ArticleService.UpdateArticle(article);
         return Json(true);
     }
     catch (Exception e)
     {
         throw new HttpException(500, e.Message);
     }
 }
        public ActionResult GetArticleById(string articleID)
        {
            try
            {
                if (!FeatureListModel.Instance.CheckFeatureForEnabled(Features.GetAtricleById))
                    throw new Exception("Просмотр статей отключен");
                var maybeId = articleID.MaybeAs<string>().Bind(c => c.Split('-').Skip(1).Take(1).Last()).GetOrDefault("");
                int currentId;
                int.TryParse(maybeId, out currentId);
                var helper = new IocHelper();
                CommonHelper.Instance.CurrentArticle = helper.ArticleService.GetArticleById(currentId);
                var dto = new ArticleDto(CommonHelper.Instance.CurrentArticle);
                var groups = helper.GroupService.GetAllGroups(c => c.GroupName, 0, 999).ToList();
                if (IocHelper.CurrentToggle == "xml")
                {
                    dto.Group = groups.FirstOrDefault(c => c.Groups.FirstOrDefault(x => x == dto.ArticleName) != null)
                        .MaybeAs<ArticleGroup>()
                        .Bind(c => c.GroupName)
                        .GetOrDefault(null);
                }

                return Json(dto, JsonRequestBehavior.AllowGet);
            }
            catch (Exception e)
            {
                throw new HttpException(500, e.Message);
            }
        }
        public ActionResult SaveArticleByRef(string link)
        {
            try
            {
                var dto = new ArticleDto();
                var client = new WebClient();
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

                var streamData = client.OpenRead(link);
                var reader = new StreamReader(streamData);
                string html = reader.ReadToEnd();
                var res = _regexForTitle.Match(html);
                dto.ArticleName = res.Groups[1].Value;
                var tags = CommonHelper.Instance.StripTagsCharArray(html);
                var content = tags.Replace(dto.ArticleName, string.Empty);
                dto.Content = content;
                //var article = dto.Convert();
                //IocHelper.ArticleService.SaveArticle(article);
                return Json(dto);
            }
            catch (Exception e)
            {
                throw new HttpException(500, e.Message);
            }
        }