Beispiel #1
0
        public IActionResult Index(string search)
        {
            MediumpageModels    mediumpageModel = new MediumpageModels();
            List <MediumModels> mediumModel     = new List <MediumModels>();

            ViewBag.search = search;
            try
            {
                mediumpageModel.Mediumpage = _mediumpageDal.GetAll().Where(i => i.isApproved == true).First();
            }
            catch (Exception)
            {
                mediumpageModel.Mediumpage = null;
            }
            try
            {
                XNamespace content    = "http://purl.org/rss/1.0/modules/content/";
                string     url        = "https://medium.com/feed/@" + mediumpageModel.Mediumpage.MediumUsername;
                var        httpClient = new HttpClient();
                XDocument  xDoc       = new XDocument();
                xDoc = XDocument.Load(url);
                var items = (from x in xDoc.Descendants("item")
                             select new
                {
                    title = x.Element("title").Value,
                    link = x.Element("link").Value,
                    pubDate = x.Element("pubDate").Value,
                    content = x.Element(content + "encoded").Value,
                });
                foreach (var item in items)
                {
                    MediumModels model = new MediumModels
                    {
                        Title   = item.title,
                        Link    = item.link,
                        Date    = item.pubDate,
                        Content = item.content
                    };
                    mediumModel.Add(model);
                    if (!string.IsNullOrEmpty(search))
                    {
                        mediumpageModel.Medium = mediumModel.Where(i => EF.Functions.Like(i.Title, "%" + search + "%") || EF.Functions.Like(i.Content, "%" + search + "%")).ToList();
                    }
                    else
                    {
                        mediumpageModel.Medium = mediumModel;
                    }
                }
                return(View(mediumpageModel));
            }
            catch (Exception)
            {
                return(View(mediumpageModel));
            }
        }
Beispiel #2
0
 public List <Mediumpage> GetAll()
 {
     return(_mediumpageDal.GetAll().ToList());
 }