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)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => false; options.MinimumSameSitePolicy = SameSiteMode.None; }); string ConnString = Configuration.GetConnectionString("DefaultConnectionString"); string UserConnString = Configuration.GetConnectionString("UserDB"); AdminDAL adminDAL = new AdminDAL(ConnString); services.AddSingleton <AdminDAL>(adminDAL); BlogDAL blogDAL = new BlogDAL(ConnString); services.AddSingleton <BlogDAL>(blogDAL); UserDAL userDAL = new UserDAL(UserConnString); services.AddSingleton <UserDAL>(userDAL); CategoryDAL categoryDAL = new CategoryDAL(ConnString); services.AddSingleton <CategoryDAL>(categoryDAL); services.AddSession(); //services.AddSingleton<BlogDbConnection>(); //services.AddSingleton<ConnectionFactory>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public HomeController(CategoryDAL categoryDal, BlogDAL blogDal, IHostingEnvironment hostingEnvironment, AdminDAL adminDAL) { _CategoryDAL = categoryDal; _BlogDAL = blogDal; _AdminDAL = adminDAL; hostingEnv = hostingEnvironment; }
public HomeController(IHostingEnvironment env, AdminDAL adminDAL, BlogDAL blogDAL, CategoryDAL categoryDAL) { this.hostingEvn = env; AdminDAL = adminDAL; BlogDAL = blogDAL; CategoryDAL = categoryDAL; }
public static void Main(string[] args) { BuildWebHost(args).Run(); BlogDAL bDal = new BlogDAL(); bDal.queryBlog(); bDal.saveBlog(); }
public ActionResult AddBlogNewUser(BlogDAL.Entities.Blog blog) { if (!string.IsNullOrEmpty(blog.Document) && !string.IsNullOrEmpty(blog.Tag) && (blog.Tag.Length < 10)) { bool check = myDal.AddDocument(blog, User.Identity.Name.Replace(" ", "")); return RedirectToAction("Blog/" + User.Identity.Name.Replace(" ",""), "Home"); } ViewBag.Error = "Не все данные были введены некорректно, проверьте заполнение всех полей."; return View(blog); }
/// <summary> /// 点击录入按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button2_Click(object sender, EventArgs e) { Blog model = new Blog(); model.name = textBox1.Text; model.author = textBox2.Text; model.date = dateTimePicker1.Text; //XX年XX月XX日 BlogDAL.Add(model); ShowDataGird(); }
public ActionResult AddNewComment(BlogDAL.Entities.Comment comment) { if (!string.IsNullOrEmpty(comment.CommentText)) { comment.BlogID = int.Parse(RouteData.Values["id"].ToString()); bool check = myDal.AddComment(comment, User.Identity.Name.Replace(" ", "")); return RedirectToAction("Comment/" + comment.BlogID, "Home"); } ViewBag.Error = "Не все данные были введены корректно, проверьте заполнение всех полей."; return View(comment); }
/// <summary> /// 点击删除按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("请填写要删除的ID"); return; } Blog model = new Blog(); model.Id = Convert.ToInt32(textBox1.Text); BlogDAL.Drop(model, "id"); ShowDataGird(); }
public ActionResult Registration(BlogDAL.Entities.User myNewUser) { if (myDal.CheckAddUser(myNewUser.Login) && !string.IsNullOrEmpty(myNewUser.Login) && (myNewUser.Login.Length < 10) && !string.IsNullOrEmpty(myNewUser.Password) && (myNewUser.Password.Length < 10)) { myDal.AddUser(myNewUser); ViewBag.RegistrationUser = "******"; return RedirectToAction("Index", "Home"); } ViewBag.Error = "Такой пользователь уже существует или данные были введены некорректно, проверьте заполнение всех полей."; return View(myNewUser); }
/// <summary> /// 显示数据网格控件 /// </summary> public void ShowDataGird() { this.dataGridView1.DataSource = null; this.dataGridView1.Columns.Clear(); List <Blog> list = BlogDAL.FindList(null); dataGridView1.DataSource = list; dataGridView1.Columns["name"].HeaderText = "博客名"; dataGridView1.Columns["author"].HeaderText = "作者"; dataGridView1.Columns["date"].HeaderText = "上传日期"; }
/// <summary> /// 按作者查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button1_Click(object sender, EventArgs e) { Blog model = new Blog(); model.author = textBox1.Text; this.dataGridView1.DataSource = null; //清理数据网格 this.dataGridView1.Columns.Clear(); //清理数据网格 List <Blog> list = BlogDAL.FindList(model, "author"); dataGridView1.DataSource = list; dataGridView1.Columns["name"].HeaderText = "博客名"; dataGridView1.Columns["author"].HeaderText = "作者"; dataGridView1.Columns["date"].HeaderText = "上传日期"; }
/// <summary> /// 点击数据网格 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "colBtn_alter") { Blog model = new Blog(); model.Id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); model.name = dataGridView1.Rows[e.RowIndex].Cells["name"].Value.ToString(); model.author = dataGridView1.Rows[e.RowIndex].Cells["author"].Value.ToString(); model.date = dataGridView1.Rows[e.RowIndex].Cells["date"].Value.ToString(); if (BlogDAL.AlterByPK(model, "Id")) { ShowDataGird(); MessageBox.Show("修改成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddMvc(); string ConnStr = Configuration.GetSection("ConnStr").Value; AdminDAL admin = new AdminDAL(ConnStr); services.AddSingleton <AdminDAL>(admin); BlogDAL blog = new BlogDAL(ConnStr); services.AddSingleton <BlogDAL>(blog); CategoryDAL category = new CategoryDAL(ConnStr); services.AddSingleton <CategoryDAL>(category); services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2); services.AddSession(); services.AddDistributedMemoryCache(); }
/// <summary> /// 显示数据网格控件 /// </summary> public void ShowDataGird() { this.dataGridView1.DataSource = null; this.dataGridView1.Columns.Clear(); List <Blog> list = BlogDAL.FindList(null); dataGridView1.DataSource = list; dataGridView1.Columns["name"].HeaderText = "博客名"; dataGridView1.Columns["author"].HeaderText = "作者"; dataGridView1.Columns["date"].HeaderText = "上传日期"; dataGridView1.Columns["id"].ReadOnly = true; //id列设为不可编辑 //加一列按钮 DataGridViewButtonColumn col_Btn_alter = new DataGridViewButtonColumn(); col_Btn_alter.Name = "colBtn_alter"; col_Btn_alter.HeaderText = ""; col_Btn_alter.DefaultCellStyle.NullValue = "修改"; dataGridView1.Columns.Add(col_Btn_alter); }
public BlogBLL(BlogDAL blog, PostDAL post) { _blog = blog; _post = post; }
/// <summary> /// 注入传递 /// </summary> /// <param name="bdal"></param> public BlogController(BlogDAL bdal, BlogCommentDAL bcdal) { this.blogDAL = bdal; this.blogCommentDAL = bcdal; }
protected void GetBlogObjects(string strBlogId) { blogDal = new BlogDAL(); blog = blogDal.LoadBlogData(strBlogId); }
public HomeController(AdminDAL adminDAL, CategoryDAL categoryDAL, BlogDAL blogDAL) { _AdminDAL = adminDAL; _CATEGORYDAL = categoryDAL; _BlogDAL = blogDAL; }
public HomeController(BlogDAL blogDAL) { BlogDAL = blogDAL; }
public ActionResult FindByTag(BlogDAL.Entities.Blog blog) { if (!string.IsNullOrEmpty(blog.Tag) && (blog.Tag.Length < 10)) { return View("ShowBlogsByTag", myDal.GetBlogByTag(blog.Tag)); } ViewBag.Error = "Данные были введены некорректно, проверьте заполнение всех полей."; return View(); }