Example #1
0
        /// <summary>
        /// 创建资源
        /// </summary>
        /// <param name="model"></param>
        public static void Create(ManageResViewModel model)
        {
            //using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
            using (MRDataEntities _db = new MRDataEntities())
            {
                tbl_Resource res = new tbl_Resource()
                {
                    res_Movie      = model.MovieId,
                    res_Name       = model.FileName,
                    res_Content    = model.Content,
                    res_Size       = float.Parse(model.FileSize),
                    res_Type       = model.ResType,
                    res_FavorCount = 0,
                    res_Status     = model.Status
                };
                if (model.User != null)
                {
                    res.res_User = model.User;
                }
                string guid;
                do
                {
                    guid = Guid.NewGuid().ToString("N").ToUpper();
                } while (_db.tbl_Resource.Where(p => p.res_Id == guid).Count() != 0);
                res.res_Id = guid;

                //_db.tbl_Resource.InsertOnSubmit(res);
                //_db.SubmitChanges();
                //_db.SetResTime(guid);
                _db.tbl_Resource.Add(res);
                _db.SaveChanges();
            }
        }
Example #2
0
        public ActionResult CreateTorrent(string id)
        {
            if (!MovieManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            ManageResViewModel res = new ManageResViewModel()
            {
                MovieId = id, MovieTitle = _db.tbl_Movie.Single(m => m.movie_Id == id).movie_Title
            };

            return(View(res));
        }
Example #3
0
        public ActionResult CreateTorrent(ManageResViewModel model, System.Web.HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (file != null && file.ContentLength > 0)
            {
                if (System.IO.Path.GetExtension(file.FileName) == ".torrent")
                {
                    var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Torrent/"), model.Id + System.IO.Path.GetFileName(file.FileName));
                    file.SaveAs(fileName);
                    model.Content = System.IO.Path.GetFileName(file.FileName);
                    model.ResType = 2;

                    var user = _db.tbl_UserAccount.SingleOrDefault(u => u.user_Account == CookieHepler.GetCookie("user"));
                    if ((bool)user.user_IsAdmin)
                    {
                        model.Status = 2;
                    }
                    else
                    {
                        model.Status = 0;
                    }
                    model.User = user.user_Id;
                    ResManager.Create(model);
                    return(RedirectToAction("Index", "Movie", new { id = model.MovieId }));
                }
                else
                {
                    ModelState.AddModelError("", "请选择正确的torrent文件");
                    return(View(model));
                }
            }
            else
            {
                ModelState.AddModelError("", "请选择一个torrent文件");
                return(View(model));
            }
        }
Example #4
0
        public ActionResult Create(ManageResViewModel model)
        {
            if (!string.IsNullOrEmpty(model.Content) && !string.IsNullOrWhiteSpace(model.Content))
            {
                model.Content = System.Web.HttpUtility.UrlDecode(model.Content);

                var user = _db.tbl_UserAccount.SingleOrDefault(u => u.user_Account == CookieHepler.GetCookie("user"));
                if ((bool)user.user_IsAdmin)
                {
                    model.Status = 2;
                }
                else
                {
                    model.Status = 0;
                    model.User   = user.user_Id;
                }
                if (model.Content.StartsWith("ed2k", true, null))
                {
                    model.ResType = 0;
                    ResManager.Create(model);
                    return(RedirectToAction("Index", "Movie", new { id = model.MovieId }));
                }
                else if (model.Content.StartsWith("magnet", true, null))
                {
                    model.ResType = 1;
                    ResManager.Create(model);
                    return(RedirectToAction("Index", "Movie", new { id = model.MovieId }));
                }
                else
                {
                    ModelState.AddModelError("", "URL不合法,请重新输入。");
                    return(View(model));
                }
            }
            else
            {
                ModelState.AddModelError("", "URL不能为空,请重新输入URL。");
                return(View(model));
            }
        }