public IActionResult Add(Model.Blog m) { m.CreateDate = DateTime.Now; if (m.CaName == null) { m.CaName = "默认"; } Model.Category ca = cadal.GetModelByBh(m.CaBh); if (ca != null) { m.CaName = ca.CaName; } if (m.Id == 0) { //新增 dal.Insert(m); } else { //修改 dal.Update(m); } return(Redirect("/Adnn1n/Blog/Index")); }
public IActionResult Add(Model.Blog m) { Model.Category ca = cadal.GetModelByBh(m.CaBh); if (ca != null) { m.CaName = ca.CaName; } if (m.Id == 0) { dal.Insert(m); } else { m.updatetime = DateTime.Now; dal.Update(m); } return(Redirect("/Admin/Blog/Index")); }
public IActionResult Add(Model.Blog m) { Model.Category ca = cadal.GetModelByNumber(m.CategoryNum); if (ca != null) { m.CategoryName = ca.CategoryName; } if (m.Id == 0) { //新增 dal.Insert(m); } else { //修改 dal.Update(m); } return(Redirect("/Admin/Blog/Index")); }
public IActionResult Index() { string str = ""; Random r = new Random(); List <Model.Category> list = cadal.GetList(""); for (int i = 0; i < 100; i++) { Model.Category ca = list[r.Next(0, list.Count)]; Model.Blog m = new Model.Blog { Title = $"第{i}条数据", Body = $"第{i}条数据的内容", CaBh = ca.Bh, CaName = ca.CaName, VisitNum = r.Next(100, 999) }; bdal.Insert(m); } str = "添加100条数据成功"; //str = "新增返回的值" + cadal.Insert(new Model.Category() { CaName="789"}) + "<hr />"; //bool b = cadal.Delete(7); //str += "删除ID=7的数据" + b + "<hr />"; //Model.Category ca = cadal.GetModel(8); //if(ca!=null) //{ // ca.CaName = "新修改的名字" + DateTime.Now; // bool b2 = cadal.Update(ca); // str += "修改ID=8的实体类结果" + b2 + "<hr />"; //} //List<Model.Category> list = cadal.GetList(""); //foreach (var item in list) //{ // str += $"<div>分类ID:{item.Id},分类名称:{item.CaName}</div>"; //} return(Content(str)); }
public IActionResult Index() { string str = ""; Random rd = new Random(); DAL.CategoryDAL cadal = new DAL.CategoryDAL(); DAL.BlogDAL bdal = new DAL.BlogDAL(); var calist = cadal.GetList(""); for (int i = 0; i < 100; i++) { string title = $"英雄联盟比赛{i}"; string body = title + "的内容"; Model.Category m = calist[rd.Next(0, calist.Count())]; string number = m.Number; string categoryName = m.CategoryName; bdal.Insert(new Model.Blog() { Title = title, Body = body, CategoryName = categoryName, CategoryNum = number }); } str = "添加100条数据"; //str += "新增的insert方法返回的值" + cadal.Insert(new Model.Category { CategoryName = "newca"}) + "<hr/>"; //str += "删除ID=11的数据值"+ cadal.Delete(11) + "<hr/>"; //Model.Category ca = cadal.GetModel(10); //if (ca != null) { // ca.CategoryName = "asadad"; // str += "更新ID=10的数据值" + cadal.Update(ca) + "<hr/>"; //} //List<Model.Category> list = cadal.GetList(""); //foreach(var item in list){ // str += $"<div>分类ID:{item.Id},分类名称:{item.CategoryName}</div>"; //} return(Content(str)); }
public IActionResult Add(Model.Blog blog) { blog.CreateDate = DateTime.Now; if (blog.CateNo == "0") { //新分类,先增加 string cateNo = catedal.GetCateNo("0", 2); catedal.Insert(new Model.Category() { CateName = blog.CateName, CateNo = cateNo, CreateDate = DateTime.Now, ParentCate = "0", Remark = "" }); blog.CateNo = cateNo; } if (blog.Id == 0) { blogdal.Insert(blog); return(Json(new { status = "y", info = "博客新增成功!" })); } else { blogdal.Update(blog); return(Json(new { status = "y", info = "博客编辑成功!" })); } }