コード例 #1
0
 //文章详情页面
 public ActionResult Detail(int id)
 {
     Article a;
     using (ArticleDao dao = new ArticleDao())
         a = dao.detail(id);
     return View(a);
 }
コード例 #2
0
ファイル: RubrikaController.cs プロジェクト: PPRO/projectBlog
        public ActionResult Rusko()
        {
            int id = 5;

            IList<Article> articles = new ArticleDao().GetArticleInCategoryId( id );
            return View("Rubrika", articles);
        }
コード例 #3
0
ファイル: BlogController.cs プロジェクト: PPRO/projectBlog
        public ActionResult ArticleDetail(int id)
        {
            User user = new UserDao().GetByLogin(User.Identity.Name);
            ViewBag.User = user.Name;

            Article article = new ArticleDao().GetById(id);

            return View(article);
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: PPRO/projectBlog
        public ActionResult ArticleNew()
        {
            int itemOnPage = 3;
            int pg = 1;
            int totalArticle;

            IList<Article> articles = new ArticleDao().GetArticlePage(itemOnPage, pg, out totalArticle);

            return View(articles);
        }
コード例 #5
0
ファイル: ArticleController.cs プロジェクト: PPRO/projectBlog
        public ActionResult AddArticle( Article article, HttpPostedFileBase picture, int categoryId )
        {
            if( ModelState.IsValid )
            {

                if( picture != null )
                {
                    if( picture.ContentType == "image/jpeg" || picture.ContentType == "image/png" )
                    {
                        Image image = Image.FromStream( picture.InputStream );

                        if( image.Height > 200 || image.Width > 200 )
                        {
                            Image small = Class.ImageHelper.ScaleImage( image, 200, 200 );
                            Bitmap b = new Bitmap( small );

                            Guid guid = Guid.NewGuid();
                            string imageName = guid.ToString() + ".jpg";

                            b.Save( Server.MapPath( "~/uploads/aticleImage/" + imageName ), ImageFormat.Jpeg );
                            b.Save( Server.MapPath( "~/uploads/articleImage/" + imageName ), ImageFormat.Jpeg );

                            small.Dispose();
                            b.Dispose();

                            article.ImageName = imageName;
                        }
                        else
                        {
                            picture.SaveAs( Server.MapPath( "~/uploads/Article/" + picture.FileName ) );
                        }
                    }
                }
                ArticleCategoryDao articleCategoryDao = new ArticleCategoryDao();

                ArticleCategory articleCategory = articleCategoryDao.GetById( categoryId );
                article.Category = articleCategory;
                article.PostDate = DateTime.Now;
                article.User = new BlogUserDao().GetByLogin(User.Identity.Name);
                ArticleDao articleDao = new ArticleDao();

                articleDao.Create( article );

                TempData["message-success"] = "Kniha byla pridana";

            }
            else
            {
                return View( "Create", article );
            }

            return RedirectToAction( "Index" );
        }
コード例 #6
0
ファイル: BlogController.cs プロジェクト: PPRO/projectBlog
        /// <summary>
        /// Detail článku
        /// </summary>
        /// <param name="id">Identifikační číslo článku</param>
        /// <returns>detail článku</returns>
        public ActionResult ArticleDetail(int? id)
        {
            int i = id ?? 0;
            if ( i == 0 )
            {
                return RedirectToAction("Index");
            }
            else
            {

                Article article = new ArticleDao().GetById(i);
                return View(article);
            }
        }
コード例 #7
0
ファイル: BlogController.cs プロジェクト: PPRO/projectBlog
        // GET: Blog
        /// <summary>
        /// Seznam všech článků
        /// </summary>
        /// <param name="page"></param>
        /// <returns>články</returns>
        public ActionResult Index(int? page)
        {
            int itemOnPage = 5;
            int pg = page ?? 1;
            int totalArticle;

            IList<Article> articles = new ArticleDao().GetArticlePage(itemOnPage, pg, out totalArticle);

            // Stránkování - max 5 článků
            ViewBag.Pages = (int) Math.Ceiling((double)totalArticle/(double)itemOnPage);
            ViewBag.CurrentPage = pg;

            // všechny kategorie článků
            ViewBag.Category = new ArticleCategoryDao().GetAll();
            return View(articles);
        }
コード例 #8
0
ファイル: BlogController.cs プロジェクト: PPRO/projectBlog
        // GET: Blog
        public ActionResult Index(int? page)
        {
            int itemOnPage = 10;
            int pg = page ?? 1;
            int totalArticle;

            User user = new UserDao().GetByLogin(User.Identity.Name);
            ViewBag.User = user.Name;
            IList<Article> articles = new ArticleDao().GetArticlePage(itemOnPage, pg, out totalArticle);

            ViewBag.Pages = (int) Math.Ceiling((double)totalArticle/(double)itemOnPage);
            ViewBag.CurrentPage = pg;
            ViewBag.Category = new ArticleCategoryDao().GetAll();

            return View(articles);
        }
コード例 #9
0
ファイル: HomeController.cs プロジェクト: PPRO/projectBlog
        public ActionResult Index( int? page)
        {
            int itemsOnPage = 10;
            int pg = page ?? 1;
            int totalArticles;

            ArticleDao articleDao = new ArticleDao();
            IList<Article> articles = articleDao.GetArticlePaged( itemsOnPage, pg, out totalArticles);
            /*
            IList<BlogComment> comments = new BlogCommentDao().GetAll();
            */
            ViewBag.Pages = (int)Math.Ceiling( (double)totalArticles / (double)itemsOnPage );
            ViewBag.CurrentPage = pg;
            ViewBag.Category = new ArticleCategoryDao().GetAll();

            return View(articles);
        }
コード例 #10
0
ファイル: BlogController.cs プロジェクト: PPRO/projectBlog
        public ActionResult MenuRubrika()
        {
            {

                IList<Article> article = new List<Article>();
                List<int> pouzito = new List<int>();

                IList<Article> articles = new ArticleDao().GetAll();

                foreach (Article a in articles)
                {
                    bool y = false;
                    int d = a.Id;
                    if (pouzito.Count == 0)
                    {

                        pouzito.Add(a.Category.Id);
                        article.Add(a);

                    }
                    else
                    {
                        for (int i = 0; i < pouzito.Count; i++)
                        {
                            if (a.Category.Id == pouzito[i])
                            {
                                y = true;
                            }
                        }
                        if (!y)
                        {

                            pouzito.Add(a.Category.Id);
                            article.Add(a);

                        }

                    }

                }

                return View(article);
            }
        }
コード例 #11
0
ファイル: ReplyDao.cs プロジェクト: zwkjgs/XKD
        public int GetArticleIDByOldArticle(int replyid, MessageType msgtype)
        {
            int         result      = 0;
            ArticleInfo articleInfo = new ArticleInfo();

            switch (msgtype)
            {
            case MessageType.News:
            {
                NewsReplyInfo newsReplyInfo = this.GetReply(replyid) as NewsReplyInfo;
                if (newsReplyInfo != null && newsReplyInfo.NewsMsg != null && newsReplyInfo.NewsMsg.Count != 0)
                {
                    articleInfo.Title       = newsReplyInfo.NewsMsg[0].Title;
                    articleInfo.ArticleType = ArticleType.News;
                    articleInfo.Content     = newsReplyInfo.NewsMsg[0].Content;
                    articleInfo.ImageUrl    = newsReplyInfo.NewsMsg[0].PicUrl;
                    articleInfo.Url         = newsReplyInfo.NewsMsg[0].Url;
                    articleInfo.Memo        = newsReplyInfo.NewsMsg[0].Description;
                    articleInfo.PubTime     = DateTime.Now;
                    if (articleInfo.Url.Length > 10)
                    {
                        articleInfo.LinkType = LinkType.Userdefined;
                    }
                    else
                    {
                        articleInfo.LinkType = LinkType.ArticleDetail;
                    }
                    result = new ArticleDao().AddSingerArticle(articleInfo);
                }
                break;
            }

            case MessageType.List:
            {
                NewsReplyInfo newsReplyInfo = this.GetReply(replyid) as NewsReplyInfo;
                articleInfo.Title       = newsReplyInfo.NewsMsg[0].Title;
                articleInfo.ArticleType = ArticleType.List;
                articleInfo.Content     = newsReplyInfo.NewsMsg[0].Content;
                articleInfo.ImageUrl    = newsReplyInfo.NewsMsg[0].PicUrl;
                articleInfo.Url         = newsReplyInfo.NewsMsg[0].Url;
                articleInfo.Memo        = newsReplyInfo.NewsMsg[0].Description;
                articleInfo.PubTime     = DateTime.Now;
                if (articleInfo.Url.Length > 10)
                {
                    articleInfo.LinkType = LinkType.Userdefined;
                }
                else
                {
                    articleInfo.LinkType = LinkType.ArticleDetail;
                }
                List <ArticleItemsInfo> list = new List <ArticleItemsInfo>();
                if (newsReplyInfo.NewsMsg != null && newsReplyInfo.NewsMsg.Count > 0)
                {
                    int num = 0;
                    foreach (NewsMsgInfo current in newsReplyInfo.NewsMsg)
                    {
                        num++;
                        if (num != 1)
                        {
                            ArticleItemsInfo articleItemsInfo = new ArticleItemsInfo();
                            articleItemsInfo.Title     = current.Title;
                            articleItemsInfo.Content   = current.Content;
                            articleItemsInfo.ImageUrl  = current.PicUrl;
                            articleItemsInfo.Url       = current.Url;
                            articleItemsInfo.ArticleId = 0;
                            if (articleItemsInfo.Url.Length > 10)
                            {
                                articleItemsInfo.LinkType = LinkType.Userdefined;
                            }
                            else
                            {
                                articleItemsInfo.LinkType = LinkType.ArticleDetail;
                            }
                            list.Add(articleItemsInfo);
                        }
                    }
                }
                articleInfo.ItemsInfo = list;
                result = new ArticleDao().AddMultiArticle(articleInfo);
                break;
            }
            }
            return(result);
        }
コード例 #12
0
ファイル: RubrikaController.cs プロジェクト: PPRO/projectBlog
        // GET: Admin/Rubrika
        public ActionResult Index(int id)
        {
            IList<Article> articles = new ArticleDao().GetArticleInCategoryId(id);

            return View("Rubrika", articles);
        }
コード例 #13
0
ファイル: RubrikaController.cs プロジェクト: PPRO/projectBlog
        public ActionResult ArticleDetail(int id)
        {
            Article article = new ArticleDao().GetById(id);

            return View(article);
        }
コード例 #14
0
        public ActionResult AddArticle(Article article, HttpPostedFileBase picture, int categoryId)
        {
            if (ModelState.IsValid)
            {
                 IList<Article> art = new ArticleDao().GetAll();

                foreach (Article a in art)
                {
                    if (a.Title == article.Title)
                    {
                        TempData["message-unsuccess"] = "Nadpis už existuje";
                        IList<ArticleCategory> categories = new ArticleCategoryDao().GetAll();
                        ViewBag.Category = categories;
                        return View("CreateArticle", article);
                    }

                }

                if (picture != null)
                {
                    if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")
                    {
                        Image image = Image.FromStream(picture.InputStream);

                        if (image.Height > 200 || image.Width > 200)
                        {
                            Image small = Helper.ImageHelper.ScaleImage(image, 200, 200);
                            Bitmap b = new Bitmap(small);

                            Guid guid = Guid.NewGuid();
                            string imageName = guid.ToString() + ".jpg";

                            b.Save(Server.MapPath("~/image/aticleImage/" + imageName), ImageFormat.Jpeg);
                            b.Save(Server.MapPath("~/image/articleImage/" + imageName), ImageFormat.Jpeg);

                            small.Dispose();
                            b.Dispose();

                            article.ImageName = imageName;
                        }
                        else
                        {
                            picture.SaveAs(Server.MapPath("~/image/articleImage/" + picture.FileName));
                        }
                    }
                }

                ArticleCategoryDao articleCategoryDao = new ArticleCategoryDao();

                ArticleCategory articleCategory = articleCategoryDao.GetById(categoryId);
                article.Category = articleCategory;
                article.PosteDate = DateTime.Now;
                article.User = new UserDao().GetByLogin(User.Identity.Name);
                ArticleDao articleDao = new ArticleDao();

                articleDao.Create(article);

                TempData["message-success"] = "Článek byl přidán";

            }
            else
            {
                IList<ArticleCategory> categories = new ArticleCategoryDao().GetAll();
                ViewBag.Category = categories;
                return View("CreateArticle", article);
            }

            return RedirectToAction("Index");
        }
コード例 #15
0
ファイル: BlogController.cs プロジェクト: PPRO/projectBlog
        /// <summary>
        /// Menu rubrika
        /// </summary>
        /// <param name="id"></param>
        /// <returns>clanky</returns>
        public ActionResult Rubrika(int? id)
        {
            User user = new UserDao().GetByLogin(User.Identity.Name);
            ViewBag.User = user.Name;

            int i = id ?? 0;
            if ( i == 0 )
            {
                return RedirectToAction("Index");
            }
            else
            {
                IList<Article> article = new ArticleDao().GetArticleInCategoryId(i);
                ViewBag.Categoties = new ArticleCategoryDao().GetAll();

                /*
                 * predani identifikacniho cisla htmlHelpers pro porovnani
                 */
                HtmlHelpersExtension.Id = id.ToString();

                return View("Index", article);
            }
        }
コード例 #16
0
        public ActionResult EditArticle(int id)
        {
            User user = new UserDao().GetByLogin(User.Identity.Name);
            ViewBag.User = user.Name;
            Article article = new ArticleDao().GetById(id);
            ViewBag.Category = new ArticleCategoryDao().GetAll();

            return View(article);
        }
コード例 #17
0
        public ActionResult DeleteCategory(int id)
        {
            int i = id;
            IList<Article> article = new ArticleDao().GetArticleInCategoryId(id);
            if (article.Count == 0 )
            {
                ArticleCategory category = new ArticleCategoryDao().GetById(id);
                new ArticleCategoryDao().Delete(category);
                TempData["message-success"] = "Kategorie byla smazána";

                return RedirectToAction("Kategorie");
            }
            TempData["message-unsuccess"] =
                "Kategorie je použita u těchto článků. Před smazáním kategorie je potřeba změnit kategorii u článků!";

            return RedirectToAction("Rubrika", "Blog", routeValues: new
            {
                id = i
            });
        }
コード例 #18
0
ファイル: ArticleController.cs プロジェクト: PPRO/projectBlog
        public ActionResult EditArticle( int id )
        {
            Article article = new ArticleDao().GetById( id );
            ViewBag.Categories = new ArticleCategoryDao().GetAll();

            return View( article );
        }
コード例 #19
0
ファイル: ArticleController.cs プロジェクト: PPRO/projectBlog
        public ActionResult DeleteArticle( int id )
        {
            try
            {
                ArticleDao articleDao = new ArticleDao();
                Article article = articleDao.GetById( id );

                if( article.ImageName != null )
                    System.IO.File.Delete( Server.MapPath( "~/uploads/articleImage/" + article.ImageName ) );

                articleDao.Delete( article );

                TempData["message-success"] = "Článek" + article.Title + "byla smazan.";
            }
            catch( Exception exception )
            {

                throw;
            }

            return RedirectToAction( "Index" );
        }
コード例 #20
0
ファイル: ArticleController.cs プロジェクト: PPRO/projectBlog
        // GET: Admin/Article
        public ActionResult Index( int? page )
        {
            int itemsOnPage = 5;
            int pg = page ?? 1;
            int totalArticles;

            BlogUser user = new BlogUserDao().GetByLogin( User.Identity.Name );
            int id = user.Id;
            ArticleDao articleDao = new ArticleDao();

            IList<Article> article = articleDao.GetArticlePagedByUserId( itemsOnPage, pg, out totalArticles, id );

            ViewBag.Pages = (int)Math.Ceiling( (double)totalArticles / (double)itemsOnPage );
            ViewBag.CurrentPage = pg;
            ViewBag.Category = new ArticleCategoryDao().GetAll();

            return View( article );
        }
コード例 #21
0
ファイル: ArticleController.cs プロジェクト: PPRO/projectBlog
        public ActionResult UpdateArticle( Article article, HttpPostedFileBase picture, int categoryId )
        {
            try
            {
                ArticleDao articleDao = new ArticleDao();
                ArticleCategoryDao articleCategoryDao = new ArticleCategoryDao();

                ArticleCategory articleCategory = articleCategoryDao.GetById( categoryId );
                BlogUser user = new BlogUserDao().GetByLogin(User.Identity.Name);

                article.Category = articleCategory;
                article.User = user;

                if( picture != null )
                {
                    if( picture.ContentType == "image/jpeg" || picture.ContentType == "image/png" )
                    {
                        Image image = Image.FromStream( picture.InputStream );

                        Guid guid = Guid.NewGuid();
                        string imageName = guid.ToString() + ".jpg";

                        if( image.Height > 200 || image.Width > 200 )
                        {
                            Image small = Class.ImageHelper.ScaleImage( image, 200, 200 );
                            Bitmap b = new Bitmap( small );

                            b.Save( Server.MapPath( "~/uploads/articleImage/" + imageName ), ImageFormat.Jpeg );

                            small.Dispose();
                            b.Dispose();

                        }
                        else
                        {
                            picture.SaveAs( Server.MapPath( "~/uploads/articleImage/" + picture.FileName ) );
                        }

                        System.IO.File.Delete( Server.MapPath( "~/uploads/articleImage/" + article.ImageName ) );
                        article.ImageName = imageName;
                    };
                }

                articleDao.Update( article );

                TempData["message-success"] = "Kniha" + article.Title + "byla upravena.";
            }
            catch( Exception )
            {

                throw;
            }

            return RedirectToAction( "Index", "Article" );
        }