コード例 #1
0
        public bool DeleteSelectedNews(string[] newsID)
        {
            if (newsID == null)
                return false;
            int NewsID = Convert.ToInt32(newsID[0]);

            //Find a news with NewsID equal to the id action parameter
            using (MagazineDBEntities cntxt = new MagazineDBEntities())
            {
                allNews = cntxt.News.ToList();
                News newsToDelete = (from news in allNews
                                     where news.NewsID == NewsID
                                     select news).SingleOrDefault();
                cntxt.News.Remove(newsToDelete);
                cntxt.SaveChanges();
                return true;
            }
        }
コード例 #2
0
        public List<MODEL.News> GetAllNews()
        {
            using (MagazineDBEntities cntxt = new MagazineDBEntities())
            {

                var newsList = new List<MODEL.News>();
                var newsListDAL = cntxt.News.ToList();

                foreach (var n in newsListDAL)
                {
                    var news = new MODEL.News();
                    news.NewsID = n.NewsID;

                    newsList.Add(news);
                }

                return newsList;
            }
        }