/// <summary> /// 获取电影名 /// </summary> /// <param name="id">电影id</param> /// <returns></returns> public static string GetTitle(string id) { //using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext()) using (MRDataEntities _db = new MRDataEntities()) { tbl_Movie movie = _db.tbl_Movie.SingleOrDefault(s => s.movie_Id == id); if (movie == null) { return(null); } else { return(movie.movie_Title); } } }
public AskViewModel(tbl_Ask ask) { Id = ask.ask_Id; MovieId = ask.ask_Movie; MR_DataClassesDataContext _db = new MR_DataClassesDataContext(); tbl_Movie tblmovie = _db.tbl_Movie.SingleOrDefault(m => m.movie_Id == ask.ask_Movie); Movie = new MovieViewModel(tblmovie); Note = ask.ask_Note; State = (bool)ask.ask_State; User = ask.ask_User; Account = AccountManager.GetAccount(ask.ask_User); Time = ((DateTime)ask.ask_Time).Date.ToShortDateString();; With = (int)ask.ask_With; hadWith = false; }
public ActionResult Create(tbl_Movie movie, HttpPostedFileBase Image) { try { if (Image != null) { WebImage img = new WebImage(Image.InputStream); FileInfo fileInfo = new FileInfo(Image.FileName); string newPhoto = Guid.NewGuid().ToString() + fileInfo.Extension; img.Save("~/Uploads/MoviePhoto/" + newPhoto); movie.Image = "/Uploads/MoviePhoto/" + newPhoto; } db.tbl_Movie.Add(movie); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View(movie)); } }
/// <summary> /// 从豆瓣返回的json中提取电影信息 /// </summary> /// <param name="json">豆瓣电影json</param> /// <param name="mappath">电影海报保存地址</param> /// <returns></returns> public static tbl_Movie JsonToMovie(JObject json, string mappath) { tbl_Movie movie = new tbl_Movie(); //电影名 movie.movie_Title = json["title"].ToString(); //外文名 movie.movie_TitleEn = json["original_title"].ToString(); //又名 System.Text.StringBuilder temp = new System.Text.StringBuilder(); var aka = json["aka"].Children().Values(); foreach (var item in aka) { temp.Append(item.ToString()).Append("/"); } if (temp.Length > 0) { movie.movie_Aka = temp.Remove(temp.Length - 1, 1).ToString(); } movie.movie_Summary = json["summary"].ToString(); //剧情简介 movie.movie_DoubanID = json["id"].ToString(); //豆瓣编号 movie.movie_Year = json["year"].ToString(); //年代 //类型 temp.Clear(); var genre = json["genres"].Children().Values(); foreach (var item in genre) { temp.Append(item.ToString()).Append("/"); } if (temp.Length > 0) { movie.movie_Genres = Translator.GenreToId(temp.Remove(temp.Length - 1, 1).ToString()); } //制片国家/地区 temp.Clear(); var country = json["countries"].Children().Values(); foreach (var item in country) { temp.Append(item.ToString()).Append("/"); } if (temp.Length > 0) { movie.movie_Countries = Translator.CountryToId(temp.Remove(temp.Length - 1, 1).ToString()); } temp.Clear(); temp.Append(json["rating"]["average"].ToString());//评分 if (temp.Length == 1) { temp.Append(".0"); } movie.movie_Rating = temp.ToString(); movie.movie_RatingCount = json["ratings_count"].ToString();//评分人数 //海报 string imgurl = json["images"]["large"].ToString(); System.IO.MemoryStream ms = new System.IO.MemoryStream(HtmlDecoder.GetImage(imgurl)); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); Uri uri = new Uri(imgurl); string filePath = mappath + uri.Segments[uri.Segments.Length - 1]; img.Save(filePath); movie.movie_Avatar = uri.Segments[uri.Segments.Length - 1]; //导演 string sHtmlCode = HtmlDecoder.GetHtmlCode(string.Format("{0}{1}{2}", "http://movie.douban.com/subject/", movie.movie_DoubanID, "/")); string sDivInfo = HtmlDecoder.CutString(sHtmlCode, "<div id=\"info\">", "</div>"); if (sDivInfo.Contains(">导演")) { movie.movie_Directors = HtmlDecoder.SplitRegex(HtmlDecoder.CutString(sDivInfo, "<span class='pl'>导演</span>", "</span></span><br/>"), "<a[^>]+>([^<]+)</a>"); movie.movie_DirectorsId = HtmlDecoder.SplitRegex(HtmlDecoder.CutString(sDivInfo, "<span class='pl'>导演</span>", "</span></span><br/>"), "<a[^>]+>([^<]+)</a>", "href=\"/celebrity/", "/\""); temp.Clear(); //MR_DataClassesDataContext _db = new MR_DataClassesDataContext(); MRDataEntities _db = new MRDataEntities(); foreach (var item in movie.movie_DirectorsId.Split('/')) { var director = _db.tbl_Celebrity.SingleOrDefault(c => c.celeb_DoubanID != null && c.celeb_DoubanID == item); if (director == null) { temp.Append(item.Trim()).Append("/"); } else { temp.Append(director.celeb_Id).Append("/"); } } movie.movie_DirectorsId = temp.Remove(temp.Length - 1, 1).ToString(); } //编剧 if (sDivInfo.Contains(">编剧")) { movie.movie_Writers = HtmlDecoder.SplitRegex(HtmlDecoder.CutString(sDivInfo, "<span class='pl'>编剧</span>: <span class='attrs'>", "</span></span><br/>"), "<a[^>]+>([^<]+)</a>"); movie.movie_WritersId = HtmlDecoder.SplitRegex(HtmlDecoder.CutString(sDivInfo, "<span class='pl'>编剧</span>: <span class='attrs'>", "</span></span><br/>"), "<a[^>]+>([^<]+)</a>", "href=\"/celebrity/", "/\""); temp.Clear(); //MR_DataClassesDataContext _db = new MR_DataClassesDataContext(); MRDataEntities _db = new MRDataEntities(); foreach (var item in movie.movie_WritersId.Split('/')) { var writer = _db.tbl_Celebrity.SingleOrDefault(c => c.celeb_DoubanID != null && c.celeb_DoubanID == item); if (writer == null) { temp.Append(item.Trim()).Append("/"); } else { temp.Append(writer.celeb_Id).Append("/"); } } movie.movie_WritersId = temp.Remove(temp.Length - 1, 1).ToString(); } //主演 if (sDivInfo.Contains(">主演")) { movie.movie_Casts = HtmlDecoder.SplitRegex(HtmlDecoder.CutString(sDivInfo, "<span class=\"actor\"><span class='pl'>主演</span>: <span class='attrs'>", "</span></span><br/>"), "<a[^>]+>([^<]+)</a>"); movie.movie_CastsId = HtmlDecoder.SplitRegex(HtmlDecoder.CutString(sDivInfo, "<span class=\"actor\"><span class='pl'>主演</span>: <span class='attrs'>", "</span></span><br/>"), "<a[^>]+>([^<]+)</a>", "href=\"/celebrity/", "/\""); temp.Clear(); //MR_DataClassesDataContext _db = new MR_DataClassesDataContext(); MRDataEntities _db = new MRDataEntities(); foreach (var item in movie.movie_CastsId.Split('/')) { var cast = _db.tbl_Celebrity.SingleOrDefault(c => c.celeb_DoubanID != null && c.celeb_DoubanID == item); if (cast == null) { temp.Append(item.Trim()).Append("/"); } else { temp.Append(cast.celeb_Id).Append("/"); } } movie.movie_CastsId = temp.Remove(temp.Length - 1, 1).ToString(); } //语言 if (sDivInfo.Contains(">语言")) { string sLangs = HtmlDecoder.CutString(sDivInfo, "<span class=\"pl\">语言:</span>", "<br/>"); movie.movie_Languages = Translator.LangToId(HtmlDecoder.SplitSlash(sLangs)); } //上映日期 if (sDivInfo.Contains(">上映日期")) { movie.movie_Pubdates = HtmlDecoder.SplitRegex(HtmlDecoder.CutString(sDivInfo, "<span class=\"pl\">上映日期:</span>", "<br/>"), "<span[^>]+>([^<]+)</span>"); } //片长 if (sDivInfo.Contains(">片长")) { movie.movie_Durations = HtmlDecoder.CutString(HtmlDecoder.CutString(sDivInfo, "<span class=\"pl\">片长:</span>", "<br/>"), "\">", "</span>").Trim(); } //IMDb链接 if (sDivInfo.Contains(">IMDb链接")) { movie.movie_IMDbID = HtmlDecoder.CutString(HtmlDecoder.CutString(sDivInfo, "<span class=\"pl\">IMDb链接:</span>", "<br>"), "\">", "</a>").Trim(); } return(movie); }
//// //// GET: /Movie/IndexNew/ public ActionResult Index(string id) { if (!MovieManager.Exist(id)) { //return HttpNotFound(); return(RedirectToAction("NotFound", "Error")); } tbl_Movie tblmovie = _db.tbl_Movie.SingleOrDefault(s => s.movie_Id == id); if (tblmovie == null) { //return HttpNotFound(); return(RedirectToAction("NotFound", "Error")); } MovieViewModel movie = new MovieViewModel(tblmovie); if (User.Identity.IsAuthenticated) { movie.IsPlan = MarkManager.Validate(tblmovie.movie_Id, AccountManager.GetId(CookieHepler.GetCookie("user")), 1); movie.IsFinish = MarkManager.Validate(tblmovie.movie_Id, AccountManager.GetId(CookieHepler.GetCookie("user")), 2); movie.IsFavor = MarkManager.Validate(tblmovie.movie_Id, AccountManager.GetId(CookieHepler.GetCookie("user")), 3); movie.PlanCount = _db.tbl_Mark.Where(m => m.mark_Target == id && m.mark_Type == 1).Count(); movie.FinishCount = _db.tbl_Mark.Where(m => m.mark_Target == id && m.mark_Type == 2).Count(); movie.FavorCount = _db.tbl_Mark.Where(m => m.mark_Target == id && m.mark_Type == 3).Count(); if (tblmovie.movie_Create == AccountManager.GetId(CookieHepler.GetCookie("user")) || (bool)_db.tbl_UserAccount.SingleOrDefault(a => a.user_Account == CookieHepler.GetCookie("user")).user_IsAdmin) { movie.IsCreate = true; } var cmt = _db.tbl_Comment.SingleOrDefault(c => c.cmt_Movie == id && c.cmt_User == AccountManager.GetId(CookieHepler.GetCookie("user"))); if (cmt != null) { movie.MyComment = new CommentViewModel(cmt); } } var ress = _db.tbl_Resource.Where(m => m.res_Movie == movie.Id && m.res_Status == 2); movie.Resources = new List <ResViewModel>(); foreach (var item in ress) { movie.Resources.Add(new ResViewModel(item)); } var allcmt = _db.tbl_Comment.Where(c => c.cmt_Movie == id).OrderByDescending(c => c.cmt_Time).Take(10); movie.Comments = new List <CommentViewModel>(); foreach (var item in allcmt) { movie.Comments.Add(new CommentViewModel(item)); } movie.CommentCount = _db.tbl_Comment.Where(c => c.cmt_Movie == id).Count(); var albums = _db.tbl_Album.Where(a => a.album_Item.Contains(movie.Id)).OrderByDescending(a => a.album_Time).Take(15); movie.Albums = new List <LinkItem>(); foreach (var item in albums) { movie.Albums.Add(new LinkItem() { Id = item.album_Id, Title = item.album_Title }); } MovieManager.Visit(id); return(View(movie)); }
public MovieViewModel(tbl_Movie movie) { Id = movie.movie_Id; Title = movie.movie_Title; TitleEn = movie.movie_TitleEn; Aka = movie.movie_Aka; Pubdates = movie.movie_Pubdates; Year = movie.movie_Year; Durations = movie.movie_Durations; Genres = string.IsNullOrEmpty(movie.movie_Genres) || string.IsNullOrWhiteSpace(movie.movie_Genres) ? null : Translator.GenreToName(movie.movie_Genres); Languages = string.IsNullOrEmpty(movie.movie_Languages) || string.IsNullOrWhiteSpace(movie.movie_Languages) ? null : Translator.LangToName(movie.movie_Languages); Countries = string.IsNullOrEmpty(movie.movie_Countries) || string.IsNullOrWhiteSpace(movie.movie_Countries) ? null : Translator.CountryToName(movie.movie_Countries); Rating = movie.movie_Rating; RatingCount = movie.movie_RatingCount; Avatar = movie.movie_Avatar; Summary = movie.movie_Summary; DoubanID = movie.movie_DoubanID; IMDbID = movie.movie_IMDbID; VisitCount = (int)movie.movie_VisitCount; Create = movie.movie_Create; Status = (byte)movie.movie_Status; Note = movie.movie_Note; if (movie.movie_Summary != null && movie.movie_Summary.Length > 250) { SummaryShort = movie.movie_Summary.Substring(0, 247) + "..."; } else { SummaryShort = movie.movie_Summary; } if (movie.movie_Summary != null) { if (SummaryShort.LastIndexOfAny(new char[] { ',', '.', ',', '。', '\n' }) > 0) { SummaryShort = SummaryShort.Substring(0, SummaryShort.LastIndexOfAny(new char[] { ',', '.', ',', '。', '\n' })) + "..."; } else { SummaryShort = SummaryShort.Replace("\n", "<br/>") + "..."; } SummaryPara = movie.movie_Summary.Split('\n'); } else { SummaryPara = null; } IsCreate = false; IsPlan = false; IsFinish = false; IsFavor = false; PlanCount = 0; FinishCount = 0; FavorCount = 0; //MR_DataClassesDataContext _db = new MR_DataClassesDataContext(); MRDataEntities _db = new MRDataEntities(); Directors = new List <LinkItem>(); if (string.IsNullOrEmpty(movie.movie_DirectorsId)) { if (!string.IsNullOrEmpty(movie.movie_Directors)) { foreach (var item in movie.movie_Directors.Split('/')) { Directors.Add(new LinkItem() { Title = item }); } } } else { int i = 0; foreach (var item in movie.movie_DirectorsId.Split('/')) { if (item.Length == 32) { var celeb = _db.tbl_Celebrity.SingleOrDefault(c => c.celeb_Id == item); if (celeb != null) { Directors.Add(new LinkItem() { Title = celeb.celeb_Name, Id = celeb.celeb_Id }); } } else { Directors.Add(new LinkItem() { Title = movie.movie_Directors.Split('/')[i] }); } i++; } } Writers = new List <LinkItem>(); if (string.IsNullOrEmpty(movie.movie_WritersId)) { if (!string.IsNullOrEmpty(movie.movie_Writers)) { foreach (var item in movie.movie_Writers.Split('/')) { Writers.Add(new LinkItem() { Title = item }); } } } else { int i = 0; foreach (var item in movie.movie_WritersId.Split('/')) { if (item.Length == 32) { var celeb = _db.tbl_Celebrity.SingleOrDefault(c => c.celeb_Id == item); if (celeb != null) { Writers.Add(new LinkItem() { Title = celeb.celeb_Name, Id = celeb.celeb_Id }); } } else { Writers.Add(new LinkItem() { Title = movie.movie_Writers.Split('/')[i] }); } i++; } } Casts = new List <LinkItem>(); if (string.IsNullOrEmpty(movie.movie_CastsId)) { if (!string.IsNullOrEmpty(movie.movie_Casts)) { foreach (var item in movie.movie_Casts.Split('/')) { Casts.Add(new LinkItem() { Title = item }); } } } else { int i = 0; foreach (var item in movie.movie_CastsId.Split('/')) { if (item.Length == 32) { var celeb = _db.tbl_Celebrity.SingleOrDefault(c => c.celeb_Id == item); if (celeb != null) { Casts.Add(new LinkItem() { Title = celeb.celeb_Name, Id = celeb.celeb_Id }); } } else { Casts.Add(new LinkItem() { Title = movie.movie_Casts.Split('/')[i] }); } i++; } } }