public ActionResult Delete(string id) { var result = VideoDao.Delete(id); if (result == 1) { return(Ok()); } return(BadRequest()); }
protected void ShowVideoImage() { VideoDao dao = Factory.Get(new VideoDao()); List <VideoModel> list = (List <VideoModel>)dao.GetBy("where user_id='" + (Session["user"] as UserModel).id + "'"); foreach (VideoModel model in list) { System.Windows.Forms.ListViewItem item1 = new System.Windows.Forms.ListViewItem(); //之前是直接用Images.FromFile(string Path)从文件夹中读取,删除时没法删除 //改从文件流中读取图片,关闭窗口时可以删除文件 string image_path = "VideoIcon/" + model.video_id.Split('.')[0] + ".jpg"; ImageButton button = new ImageButton(); button.Height = 100; button.Width = 160; button.ImageUrl = image_path; Label label = new Label(); button.Click += (object sender, ImageClickEventArgs e) => { if (model.iscansee) { Session["video"] = model; Response.Redirect("VideoPage.aspx"); } else { Server.Transfer("ErrorPage.aspx"); } }; Label title = new Label(); Button delete_button = new Button(); delete_button.Text = "删除"; delete_button.CssClass = "del_btn"; delete_button.Click += (object sender, EventArgs e) => { VideoDao video_dao = Factory.Get(new VideoDao()); video_dao.Delete(model); File.Delete(Server.MapPath("~/Video/") + model.video_id); File.Delete(Server.MapPath("~/VideoIcon/") + model.video_id.Split('.')[0] + ".jpg"); Server.Transfer("VideoUpLoadPage.aspx"); }; if (model.iscansee) { label.Text = "审核已通过"; } else { label.Text = "正在审核..."; } title.Text = model.title; label.Font.Bold = true; title.Font.Size = 15; label.Font.Size = 20; if (Table1.Rows.Count == 0) { _last_row = new TableRow(); Table1.Rows.Add(_last_row); } if (_last_row.Cells.Count < 2) { TableCell cell = new TableCell(); cell.Controls.Add(button); TableCell cell3 = new TableCell(); cell3.Controls.Add(title); TableCell cell1 = new TableCell(); cell1.Controls.Add(label); TableCell cell2 = new TableCell(); cell2.Controls.Add(delete_button); _last_row.Cells.Add(cell); _last_row.Cells.Add(cell3); _last_row.Cells.Add(cell1); _last_row.Cells.Add(cell2); cell.HorizontalAlign = HorizontalAlign.Center; cell2.HorizontalAlign = HorizontalAlign.Center; } else { _last_row = new TableRow(); TableCell cell = new TableCell(); TableCell cell1 = new TableCell(); TableCell cell2 = new TableCell(); cell1.Controls.Add(label); cell2.Controls.Add(delete_button); TableCell cell3 = new TableCell(); cell3.Controls.Add(title); cell.Controls.Add(button); _last_row.Cells.Add(cell); _last_row.Cells.Add(cell3); _last_row.Cells.Add(cell1); _last_row.Cells.Add(cell2); Table1.Rows.Add(_last_row); cell.HorizontalAlign = HorizontalAlign.Center; cell2.HorizontalAlign = HorizontalAlign.Center; } } }
protected void ShowVideoImage() { VideoDao dao = Factory.Get(new VideoDao()); List <VideoModel> list = (List <VideoModel>)dao.GetAll(); foreach (VideoModel model in list) { System.Windows.Forms.ListViewItem item1 = new System.Windows.Forms.ListViewItem(); //之前是直接用Images.FromFile(string Path)从文件夹中读取,删除时没法删除 //改从文件流中读取图片,关闭窗口时可以删除文件 string image_path = "VideoIcon/" + model.video_id.Split('.')[0] + ".jpg"; ImageButton button = new ImageButton(); button.Height = 100; button.Width = 160; button.ImageUrl = image_path; Label title_user = new Label(); button.Click += (object sender, ImageClickEventArgs e) => { Session["video"] = model; Response.Redirect("VideoPage.aspx"); }; Label label = new Label(); Button see_button = new Button(); title_user.Text = model.title + "<br>上传者:" + model.user_id; Button delete_button = new Button(); delete_button.Text = "删除"; delete_button.Click += (object sender, EventArgs e) => { VideoDao video_dao = Factory.Get(new VideoDao()); video_dao.Delete(model); File.Delete(Server.MapPath("~/Video/") + model.video_id); File.Delete(Server.MapPath("~/VideoIcon/") + model.video_id.Split('.')[0] + ".jpg"); Server.Transfer("ManagerPage.aspx"); }; if (model.iscansee) { label.Text = "审核已通过"; see_button.Text = "已审核"; see_button.Enabled = false; } else { label.Text = "未审核"; see_button.Text = "审核"; } see_button.Click += (object sender, EventArgs e) => { model.iscansee = true; VideoDao video_dao = Factory.Get(new VideoDao()); video_dao.Update(model); label.Text = "审核已通过"; see_button.Text = "已审核"; see_button.Enabled = false; }; see_button.Height = 50; see_button.Width = 80; delete_button.Height = 50; delete_button.Width = 80; label.Font.Bold = true; label.Font.Size = 20; if (Table1.Rows.Count == 0) { _last_row = new TableRow(); Table1.Rows.Add(_last_row); } if (_last_row.Cells.Count < 2) { TableCell cell = new TableCell(); cell.Controls.Add(button); TableCell cell4 = new TableCell(); cell4.Controls.Add(title_user); TableCell cell1 = new TableCell(); cell1.Controls.Add(label); TableCell cell2 = new TableCell(); cell1.Controls.Add(label); cell2.Controls.Add(see_button); cell2.Controls.Add(delete_button); _last_row.Cells.Add(cell); _last_row.Cells.Add(cell4); _last_row.Cells.Add(cell1); _last_row.Cells.Add(cell2); cell1.HorizontalAlign = HorizontalAlign.Center; cell.HorizontalAlign = HorizontalAlign.Center; cell2.HorizontalAlign = HorizontalAlign.Center; } else { _last_row = new TableRow(); TableCell cell = new TableCell(); TableCell cell1 = new TableCell(); TableCell cell2 = new TableCell(); cell1.Controls.Add(label); TableCell cell4 = new TableCell(); cell4.Controls.Add(title_user); cell2.Controls.Add(see_button); cell2.Controls.Add(delete_button); cell.Controls.Add(button); _last_row.Cells.Add(cell); _last_row.Cells.Add(cell4); _last_row.Cells.Add(cell1); _last_row.Cells.Add(cell2); Table1.Rows.Add(_last_row); cell1.HorizontalAlign = HorizontalAlign.Center; cell.HorizontalAlign = HorizontalAlign.Center; cell2.HorizontalAlign = HorizontalAlign.Center; } } }