예제 #1
0
        public IQueryable GetExternArticles()
        {
            var        _db   = new WorldOfNews.Models.ArticleContext();
            IQueryable query = _db.ExternArticles;

            return(query);
        }
예제 #2
0
        public IQueryable GetCategories()
        {
            var        _db   = new WorldOfNews.Models.ArticleContext();
            IQueryable query = _db.Categories;

            return(query);
        }
        public IQueryable <Comment> GetComments([QueryString("articleID")] int?articleId)
        {
            var _db = new WorldOfNews.Models.ArticleContext();
            IQueryable <Comment> query = _db.Comments;

            if (articleId.HasValue && articleId > 0)
            {
                query = query.Where(p => p.ArticleID == articleId);
            }
            return(query);
        }
        public IQueryable <Article> GetArticle([QueryString("articleID")] int?articleId)
        {
            var _db = new WorldOfNews.Models.ArticleContext();
            IQueryable <Article> query = _db.Articles;

            if (articleId.HasValue && articleId > 0)
            {
                query = query.Where(p => p.ArticleID == articleId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
예제 #5
0
        public IQueryable <ExternArticle> GetExternArticles([QueryString("id")] int?categoryId)
        {
            var _db = new WorldOfNews.Models.ArticleContext();
            IQueryable <ExternArticle> query = _db.ExternArticles;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
                query = query.OrderBy(p => p.ArticleName);
            }

            string searchInput;

            searchInput = (string)Session["searchInput2"];

            if (!string.IsNullOrEmpty(searchInput))
            {
                query = query.Where(p => (p.ArticleName.Contains(searchInput)));
                Session["searchInput2"] = "";
            }

            string orderingInput;

            orderingInput = (string)Session["orderingInput"];

            switch (orderingInput)
            {
            case "A to Z":
                return(query.OrderBy(p => p.ArticleName));

            case "Z to A":
                return(query.OrderByDescending(p => p.ArticleName));

            case "From Old to New":
                return(query.OrderBy(p => p.DatePublished));

            case "From New to Old":
                return(query.OrderByDescending(p => p.DatePublished));
            }

            return(query);
        }
예제 #6
0
        protected void RemoveExternArticleButton_Click(object sender, EventArgs e)
        {
            using (var _db = new WorldOfNews.Models.ArticleContext())
            {
                int articleId = Convert.ToInt16(DropDownRemoveExternArticle.SelectedValue);
                var myItem    = (from c in _db.ExternArticles where c.ArticleID == articleId select c).FirstOrDefault();
                if (myItem != null)
                {
                    _db.ExternArticles.Remove(myItem);
                    _db.SaveChanges();

                    // Reload the page.
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl + "?ExternArticleAction=remove");
                }
                else
                {
                    LabelRemoveStatus.Text = "Unable to locate article.";
                }
            }
        }
예제 #7
0
 protected void RemoveCategoryButton_Click(object sender, EventArgs e)
 {
     using (var _db = new WorldOfNews.Models.ArticleContext())
     {
         int categoryId;
         try
         {
             categoryId = Convert.ToInt16(DropDownRemoveCategory.SelectedValue);
         }
         catch (Exception ex)
         {
             categoryId = -1;
         }
         var myItems = from c in _db.Articles where c.CategoryID == categoryId select c;
         if (myItems != null)
         {
             foreach (var iter in myItems)
             {
                 _db.Articles.Remove(iter);
             }
             var myCategory = (from c in _db.Categories where c.CategoryID == categoryId select c).FirstOrDefault();
             if (myCategory != null)
             {
                 _db.Categories.Remove(myCategory);
                 _db.SaveChanges();
             }
             else
             {
                 LabelRemoveStatus.Text += "Category not found.";
             }
             string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
             Response.Redirect(pageUrl + "?CategoryAction=remove");
         }
         else
         {
             LabelRemoveStatus.Text += "No category found.";
         }
     }
 }