public ActionResult Index(string message)
        {
            int     start   = 11625;
            placard getnews = new placard();
            var     news    = new NewsRepository().GetAll().Where(x => x.getId != null).ToList();

            if (news.Count != 0)
            {
                var n = news.Last();
                for (int i = 0; i < 5; i++)
                {
                    var h = Homenew((int)n.getId + i);
                    if (h)
                    {
                        i = 5;
                    }
                    else
                    {
                        Homenew((int)n.getId + i);
                    }
                }
            }
            else
            {
                string url = "http://www.ggesports.com/zh-TW/news/lol/global/Detail/" + start.ToString();

                var webGet = new HtmlWeb();
                var doc    = webGet.Load(url);
                HtmlNodeCollection body    = doc.DocumentNode.SelectNodes("//*[@class='news-content-body']");
                string             t       = doc.DocumentNode.SelectNodes("//*[@class='subject']")[0].InnerText;
                string             c       = body[0].InnerHtml;
                string             utctime = doc.DocumentNode.SelectNodes("//*[@class='subtitle']/span")[0].InnerText;
                utctime = utctime.Replace(" (UTC)", "Z");
                DateTime rt = DateTime.Parse(utctime);

                DateTime tme = DateTime.Parse(utctime);
                string   img = doc.DocumentNode.SelectNodes("//*[@class='news-content-body']//img")[0].Attributes["src"].Value;
                getnews = new placard
                {
                    title     = t,
                    content   = c,
                    real_time = rt,
                    time      = tme,
                    image     = img,
                    p_class   = 4,
                    getId     = start
                };
                getnews.manager = "來源:GG電競王";

                new NewsRepository().Create(getnews);
            }

            ViewBag.StatusMessage =
                message != "" ? message
                : "";
            return(View());
        }
 public void Delete(placard instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("instance");
     }
     else
     {
         Db.Entry(instance).State = EntityState.Deleted;
         this.SaveChanges();
     }
 }
 public void Create(placard instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("instance");
     }
     else
     {
         Db.placard.Add(instance);
         this.SaveChanges();
     }
 }
 public ActionResult Edit(placard news)
 {
     if (news != null && ModelState.IsValid)
     {
         this.newsRepository.Update(news);
         return(RedirectToAction("News"));
     }
     else
     {
         return(RedirectToAction("News"));
     }
 }
        private bool Homenew(int i)
        {
            bool b = true;

            try
            {
                int    di  = i + 1;
                string url = "http://www.ggesports.com/zh-TW/news/lol/global/Detail/" + di.ToString();



                var webGet = new HtmlWeb();
                var doc    = webGet.Load(url);
                if (doc != null)
                {
                    HtmlNodeCollection body    = doc.DocumentNode.SelectNodes("//*[@class='news-content-body']");
                    string             t       = doc.DocumentNode.SelectNodes("//*[@class='subject']")[0].InnerText;
                    string             c       = body[0].InnerHtml;
                    string             utctime = doc.DocumentNode.SelectNodes("//*[@class='subtitle']/span")[0].InnerText;
                    utctime = utctime.Replace(" (UTC)", "Z");
                    DateTime rt = DateTime.Parse(utctime);

                    DateTime tme     = DateTime.Parse(utctime);
                    string   img     = doc.DocumentNode.SelectNodes("//*[@class='news-content-body']//img")[0].Attributes["src"].Value;
                    var      getnews = new placard
                    {
                        title     = t,
                        content   = c,
                        real_time = rt,
                        time      = tme,
                        image     = img,
                        p_class   = 4,
                        getId     = di
                    };
                    getnews.manager = "來源:GG電競王";

                    new NewsRepository().Create(getnews);
                }
            }
            catch {
                b = false;
            }

            return(b);
        }
        public async System.Threading.Tasks.Task <ActionResult> Create(placard news, HttpPostedFileBase image)
        {
            if (news != null && ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(news.image) && image != null)
                {
                    string filename = "";
                    filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                    Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                    _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                    var imageUrl = await _imageUploader.UploadImage(image, filename, "News");

                    news.image = imageUrl;
                }

                //Send to all subscribers
                if (news.mail_bear == 1)
                {
                    string timemessenger;



                    var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest;

                    request.KeepAlive   = true;
                    request.Method      = "POST";
                    request.ContentType = "application/json; charset=utf-8";

                    request.Headers.Add("authorization", "Basic YmJkNzJjYmMtNzcwNi00NDhjLWE5N2QtNWQxZWM2YzEwMGI4");
                    var serializer = new JavaScriptSerializer();
                    var obj        = new object();
                    if (news.time != null)
                    {
                        timemessenger  = Convert.ToDateTime(news.time).ToString("yyyy-MM-dd HH:mm:ss");
                        timemessenger += " GMT+0800";
                        obj            = new
                        {
                            app_id            = "d7213a53-69e2-4845-b4d3-b487528a2483",
                            contents          = new { en = news.title },
                            headings          = new { en = "熊i猜-熊報信" },
                            included_segments = new string[] { "All" },
                            ttl              = 2419200,
                            delayed_option   = "last-active",
                            chrome_web_image = news.image,
                            chrome_web_badge = news.image,
                            send_after       = timemessenger
                        };
                    }
                    else
                    {
                        obj = new
                        {
                            app_id            = "d7213a53-69e2-4845-b4d3-b487528a2483",
                            contents          = new { en = news.title },
                            headings          = new { en = "熊i猜-熊報信" },
                            included_segments = new string[] { "All" },
                            ttl              = 2419200,
                            delayed_option   = "last-active",
                            chrome_web_image = news.image,
                            chrome_web_badge = news.image
                        };
                    }
                    var    param     = serializer.Serialize(obj);
                    byte[] byteArray = Encoding.UTF8.GetBytes(param);

                    string responseContent = null;

                    try
                    {
                        using (var writer = request.GetRequestStream())
                        {
                            writer.Write(byteArray, 0, byteArray.Length);
                        }

                        using (var response = request.GetResponse() as HttpWebResponse)
                        {
                            using (var reader = new StreamReader(response.GetResponseStream()))
                            {
                                responseContent = reader.ReadToEnd();
                            }
                        }
                    }
                    catch (WebException ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());
                    }

                    System.Diagnostics.Debug.WriteLine(responseContent);
                }
                //Send to all subscribers END



                this.newsRepository.Create(news);
                return(RedirectToAction("News"));
            }
            else
            {
                return(View(news));
            }
        }