public ActionResult Index() { string str = ""; Random r = new Random(); DAL.BlogDAL blo = new BlogDAL(); DAL.CategoryDAL call = new CategoryDAL(); List <Model.Category> list_ca = call.GetList(""); for (int i = 0; i < 102; i++) { string title = $"新闻标题"; string body = title + "的内容"; Model.Category ca = list_ca[r.Next(0, list_ca.Count)]; string cabh = ca.Number, caname = ca.CaName; blo.Insert(new Model.Blog { Title = title, Body = body, VistitNum = r.Next(100, 9999), CaNumber = cabh, CaName = caname }); } str += "添加102条测试新闻成功!"; //str += "新增分类" + call.Insert(new Model.Blog {CaName="newCaName" })+ "<hr />"; //bool b = call.Delete(7); //str+= "删除Id-7的数据:" + b + "<hr />"; //Model.Category ca = call.GetModel(5); //if (ca!=null) //{ // ca.CaName = "新修改的名称" + DateTime.Now; // bool b2 = call.Update(ca); // str+="修改后的数据"+b2+ "<hr />"; //} return(Content(str)); }
public IActionResult Add(BlogModel blog) { CategoryModel model = CategoryDAL.GetCategoryByBh(blog.CBh); if (blog.Bid == 0) { if (model != null) { blog.CName = model.CName; blog.CBh = model.CBh; } blog.CreateDate = DateTime.Now; blog.Aid = 1; BlogDAL.Insert(blog); } else { if (model != null) { blog.CName = model.CName; blog.CBh = model.CBh; } BlogDAL.Update(blog); } return(Redirect("/Areas/Home/BlogList")); }
public IActionResult Add(Blog bo) { Category ca = cadal.GetModelByBh(bo.CaBh); if (ca != null) { bo.CaName = ca.CaName; } if (bo.Id == 0) { //新增 bodal.Insert(bo); } else { //修改 bodal.Update(bo); } return(Redirect("/Adnn1n/Blog/Index")); }