Example #1
0
        public List <ArticlesModels> findListByPage(ArticlesQueryModels articlesQueryModels)
        {
            List <ArticlesModels> articlesModelsList = new List <ArticlesModels>();
            String sql = "select top {0} t.id,t.title,t.create_date,t.article_types_id,t.ctr   from Articles t where t.article_types_id=@ArticleTypesId and t.Id not in (select top {1} t1.Id from Articles t1 where t1.article_types_id=@ArticleTypesId order by t1.create_date desc) order by t.create_date desc";

            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@ArticleTypesId", articlesQueryModels.ArticleTypesId)
            };
            if (articlesQueryModels.ArticleTypesId == 0)
            {
                sql = "select top {0} t.id,t.title,t.create_date,t.article_types_id,t.ctr   from Articles t where t.Id not in (select top {1} t1.Id from Articles t1 order by t1.create_date desc) order by t.create_date desc";
            }
            sql = String.Format(sql, articlesQueryModels.PageSize, ((articlesQueryModels.CurrentPage - 1) * articlesQueryModels.PageSize));
            SqlDataReader objReader = SqlHelper.getReader(sql, param);

            while (objReader.Read())
            {
                ArticlesModels articles = new ArticlesModels();
                articles.Id         = Convert.ToInt32(objReader["id"]);
                articles.Title      = Convert.ToString(objReader["title"]);
                articles.CreateDate = Convert.ToString(objReader["create_date"]);
                articles.Ctr        = Convert.ToInt32(objReader["ctr"]);
                articlesModelsList.Add(articles);
            }
            return(articlesModelsList);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ArticlesModels articlesModels = db.ArticlesModels.Find(id);

            db.ArticlesModels.Remove(articlesModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
 public ArticlesModels updateArticle(ArticlesModels model)
 {
     if (model.comments == null)
     {
         model.comments = new List <Comment>();
     }
     mapper.Update <ArticlesModels>("Set timestamp =?, view_count=?, author = ?, title = ?, content = ?, comments =? where id = ?",
                                    model.timestamp, model.view_count, model.author, model.title, model.content, model.comments, model.id);
     return(model);
 }
Example #4
0
        public ActionResult Watch(string id)
        {
            ArticlesModels model = articlesDao.ArticleById(id);

            if (Request.IsAuthenticated && model.author != User.Identity.Name)
            {
                model.view_count = model.view_count + 1;
            }
            articlesDao.updateArticle(model);
            return(View(model));
        }
 public ActionResult Edit([Bind(Include = "Id,Title,Content")] ArticlesModels articlesModels)
 {
     if (ModelState.IsValid)
     {
         articlesModels.User            = User.Identity.GetUserName();
         articlesModels.PostDate        = DateTime.Now;
         db.Entry(articlesModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(articlesModels));
 }
        // GET: Articles/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ArticlesModels articlesModels = db.ArticlesModels.Find(id);

            if (articlesModels == null)
            {
                return(HttpNotFound());
            }
            return(View(articlesModels));
        }
Example #7
0
        public ActionResult EditPost(ArticlesModels model)
        {
            var post = articlesDao.ArticleById(model.id.ToString());

            if (post.author != User.Identity.Name)
            {
                return(RedirectToAction("Index"));
            }

            post.title     = model.title;
            post.content   = model.content;
            post.timestamp = DateTimeOffset.Now;
            articlesDao.updateArticle(post);

            return(RedirectToAction("Watch", "Home", new { @id = model.id }));
        }
Example #8
0
        public ActionResult Detail(int?id)
        {
            if (id == null)
            {
                ViewBag.Message = "参数缺少ID";
                return(View());
            }
            ArticlesManager articlesManager = new ArticlesManager();
            ArticlesModels  articlesModels  = articlesManager.findById(Convert.ToInt32(id));

            if (articlesModels == null)
            {
                ViewBag.Message = "系统找不到数据,入参ID为:" + id;
                return(View());
            }
            ViewBag.ArticlesModels = articlesModels;
            ViewBag.Message        = articlesModels.Title;
            return(View());
        }
Example #9
0
        public async Task <ActionResult> CreatePost(ArticlesModels model)
        {
            model.author     = User.Identity.Name;
            model.timestamp  = DateTimeOffset.Now;
            model.view_count = 0;
            await articlesDao.addArticle(model);

            var articles = await articlesDao.getAuthorArticles(User.Identity.Name);

            if (articles.Count() > 4)
            {
                var user = usersDao.GetUserByName(User.Identity.Name);
                if (user.employeeid == 0)
                {
                    await usersDao.SetUserNotification(User.Identity.Name, true);
                }
            }

            return(RedirectToAction("Index"));
        }
Example #10
0
        public ActionResult PostComment(string comment, string postid)
        {
            ArticlesModels model = articlesDao.ArticleById(postid);
            Comment        com   = new Comment();

            com.votes      = new List <Vote>();
            com.commentary = comment;
            com.author     = User.Identity.Name;

            if (model.comments == null)
            {
                model.comments = new List <Comment>();
            }

            model.comments.Add(com);

            articlesDao.updateArticle(model);

            return(RedirectToAction("Watch", "Home", new { @id = postid }));
        }
        // GET: Articles/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ArticlesModels articlesModels = db.ArticlesModels.Find(id);

            var model = new ArticleDetailsViewModels()
            {
                Article = db.ArticlesModels.Find(id),

                Comment = db.CommentModels.Where(m => m.ArticleId == id).ToList()
            };

            if (articlesModels == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
Example #12
0
        public ArticlesModels findById(int id)
        {
            String sql = "select t.id,t.title,t.content,t.author,t.tags,t.last_update_date,t.create_date,t.article_types_id,t.ctr   from Articles t where t.id=@Id ";

            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@Id", id)
            };
            SqlDataReader objReader = SqlHelper.getReader(sql, param);

            while (objReader.Read())
            {
                ArticlesModels articles = new ArticlesModels();
                articles.Id             = Convert.ToInt32(objReader["id"]);
                articles.Title          = Convert.ToString(objReader["title"]);
                articles.CreateDate     = Convert.ToString(objReader["create_date"]);
                articles.Ctr            = Convert.ToInt32(objReader["ctr"]);
                articles.Content        = Convert.ToString(objReader["content"]);
                articles.Author         = Convert.ToString(objReader["author"]);
                articles.Tags           = Convert.ToString(objReader["tags"]);
                articles.LastUpdateDate = Convert.ToString(objReader["last_update_date"]);
                return(articles);
            }
            return(null);
        }
Example #13
0
 public void deleteArticle(ArticlesModels article)
 {
     mapper.Delete <ArticlesModels>("Where id = ?", article.id);
 }
Example #14
0
 public async Task addArticle(ArticlesModels article)
 {
     article.id = Guid.NewGuid();
     await mapper.InsertAsync(article);
 }