コード例 #1
0
        public IActionResult Index()
        {
            string      str     = "";
            Random      r       = new Random();
            BlogDal     blogdal = new BlogDal();
            CategoryDal cadal   = new CategoryDal();

            List <Model.Category> list_ca = cadal.GetList("");

            for (int i = 0; i < 102; i++)
            {
                string         title  = $"新闻标题{i}";
                string         body   = title + "的内容";
                Model.Category ca     = list_ca[r.Next(0, list_ca.Count)];
                string         cabh   = ca.Num,
                               caname = ca.CaName;

                blogdal.Insert(new Model.Blog
                {
                    Title    = title,
                    Body     = body,
                    VisitNum = r.Next(100, 999),
                    CaNum    = cabh,
                    CaName   = caname,
                });
            }
            str = "添加102条测试新闻成功!";

            return(Content(str));
        }
コード例 #2
0
        public IActionResult Add(Blog m)
        {
            Category ca = caDal.GetModelByNum(m.CaNum);

            if (ca != null)
            {
                m.CaName = ca.CaName;
            }

            if (m.Id == 0)
            {
                dal.Insert(m);
            }
            else
            {
                dal.Update(m);
            }
            return(Redirect("/Adnn1n/Blog/Index"));
        }