標籤:mvc wcf 視頻網站
大家都知道做視頻網站必須要有頂和踩的功能,我們的校園視頻管理系統的頂和踩做到了和優酷頂和踩一樣的效
果,下面我們就介紹一下我做的頂和踩的功能實現。
之前想的是點擊圖片按鈕,直接讓顯示和資料庫中的資料都+1就可以了,後來參照了優酷,決定實現圖片的“點
亮”效果,於是將原來的兩張帶顏色的按鈕另做的兩張灰色按鈕,實現了圖片點亮和資料及時更新的效果。
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
下面我就做一下簡單的介紹一下實現。
準備黑白和彩色相對應的四張圖片(可以用PS和美圖秀秀修圖)。
View中的代碼:
<div class="ding" style="cursor:pointer;"> <img id="ding1" src="../../images/vedioPlayer/5-140FG92021-55_副本.jpg" onclick="getValueDing1()" /> <span id="dingspan">@video.VideoDingCount</span> </div> <div class="cai" style="cursor:pointer;"> <img id="cai1" src="../../images/vedioPlayer/5-140FG92022_副本.jpg" onclick="getValueDing2()" /> <span id="caispan">@video.VideoCaiCount</span> </div>
img標籤放圖片,span標籤顯示播放次數。
Controller中方法1,調用WCF中的方法,返回視頻播放的的資訊:
//通過guid查詢vedio的基本資料用於頁面的顯示 Guid guid = new Guid(str); List<VideoInfo> videoInfoList = new List<VideoInfo>(); videoInfoList = videoInfoService.GetPlayVideoInfo(guid); ViewData["VideoInfo"] = videoInfoList;
Controller中方法2,更新頂和踩的記錄,以頂為例:
#region 更新頂的記錄 UpdateDingCount() 張子傑 2015-2-12 09:03:34 public bool UpdateDingCount(VideoInfo videoinfo) { string videoid = Request["VideoID"]; string dingcount = Request["DingCount"]; //將捕獲的dingcount和vedioid放到實體中 VideoInfo envideoinfo = new VideoInfo(); Guid VideoID = new Guid(videoid); int DingCount = Convert.ToInt32(dingcount); envideoinfo.VideoID = VideoID; envideoinfo.VideoDingCount = DingCount; bool result = videoInfoService.UpdateDingCount(envideoinfo); return result; } #endregion
WCF中的實現方法:
#region 更新頂的個數 bool UpdateDingCount(VideoInfo videoinfo) 張子傑 2015-2-12 07:57:02 public bool UpdateDingCount(VideoInfo videoinfo) { //建立映射規則 Mapper.CreateMap<VideoInfo, VideoInfoEntity>(); //建立實體集合 VideoInfoEntity videoinfotmp = new VideoInfoEntity(); //進行轉換 videoinfotmp = Mapper.Map<VideoInfoEntity>(videoinfotmp); VideoInfoEntity VideoInfoEntity = videoinfoBLL.LoadEnities(u => u.VideoID == videoinfo.VideoID).ToList().First(); VideoInfoEntity.VideoDingCount = videoinfo.VideoDingCount; bool result = videoinfoBLL.Update(VideoInfoEntity); return result; } #endregion
之後,高端大氣的頂和踩功能就實現了。
MVC+WCF實現視頻播放的頂和踩功能