public Article UploadArticle(Article article)
 {
     OTSDBDAL otsdbDAL = new OTSDBDAL();
     otsdbDAL.ArticleList.Add(article);
     otsdbDAL.SaveChanges();
     return article;
 }
        public ActionResult GetArticle()
        {
            ArticleViewModel articleViewModel = new ArticleViewModel();
            ArticleBusinessLayer articleBusinessLayer = new ArticleBusinessLayer();
            List<Article> articleList = articleBusinessLayer.GetArticleList();

            articleViewModel.SideBarData = new SideBarViewModel();
            articleViewModel.SideBarData.CurrentIndex = 1;

            // articleViewModel.ArticleList = articleList;

            /*  Create by Mimikami
            *   Edit by Dwayne
            */
            int articleID = Convert.ToInt32(RouteData.Values["articleId"].ToString());
            if(articleID != 0)
            {
                Article ShowArticle = new Article();
                bool FindedFlag = false;
                foreach(Article art in articleList)
                {
                    if(art.ArticleID == articleID)
                    {
                        ShowArticle.ArticleID = art.ArticleID;
                        ShowArticle.Author = art.Author;
                        ShowArticle.Content = art.Content;
                        ShowArticle.CreateDate = art.CreateDate;
                        ShowArticle.Title = art.Title;
                        ShowArticle.Description = art.Description;
                        FindedFlag = true;
                        break;
                    }
                }
                if(FindedFlag)
                {
                    articleViewModel.ArticleID = ShowArticle.ArticleID;
                    articleViewModel.Author = ShowArticle.Author;
                    articleViewModel.Content = ShowArticle.Content;
                    articleViewModel.CreateDate = ShowArticle.CreateDate;
                    articleViewModel.Title = ShowArticle.Title;
                    articleViewModel.Description = ShowArticle.Description;
                }
            }

            /* Code by Dwayne */
            if (HttpContext.Session["User"] != null && Session["User"].ToString() != "")
            {
                articleViewModel.NavStatusData = new NavStatusViewModel();
                articleViewModel.NavStatusData.LeftLink = "/User/Profile/" + HttpContext.Session["User"].ToString();
                articleViewModel.NavStatusData.LeftText = Session["User"].ToString();
                articleViewModel.NavStatusData.RightLink = "/User/Logout";
                articleViewModel.NavStatusData.RightText = "Log out";
            }

            return View("content", articleViewModel);
        }
Ejemplo n.º 3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<OTSDBDAL>());

            /* Create by Dwayne 2015-12-4 14:05:12 */
            UserInfoBusinessLayer userInfoBusinessLayer = new UserInfoBusinessLayer();
            UserInfo userInfo = new UserInfo();
            userInfo.NickName = "Admin";
            userInfo.Mail = "*****@*****.**";
            userInfo.Password = "******";
            userInfo.Grade = 1;
            userInfoBusinessLayer.SignUp(userInfo);

            ArticleBusinessLayer articleBusinessLayer = new ArticleBusinessLayer();
            Article article = new Article();
            Regex rgx = new Regex("<[^>]+>");
            String TEMP;
            Markdown m = new Markdown();

                StreamReader SR1 = new StreamReader(Server.MapPath("./testArticle/Markdown_Documentation_Basics.text"));
                StreamReader SR2 = new StreamReader(Server.MapPath("./testArticle/Markdown_Documentation_Syntax.text"));
                StreamReader SR3 = new StreamReader(Server.MapPath("./testArticle/markdown-readme.text"));

                article.Author = "TestTest";
                article.CreateDate = DateTime.Now;
                article.Title = "Test" + (1).ToString();

                TEMP = SR1.ReadToEnd();
                article.Content = m.Transform(TEMP);
                TEMP = rgx.Replace(article.Content, " ");
                TEMP = TEMP.Replace("\n", "");
                if (TEMP.Length >= 80) article.Description = TEMP.Substring(0, 79) + "...";
                else article.Description = TEMP.Substring(0) + "...";

                articleBusinessLayer.UploadArticle(article);

                article.Author = "TestTest";
                article.CreateDate = DateTime.Now;
                article.Title = "Test" + (2).ToString();

                TEMP = SR2.ReadToEnd();
                article.Content = m.Transform(TEMP);
                TEMP = rgx.Replace(article.Content, " ");
                TEMP = TEMP.Replace("\n", "");
                if (TEMP.Length >= 80) article.Description = TEMP.Substring(0, 79) + "...";
                else article.Description = TEMP.Substring(0) + "...";

                articleBusinessLayer.UploadArticle(article);

                article.Author = "TestTest";
                article.CreateDate = DateTime.Now;
                article.Title = "Test" + (3).ToString();

                TEMP = SR3.ReadToEnd();
                article.Content = m.Transform(TEMP);
                TEMP = rgx.Replace(article.Content, " ");
                TEMP = TEMP.Replace("\n", "");
                if (TEMP.Length >= 80) article.Description = TEMP.Substring(0, 79) + "...";
                else article.Description = TEMP.Substring(0) + "...";

                articleBusinessLayer.UploadArticle(article);

                SR1.Close();
                SR2.Close();
                SR3.Close();
        }
        public ActionResult UploadArticle()
        {
            AddArticleViewModel aavm = new AddArticleViewModel();
            aavm.SideBarData = new SideBarViewModel();
            aavm.SideBarData.CurrentIndex = 1;
            aavm.CreateDate = DateTime.Now;

            Markdown m = new Markdown();
            Regex rgx = new Regex("<[^>]+>");
            String TEMP;

            Article readyArticle = new Article();
            ArticleBusinessLayer articleBusinessLayer = new ArticleBusinessLayer();
            readyArticle.Author = Request.Form["Author"];
            readyArticle.Title = Request.Form["Title"];
            readyArticle.CreateDate = Convert.ToDateTime(Request.Form["CreateDate"]);
            readyArticle.Content = m.Transform(Request.Unvalidated.Form["Content"]);
            TEMP = rgx.Replace(readyArticle.Content, " ");
            TEMP = TEMP.Replace("\n", "");
            if (TEMP.Length >= 80) readyArticle.Description = TEMP.Substring(0, 79)+"...";
            else readyArticle.Description = TEMP.Substring(0)+"...";

            articleBusinessLayer.UploadArticle(readyArticle);

            aavm.Message = "Add article successfully!";
            aavm.AlertType = "success";

            return View("Add", aavm);
        }