开发时间:2021-10-4~2021-10-20
开发工具:Visual Studio 2019 SQL Server2019 VS Code
使用技术: MVC开发模式 EnitityFramework ASP.NET WEB
研究目标与内容:
目标:随着影视娱乐业的发展越来越强大,现在越来越多的人都喜欢网上追剧,奈何苦于广告的烦恼,需要充值会员才可跳过广告,此网站可完美解决此问题,杜绝广告从我做起,且无会员也可急速上传视频资源,工作人员快速审核,只为以最高的效率将此共享给更多的客户。
内容:
一、1.首页功能:最近热映、分类信息展示、用户注册与登录
2.分类展示:展示剧集信息、展示播放信息
3.播放界面:视频播放、剧集选集、热门推荐
4.视频上传:视频上传、信息提交、查看数据
5.最近播放:播放记录展示、收藏夹、我的关注
二、1.后台管理:视频审核,类型管理,管理员设置、退出后台
2.剧集管理:上传剧集、审核剧集、下架剧集
3.用户管理:创建用户、设置信息、设置账号状态
初步分析:
客户界面
管理员界面
数据库设计:
EnitityFramework设计器
造数据:
可以使用 包含视图的MVC5控制器 添加测试数据
/添加数据添加到吐
创建用户数据
public ActionResult Create([Bind(Include = "UserID,UserName,UserPhone,UserQQ,UserPwd,UserPic")] User user, HttpPostedFileBase HeadPic)
{
if (ModelState.IsValid)
{
//生成guid当主键
user.UserID = Guid.NewGuid().ToString();
//测试数据就不判断了 直接保存图片
string PicName = Guid.NewGuid().ToString() + HeadPic.FileName.Substring(HeadPic.FileName.LastIndexOf('.'));
HeadPic.SaveAs(Server.MapPath("~/images/UserPic/" + PicName));
//设置存储的照片名称
user.UserPic = PicName;
db.User.Add(user);
db.SaveChanges();
//创建完账户 默认创建个人信息
UserInfo userInfo = new UserInfo();
userInfo.InfoID = Guid.NewGuid().ToString();
userInfo.UserID = user.UserID;
userInfo.InfoTime = DateTime.Now;
userInfo.InfoDesc = userInfo.InfoDesc ?? "这个人很懒什么也没有留下";
db.UserInfo.Add(userInfo);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(user);
}
创建视频数据
public ActionResult Create([Bind(Include = "DramaID,DramaName,DramaType,UserID,UpTime,Dramadesc,DramaPic,DramaIsmove,DramaSetNum,VideoUrl,DramaSearch,DramaPlayCount")] Drama drama, HttpPostedFileBase HeadPic, HttpPostedFileBase HeadVideo)
{
if (ModelState.IsValid)
{
//设置主键
drama.DramaID = Guid.NewGuid().ToString();
//设置上传时间
drama.UpTime = DateTime.Now;
//设置默认简介
drama.Dramadesc = drama.Dramadesc ?? "作者很懒什么也没有留下";
//存图片
string PicName = Guid.NewGuid().ToString() + HeadPic.FileName.Substring(HeadPic.FileName.LastIndexOf('.'));
HeadPic.SaveAs(Server.MapPath("~/images/DramaImg/" + PicName));
drama.DramaPic = PicName;
//判断是不是电影
if (drama.DramaType == "6b0416bf-340a-498e-b4c7-dd6ee8738987")
{
//修改类型为电影(1)
drama.DramaIsmove = 1;
//设置集数为1
drama.DramaSetNum = 1;
//存视频
string MovieName = Guid.NewGuid().ToString() + HeadVideo.FileName.Substring(HeadVideo.FileName.LastIndexOf('.'));
HeadVideo.SaveAs(Server.MapPath("~/Movies/" + MovieName));
drama.VideoUrl = MovieName;
}
else
{
//设置为非电影
drama.DramaIsmove = 0;
//判断集数为空设置为1
drama.DramaSetNum = drama.DramaSetNum ?? 1;
}
//设置搜索记录为0 播放记录为0
drama.DramaSearch = 0;
drama.DramaPlayCount = 0;
db.Drama.Add(drama);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.DramaType = new SelectList(db.ClassIfication, "ClassID", "ClassName", drama.DramaType);
ViewBag.UserID = new SelectList(db.User, "UserID", "UserName", drama.UserID);
return View(drama);
}
奋斗一小时 刚搞到这些数据
创建数据时注意 [ValidateAntiForgeryToken] 添加有时会报错
所需的防伪 Cookie“__RequestVerificationToken”不存在。
解决办法将此验证去除 嘿嘿
页面制作:
登录页面:
功能分析:时间展示 非空判断 验证码生成与判断 错误提示
第二天 哈哈我熬过去了
今天又添加了很多数据 剧集信息 剧集上传 太烦躁了/哭了/
做了一个模板页 不过很难看 寻求一位写前端的兄弟
using (BoomDBEntities db = new BoomDBEntities())
{
ViewData["shouyedatu"] = (from n in db.Drama select n).Take(1).ToList();
ViewData["youcezhanshi"] = (from n in db.Drama select n).Take(6).ToList();
ViewData["resouzhanshi"] = (from n in db.Drama select n).Take(8).ToList();
ViewData["ClassIfication"] = (from n in db.ClassIfication select n).ToList();
}
return View();
这个页面完成了正在热播 分类管理 右侧列表的展示等功能
public ActionResult ShowClass(string SelectType, string ClassID)
{
using (BoomDBEntities db = new BoomDBEntities())
{
string sql = "";
if (SelectType != null)
{
sql = "select d.DramaID,d.DramaName,d.DramaType,d.UpTime,d.Dramadesc,d.DramaPic,d.DramaSearch,d.DramaSetNum,u.UserName,u.UserPic,u.UserID from Drama d, [User] u where d.UserID = u.UserID and d.DramaName like '%" + SelectType + "%'";
}
else
{
sql = "select d.DramaID,d.DramaName,d.DramaType,d.UpTime,d.Dramadesc,d.DramaPic,d.DramaSearch,d.DramaSetNum,u.UserName,u.UserPic,u.UserID from Drama d, [User] u where d.UserID = u.UserID and d.DramaType = '" + ClassID + "'";
}
var aa = db.Database.SqlQuery<ShowDramainfo>(sql);
List<ShowDramainfo> temp = new List<ShowDramainfo>();
foreach (var item in aa)
{
temp.Add(item);
}
ViewData["ShowDrama"] = temp;
}
return View();
}
搜索的代码 主要是查库
这个页面完成了简单的搜索功能 按照分类展示等功能
//~/Home/VideoShow?DramaID=剧id&VideoID=当前剧某集id&VideoUrl=播放地址
public ActionResult VideoShow()
{
ShowClassIfication();
string dramaID = (Request["DramaID"] ?? "").Trim();
string videoID = (Request["VideoID"] ?? "").Trim();
string VideoUrl = (Request["VideoUrl"] ?? "").Trim();
ViewData["VideoUrl"] = ""; //视频地址
//查询视频地址
using (BoomDBEntities db = new BoomDBEntities())
{
ViewData["videoUrl"] = "";
//传入剧集id但不传入某集id 先判断是不是电影 是电影返回视频地址 如果不是电影 默认播放第一集
//判断是不是电影
string sql = "select d.VideoUrl,d.DramaID,d.DramaName,d.DramaType,d.UpTime,d.Dramadesc,d.DramaPic,d.DramaIsmove,d.DramaSetNum,d.DramaSearch,d.DramaSetNum,u.UserName,u.UserPic,u.UserID from Drama d, [User] u where d.UserID = u.UserID and d.DramaID = '" + dramaID + "'";
var bb = db.Database.SqlQuery<ShowDramainfo>(sql).ToList<ShowDramainfo>()[0];
sql = "update Drama set DramaPlayCount+=1 where DramaID = '" + dramaID + "'";
int exe = db.Database.ExecuteSqlCommand(sql);
ViewData["ShowDramainfo"] = bb;
if (bb.DramaIsmove == 1)
{
//是电影的话直接传值
ViewData["videoUrl"] = bb.VideoUrl;
}
else
{
if (VideoUrl == "")
{
//判断不是电影 查询当前电视剧第一集
var temp = (from aa in db.VideoManagement where aa.DramaID == dramaID select aa).Count();
//判断当前电视剧无资源
if (temp == 0)
{
return View();
}
if (videoID != "")
{
ViewData["videoUrl"] = (from aa in db.VideoManagement where aa.VideoID == videoID select aa).FirstOrDefault().VideoUrl;
}
else
{
ViewData["videoUrl"] = (from aa in db.VideoManagement where aa.DramaID == dramaID && aa.VideoIndex == 1 select aa).FirstOrDefault().VideoUrl;
}
}
else
{
ViewData["videoUrl"] = VideoUrl;
}
//判断不为电影后 查询此剧全部信息 选集框
ViewData["video"] = (from aa in db.VideoManagement where aa.DramaID == dramaID orderby aa.VideoIndex select aa).ToList();
}
//判断是否登录
if (Signin.IsLogin())
{
string userid = Session["UserID"].ToString();
//存储播放记录
PlayBack playBack = (from aa in db.PlayBack where aa.UserID == userid && aa.DramaID == dramaID select aa).FirstOrDefault();
if (playBack == null)
{
playBack = new PlayBack();
playBack.PlayBackID = Guid.NewGuid().ToString();
playBack.DramaID = dramaID;
playBack.UserID = userid;
playBack.VideoUrl = ViewData["videoUrl"].ToString();
playBack.ShowTime = DateTime.Now;
db.PlayBack.Add(playBack);
db.SaveChanges();
}
else
{
playBack.VideoUrl = ViewData["videoUrl"].ToString();
playBack.ShowTime = DateTime.Now;
db.SaveChanges();
}
}
}
ViewData["DramaID"] = dramaID; //右侧选集
return View();
}
播放界面完成了 视频播放 选集功能 剧集信息介绍 等功能
个人主页
个人主页
功能 信息展示 修改信息 历史记录 剧集上传
using BoomVideo.App_Start;
using BoomVideo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace BoomVideo.Controllers
{
public class MyUserController : Controller
{
// GET: MyUser
/// <summary>
/// 个人信息首页
/// </summary>
/// <returns></returns>
public ActionResult Index()
{
if (Signin.IsLogin())
{
using (BoomDBEntities db = new BoomDBEntities())
{
// Session["UserID"] = a.UserID;
// Session["UserName"] = a.UserName;
// Session["UserPic"] = a.UserPic;
//ViewData["UserVal"]
//ViewData["UserInfoVal"]
var Id = Session["UserID"].ToString();
ViewData["UserInfoVal"] = (from a in db.UserInfo where a.UserID == Id select a).FirstOrDefault();
return View();
}
}
else
{
return RedirectToAction("Index", "Signin");
}
}
//修改密码
public ActionResult UpdatePwd()
{
if (Signin.IsLogin())
{
if (Request.Form.Count > 0)
{
string Id = Session["UserID"].ToString();
string OldPwd = Request["OldPwd"];
string NewPwd = Request["NewPwd"];
if (Signin.Verifypassword(NewPwd))
{
using (BoomDBEntities db = new BoomDBEntities())
{
var Temp = db.User.Find(Id);
if (Temp.UserPwd == OldPwd)
{
Temp.UserPwd = NewPwd;
db.SaveChanges();
//执行成功跳转到退出登录方法
return RedirectToAction("Logout", "Signin");
}
else
{
ViewData["message"] = "旧密码不正确 请重新尝试";
return View();
}
}
}
else
{
ViewData["message"] = "密码不符合规则";
return View();
}
}
else
{
return View();
}
}
else
{
return RedirectToAction("Index", "Signin");
}
}
//修改用户
public ActionResult UpdateUser(string UserName, string Infosex, string InfoAge, string sheng, string shi, string xian, string InfoDesc, HttpPostedFileBase HeadPic)
{
if (Signin.IsLogin())
{
if (Request.Form.Count > 0)
{
string[] fileTypeStr = { "image/png", "image/png", "image/pjpeg", "image/jpeg", "image/bmp" };
if (UserName == "" || InfoAge == "" || sheng == "1" || shi == "2" || xian == "3" || (HeadPic != null && HeadPic.ContentLength != 0 && !fileTypeStr.Contains(HeadPic.ContentType)))
{
if (UserName == "")
{
ViewData["UserNamemess"] = "姓名不能为空";
}
if (InfoAge == "")
{
ViewData["InfoAgemess"] = "年龄不能为空";
}
else if (int.Parse(InfoAge) < 0)
{
ViewData["InfoAgemess"] = "年龄不能为负数";
}
if (sheng == "1")
{
ViewData["shengmess"] = "省份不能为空";
}
if (shi == "2")
{
ViewData["shimess"] = "市不能为空";
}
if (xian == "3")
{
ViewData["xianmess"] = "县不能为空";
}
if (HeadPic != null && HeadPic.ContentLength != 0)
{
if (!fileTypeStr.Contains(HeadPic.ContentType))
{
ViewData["HeadPicmess"] = "请上传正确图片";
}
}
using (BoomDBEntities db = new BoomDBEntities())
{
var Id = Session["UserID"].ToString();
ViewData["UserInfoVal"] = (from a in db.UserInfo where a.UserID == Id select a).FirstOrDefault();
return View();
}
}
else
{
using (BoomDBEntities db = new BoomDBEntities())
{
var Id = Session["UserID"].ToString();
var temp = db.User.Find(Id);
temp.UserName = UserName;
if (HeadPic != null && HeadPic.ContentLength != 0)
{
string PicName = Guid.NewGuid().ToString() + HeadPic.FileName.Substring(HeadPic.FileName.LastIndexOf('.'));
HeadPic.SaveAs(Server.MapPath("~/images/UserPic/" + PicName));
temp.UserPic = PicName;
}
db.SaveChanges();
Session["UserName"] = temp.UserName;
Session["UserPic"] = temp.UserPic;
var temp1 = (from a in db.UserInfo where a.UserID == Id select a).FirstOrDefault();
temp1.Infosex = int.Parse(Infosex);
temp1.InfoAge = int.Parse(InfoAge);
temp1.InfoAddress = sheng + "-" + shi + "-" + xian;
temp1.InfoDesc = InfoDesc;
db.SaveChanges();
return RedirectToAction("Index", "MyUser");
}
}
}
else
{
using (BoomDBEntities db = new BoomDBEntities())
{
var Id = Session["UserID"].ToString();
ViewData["UserInfoVal"] = (from a in db.UserInfo where a.UserID == Id select a).FirstOrDefault();
return View();
}
}
}
else
{
return RedirectToAction("Index", "Signin");
}
}
/// <summary>
/// 播放历史
/// </summary>
/// <returns></returns>
public ActionResult OldShow()
{
if (Signin.IsLogin())
{
using (BoomDBEntities db = new BoomDBEntities())
{
string sql = "select p.VideoUrl,p.ShowTime,d.DramaID,d.DramaName,d.DramaPic,d.Dramadesc,d.DramaIsmove,d.DramaSetNum,u.UserName,u.UserPic,u.UserID from PlayBack p,Drama d,[User] u where p.DramaID = d.DramaID and u.UserID = d.UserID and p.UserID = '" + Session["UserID"] + "' order by p.ShowTime desc";
var aa = db.Database.SqlQuery<lishijilu>(sql);
List<lishijilu> temp = new List<lishijilu>();
foreach (var item in aa)
{
temp.Add(item);
}
ViewData["ShowDrama"] = temp;
return View();
}
}
else
{
return RedirectToAction("Index", "Signin");
}
}
/// <summary>
/// 上传视频
/// </summary>
/// <returns></returns>
public ActionResult UpMovies()
{
if (Signin.IsLogin())
{
using (BoomDBEntities db = new BoomDBEntities())
{
string id = Session["UserID"].ToString();
string sql = "select d.DramaID,d.DramaName,d.DramaType,d.UpTime,d.Dramadesc,d.DramaPic,d.DramaIsmove,d.DramaSetNum,d.DramaSearch,d.DramaSetNum,u.UserName,u.UserPic,u.UserID from Drama d, [User] u where d.UserID = u.UserID and d.UserID = '" + id + "' order by d.UpTime";
var aa = db.Database.SqlQuery<ShowDramainfo>(sql);
List<ShowDramainfo> temp = new List<ShowDramainfo>();
foreach (var item in aa)
{
temp.Add(item);
}
ViewData["ShowDrama"] = temp;
}
return View();
}
else
{
return RedirectToAction("Index", "Signin");
}
}
/// <summary>
/// 添加剧集信息
/// </summary>
/// <returns></returns>
public ActionResult InsDram()
{
if (Signin.IsLogin())
{
using (BoomDBEntities db = new BoomDBEntities())
{
ViewData["DramaType"] = db.ClassIfication.ToList();
}
return View();
}
else
{
return RedirectToAction("Index", "Signin");
}
}
[HttpPost]
public ActionResult InsDram([Bind(Include = "DramaID,DramaName,DramaType,UserID,UpTime,Dramadesc,DramaPic,DramaIsmove,DramaSetNum,VideoUrl,DramaSearch,DramaPlayCount")] Drama drama, HttpPostedFileBase HeadPic, HttpPostedFileBase HeadVideo)
{
if (Signin.IsLogin())
{
if (drama.DramaName != null && HeadPic != null)
{
//设置主键
drama.DramaID = Guid.NewGuid().ToString();
//设置上传时间
drama.UpTime = DateTime.Now;
//设置默认简介
drama.Dramadesc = drama.Dramadesc ?? "作者很懒什么也没有留下";
//存图片
string PicName = Guid.NewGuid().ToString() + HeadPic.FileName.Substring(HeadPic.FileName.LastIndexOf('.'));
HeadPic.SaveAs(Server.MapPath("~/images/DramaImg/" + PicName));
drama.DramaPic = PicName;
//判断是不是电影
if (drama.DramaType == "6b0416bf-340a-498e-b4c7-dd6ee8738987")
{
if (HeadVideo != null)
{
//修改类型为电影(1)
drama.DramaIsmove = 1;
//设置集数为1
drama.DramaSetNum = 1;
//存视频
string MovieName = Guid.NewGuid().ToString() + HeadVideo.FileName.Substring(HeadVideo.FileName.LastIndexOf('.'));
HeadVideo.SaveAs(Server.MapPath("~/Movies/" + MovieName));
drama.VideoUrl = MovieName;
}
else
{
//电影类型未上传电影 返回
TempData["message"] = "电影类型需上传视频";
return RedirectToAction("InsDram");
}
}
else
{
//设置为非电影
drama.DramaIsmove = 0;
//判断集数为空设置为1
drama.DramaSetNum = drama.DramaSetNum ?? 1;
}
//设置上传作者
drama.UserID = Session["UserID"].ToString();
//设置搜索记录为0 播放记录为0
drama.DramaSearch = 0;
drama.DramaPlayCount = 0;
using (BoomDBEntities db = new BoomDBEntities())
{
db.Drama.Add(drama);
db.SaveChanges();
}
return RedirectToAction("UpMovies");
}
else
{
if (drama.DramaName == null)
{
TempData["message"] = "剧集名称不能为空";
}
if (HeadPic == null)
{
TempData["message"] += "<br/> 剧集图片不能为空";
}
return RedirectToAction("InsDram");
}
}
else
{
return RedirectToAction("Index", "Signin");
}
}
/// <summary>
/// 剧集信息展示并展示电视剧每集信息
/// </summary>
/// <returns></returns>
public ActionResult DramaInfo()
{
if (Signin.IsLogin())
{
string Dramaid = Request["Id"];
using (BoomDBEntities db = new BoomDBEntities())
{
var Dramatemp = db.Drama.Find(Dramaid);
ViewData["drama"] = Dramatemp;
if (Dramatemp.DramaIsmove != 1)
{
ViewData["Videos"] = (from a in db.VideoManagement where a.DramaID == Dramaid orderby a.VideoIndex select a).ToList();
}
}
return View();
}
else
{
return RedirectToAction("Index", "Signin");
}
}
/// <summary>
/// 添加电视剧的每一集
/// </summary>
/// <returns></returns>
public ActionResult InsVideo()
{
if (Signin.IsLogin())
{
string Dramaid = Request["Id"];
using (BoomDBEntities db = new BoomDBEntities())
{
var temp = db.Drama.Find(Dramaid);
ViewData["dramaTemp"] = temp;
TempData["dramaId"] = temp.DramaID;
}
return View();
}
else
{
return RedirectToAction("Index", "Signin");
}
}
[HttpPost]
public ActionResult InsVideo([Bind(Include = "VideoID,DramaID,Videopic,Videodesc,VideoUrl")] VideoManagement videoManagement, HttpPostedFileBase HeadPic, HttpPostedFileBase HeadVideo)
{
if (Signin.IsLogin())
{
if (HeadVideo != null)
{
using (BoomDBEntities db = new BoomDBEntities())
{
//设置主键
videoManagement.VideoID = Guid.NewGuid().ToString();
videoManagement.DramaID = TempData["dramaId"].ToString();
//设置留言
videoManagement.Videodesc = videoManagement.Videodesc ?? "这个剧很懒 什么也没有留下";
//设置是第几集
var aaa = (from a in db.VideoManagement where a.DramaID == videoManagement.DramaID select a).Count();
videoManagement.VideoIndex = aaa + 1;
if (HeadPic != null)
{
//存图片
string PicName = Guid.NewGuid().ToString() + HeadPic.FileName.Substring(HeadPic.FileName.LastIndexOf('.'));
HeadPic.SaveAs(Server.MapPath("~/images/DramaImg/" + PicName));
videoManagement.Videopic = PicName;
}
//存视频
string MovieName = Guid.NewGuid().ToString() + HeadVideo.FileName.Substring(HeadVideo.FileName.LastIndexOf('.'));
HeadVideo.SaveAs(Server.MapPath("~/Movies/" + MovieName));
videoManagement.VideoUrl = MovieName;
db.VideoManagement.Add(videoManagement);
db.SaveChanges();
}
return RedirectToAction("UpMovies");
}
else
{
TempData["message"] = "必须上传视频文件";
return RedirectToAction("InsDram");
}
}
else
{
return RedirectToAction("Index", "Signin");
}
}
}
}
上传视频
没有图片是造数据的时候没有填写 emmmmmm
好了项目到此结束 时间原因 后台管理没有去写 如有时间可以继续完善