public void DeleteNews(int id)
        {
            news_all newsForDelete = _db.news_all.Where(x => x.ID == id).FirstOrDefault();

            _db.news_all.Remove(newsForDelete);
            _db.SaveChanges();
        }
示例#2
0
        public IHttpActionResult getNotifications(int lastReadID = -1)
        {
            if (lastReadID == -1)
            {
                return(null);
            }
            MailNewsService mailNewsService = new MailNewsService();

            mailNewsService.getUnreadEmails();
            InsuredTravelingEntity entities = new InsuredTravelingEntity();
            news_all lastReadNews           = entities.news_all.Where(x => x.ID == lastReadID).FirstOrDefault();
            IQueryable <news_all> unreadNews;

            if (lastReadNews == null)
            {
                unreadNews = entities.news_all.OrderByDescending(x => x.DataCreated).Take(10);
            }
            else
            {
                unreadNews = entities.news_all.Where(x => x.DataCreated > lastReadNews.DataCreated).
                             OrderByDescending(x => x.DataCreated);
            }

            if (unreadNews == null)
            {
                return(null);
            }

            List <News> notifications = new List <News>();

            foreach (news_all n in unreadNews)
            {
                if ((bool)n.isNotification)
                {
                    News npom = new News();
                    npom.Id      = n.ID.ToString();
                    npom.Title   = n.Title;
                    npom.Content = n.Content;
                    notifications.Add(npom);
                }
            }

            if (notifications.Count == 0)
            {
                return(null);
            }
            else
            {
                return(Ok(new { News = notifications }));
            }
        }
        public void getUnreadEmails()
        {
            InsuredTravelingEntity entities = new InsuredTravelingEntity();
            string n = "[notification]";

            using (ImapClient client = new ImapClient("imap.zoho.com", 993,
                                                      "*****@*****.**", "Enter4Sy", AuthMethod.Login, true))
            {
                IEnumerable <uint> uids = client.Search(SearchCondition.Unseen());

                foreach (uint uid in uids)
                {
                    MailMessage message = client.GetMessage(uid);
                    news_all    news    = entities.news_all.Create();;
                    news.Title            = message.Subject.Trim();
                    news.Content          = message.Body.Trim();
                    news.DataCreated      = (DateTime)message.Date();
                    news.InsuranceCompany = "Eurolink";
                    Random r = new Random();
                    //news.ID = r.Next(10000, 99999);
                    if (message.Subject.ToLower().StartsWith(n))
                    {
                        news.isNotification = true;
                    }
                    else
                    {
                        news.isNotification = false;
                    }

                    entities.news_all.Add(news);

                    client.MoveMessage(uid, "SeenNews");
                    client.DeleteMessage(uid, "Inbox");
                }

                client.Expunge("Inbox");
                client.Dispose();

                if (uids.Count() != 0)
                {
                    entities.SaveChanges();
                }
            }
        }
示例#4
0
        public ActionResult AddNews(HttpPostedFileBase newsImage, string newsTitle = null, string newsContent = null, bool newsIsNotification = false)
        {
            IQueryable <news_all> news1 = _ns.GetAllNews();

            if (newsImage == null || newsTitle == null || newsContent == null || newsTitle == "" || newsContent == "")
            {
                return(View("Index", news1));
            }

            var    lastNewsId = _ns.LastNewsId() + 1;
            string fileName   = lastNewsId + "_" + newsImage.FileName;


            var path = @"~/News/" + fileName;

            newsImage.SaveAs(Server.MapPath(path));

            news_all news = new news_all();

            news.Title            = newsTitle;
            news.Content          = newsContent;
            news.isNotification   = newsIsNotification;
            news.DataCreated      = DateTime.Now;
            news.InsuranceCompany = "Eurolink";
            news.ImageLocation    = fileName;

            try
            {
                _ns.AddNews(news);
                ViewBag.Success = true;
                news1           = _ns.GetAllNews();
                return(View("Index", news1));
            }
            catch
            {
                // return Json(new { Success = "False", Message = "Database problem" }, JsonRequestBehavior.AllowGet);
                ViewBag.Success = false;
                news1           = _ns.GetAllNews();
                return(View("Index", news1));
            }
        }
 public void AddNews(news_all News)
 {
     _db.news_all.Add(News);
     _db.SaveChanges();
 }