public ActionResult Post([FromBody] User u)
        {
            if (u == null)
            {
                return(BadRequest());
            }

            string today =
                System.DateTime.Now.Year.ToString() + "-" +
                System.DateTime.Now.Month.ToString() + "-" +
                System.DateTime.Now.Day.ToString() + " " +
                System.DateTime.Now.Hour.ToString() + ":" +
                System.DateTime.Now.Minute.ToString() + ":" +
                System.DateTime.Now.Second.ToString();

            u.creation_date = Convert.ToDateTime(today);

            _context.users.Add(u);
            _context.SaveChanges();

            return(Ok(_context.users
                      .Include(_u => _u.comments)
                      .ThenInclude(_u => _u.article)
                      .Include(_u => _u.posts)
                      .ToList()));
        }
Пример #2
0
        void ParseRssFile(String xml)
        {
            XmlDocument rssXmlDoc = new XmlDocument();

            // Load the RSS file from the RSS URL
            rssXmlDoc.LoadXml(xml);


            // Parse the Items in the RSS file
            XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");

            // Iterate through the items in the RSS file
            foreach (XmlNode rssNode in rssNodes)
            {
                //get all article data
                XmlNode rssSubNode = rssNode.SelectSingleNode("title");
                string  title      = rssSubNode != null ? rssSubNode.InnerText : "";

                rssSubNode = rssNode.SelectSingleNode("link");
                string link = rssSubNode != null ? rssSubNode.InnerText : "";

                rssSubNode = rssNode.SelectSingleNode("description");
                string description = rssSubNode != null ? rssSubNode.InnerText : "";

                rssSubNode = rssNode.SelectSingleNode("pubDate");
                string pubDate = rssSubNode != null ? rssSubNode.InnerText : "";

                //Articles too old? stop searching
                if ((DateTime.Now - Convert.ToDateTime(pubDate)).TotalDays > 30)
                {
                    break;
                }

                //check for relevant pages from each site, get all from ca.gov sites
                if ((title.Contains("California") || description.Contains("California") || link.Contains("ca.gov")) && (title.Contains("compliance") ||
                                                                                                                        title.Contains("regulation") || title.Contains("regulations") || title.Contains("regulated") ||
                                                                                                                        title.Contains("approve") || title.Contains("approved") || title.Contains("approves") ||
                                                                                                                        description.Contains("regulation") || description.Contains("regulations") || description.Contains("regulated") ||
                                                                                                                        description.Contains("approve") || link.Contains("ca.gov")))
                {
                    //if no matches with the database, we need to add it.
                    // aka: (new article published from websites below)
                    if ((_context.articles.FirstOrDefault(a => a.title == title)) == null)
                    {
                        Article tempArticle = new Article(link, title, description, Convert.ToDateTime(pubDate));
                        _context.articles.Add(tempArticle);

                        //new article, send email to subscribers
                        MailchimpRepository.CreateAndSendCampaign(modifyHTML(link));
                    }
                    else
                    {
                        //we can break out of this feed because we know we have searched this far since we have an article from this source
                        break;
                    }
                }
                _context.SaveChanges();
            }
        }
Пример #3
0
        public ActionResult Post([FromBody] Comment c)
        {
            if (c == null)
            {
                return(BadRequest());
            }

            _context.comments.Add(c);
            _context.SaveChanges();

            return(Ok(_context.comments.ToList()));
        }
        public ActionResult Post([FromBody] Post p)
        {
            if (p == null)
            {
                return(BadRequest());
            }

            _context.posts.Add(p);
            _context.SaveChanges();

            return(Ok(_context.posts.ToList()));
        }