示例#1
0
        public ActionResult Delete(int id)
        {
            Video v = videoContext.videoLists.Find(id);

            videoContext.videoLists.Remove(v);
            videoContext.SaveChanges();
            return(Content("删除成功:"));
        }
示例#2
0
        public ActionResult DodajFilm(FilmViewModel film, HttpPostedFileBase videofile)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (film.ImageUpload == null || film.ImageUpload.ContentLength == 0)
            {
                ModelState.AddModelError("ImageUpload", "Polje je obavezno");
            }
            else if (!validImageTypes.Contains(film.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Molimo odaberite podatak sa ovim ekstenzijama: GIF, JPG ili PNG.");
            }

            if (ModelState.IsValid)
            {
                if (videofile != null)
                {
                    string filename = Path.GetFileName(videofile.FileName);
                    if (videofile.ContentLength < 2147483647)
                    {
                        videofile.SaveAs(Server.MapPath("/Videofiles/" + filename));
                    }

                    var noviFilm = new Film
                    {
                        ID       = film.ID,
                        Naziv    = film.Naziv,
                        Godina   = film.Godina,
                        Zanr     = film.Zanr.ToString(),
                        Ocena    = film.Ocena,
                        Trajanje = film.Trajanje,
                        Video    = "/Videofiles/" + filename
                    };

                    if (film.ImageUpload != null && film.ImageUpload.ContentLength > 0)
                    {
                        var uploadDir = "~/Slike";
                        var imagePath = Path.Combine(Server.MapPath(uploadDir), film.ImageUpload.FileName);
                        var imageUrl  = Path.Combine(uploadDir, film.ImageUpload.FileName);
                        film.ImageUpload.SaveAs(imagePath);
                        noviFilm.Slika = imageUrl;
                    }

                    _context.Film.Add(noviFilm);
                    _context.SaveChanges();
                    return(RedirectToAction("Index", "Film"));
                }
            }
            return(View(film));
        }
        public ActionResult AddNewVideo(Video newVideo, HttpPostedFileBase uploadVideo)
        {
            Video titleVideo = db.Videos.FirstOrDefault(v => v.Title == newVideo.Title.Trim());

            if (titleVideo == null)
            {
                if (uploadVideo != null)
                {
                    string fileFormat = Path.GetExtension(uploadVideo.FileName);
                    // control format of uploaded file
                    if (fileFormat == ".mp4" || fileFormat == ".swf" || fileFormat == ".ogg" || fileFormat == ".wmv" || fileFormat == ".mpeg" || fileFormat == ".muv")
                    {
                        // control uploaded size
                        if (uploadVideo.ContentLength > 100040000)  // Size of file must be 100Mb or smaller
                        {
                            ModelState.AddModelError("Select video", $"Your video has a size of {uploadVideo.ContentLength.ToString()} bytes which exceeded the limit of 100040000 bytes.  Please save your video in size of 100Mb or less and then try again.");
                            return(View());
                        }

                        newVideo.UserId = GetUserId();
                        newVideo.Date   = DateTime.Now;


                        if (newVideo.Title == string.Empty)
                        {
                            newVideo.Title = Path.GetFileName(uploadVideo.FileName);
                        }
                        newVideo.VideoFormat = string.Concat(newVideo.Title, fileFormat);

                        // saving video in UploadedVideos folder
                        uploadVideo.SaveAs(Server.MapPath($"~/UploadedVideos/{newVideo.VideoFormat}"));

                        db.Videos.Add(newVideo);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("Select Video", "Type of video must be .mp4, .swf, .ogg, .wmv, .mpeg or .muv");
                        return(View());
                    }
                }
                else
                {
                    ModelState.AddModelError("Select Video", "Video haven't uploaded. Please upload video.");
                    return(View());
                }
            }
            else
            {
                ModelState.AddModelError("Title", "Video with this title exists. Write another title or upload another video.");
            }
            return(View());
        }
示例#4
0
        public ActionResult Create([Bind(Include = "ID,TagName")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                db.Tags.Add(tag);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tag));
        }
示例#5
0
        public ActionResult Create([Bind(Include = "ID,Title,MyDescription,FrameRate,EncodingID")] Video video)
        {
            if (ModelState.IsValid)
            {
                db.Videos.Add(video);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EncodingID = new SelectList(db.Encodings, "ID", "Codec", video.EncodingID);
            return(View(video));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "ID,VideoID,TagID")] VideoTag videoTag)
        {
            if (ModelState.IsValid)
            {
                db.VideoTags.Add(videoTag);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TagID   = new SelectList(db.Tags, "ID", "TagName", videoTag.TagID);
            ViewBag.VideoID = new SelectList(db.Videos, "ID", "Title", videoTag.VideoID);
            return(View(videoTag));
        }
示例#7
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // Дополнительные сведения о том, как включить подтверждение учетной записи и сброс пароля, см. по адресу: http://go.microsoft.com/fwlink/?LinkID=320771
                    // Отправка сообщения электронной почты с этой ссылкой
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Подтверждение учетной записи", "Подтвердите вашу учетную запись, щелкнув <a href=\"" + callbackUrl + "\">здесь</a>");
                    Profile profile = new Profile();
                    profile.UserId = Guid.Parse(user.Id);
                    using (VideoContext db = new VideoContext())
                    {
                        db.Profiles.Add(profile);
                        db.SaveChanges();
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return(View(model));
        }
示例#8
0
        public ActionResult Register(Register newUser)
        {
            User user = null;

            if (ModelState.IsValid)
            {
                if (newUser.Password.Trim() != newUser.ConfirmPassword.Trim())
                {
                    ModelState.AddModelError("ConfirmPassword", "Password fields must be equal");
                }

                // check user in DB
                using (VideoContext db = new VideoContext())
                {
                    user = db.Users.FirstOrDefault(u => u.Name == newUser.Name);
                }

                if (user == null)
                {
                    using (VideoContext db = new VideoContext())
                    {
                        db.Users.Add(new Models.User {
                            Name = newUser.Name, Password = CalculateMD5Hash(newUser.Password)
                        });
                        db.SaveChanges();
                        return(RedirectToAction("RegisterSuccess", "Authentification"));
                    }
                }
                else
                {
                    ModelState.AddModelError("Name", "User with this name exists");
                }
            }
            return(View(newUser));
        }
示例#9
0
        public ActionResult Create([Bind(Include = "Id,Name,UserId,Picture")] Profile profile, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        profile.Picture = reader.ReadBytes(upload.ContentLength);
                    }
                }
                db.Profiles.Add(profile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(profile));
        }
 public void AddVideo(Video video)
 {
     using (var videocontext = new VideoContext())
     {
         videocontext.Configuration.ValidateOnSaveEnabled = false;
         videocontext.Video.Add(video);
         videocontext.SaveChanges();
     }
 }
 public void DeleteVideo(int id)
 {
     using (var videocontext = new VideoContext())
     {
         var entity = videocontext.Video.First(x => x.VideoID == id);
         videocontext.Video.Remove(entity);
         videocontext.SaveChanges();
     }
 }
示例#12
0
        public ActionResult Create([Bind(Include = "ID,Path,Title")] Video.Models.Video video)
        {
            if (ModelState.IsValid)
            {
                db.Videos.Add(video);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View("Index"));
        }
        public ActionResult DodajKorisnika(KorisnikViewModel korisnik)
        {
            if (ModelState.IsValid)
            {
                var noviKorisnik = new Korisnik
                {
                    ID            = korisnik.ID,
                    Ime           = korisnik.Ime,
                    Prezime       = korisnik.Prezime,
                    KorisnickoIme = korisnik.KorisnickoIme,
                    Lozinka       = korisnik.Lozinka,
                    PravoPristupa = korisnik.PravoPristupa,
                };

                _context.Korisnik.Add(noviKorisnik);
                _context.SaveChanges();
                return(RedirectToAction("Index", "Korisnik"));
            }

            return(View(korisnik));
        }
示例#14
0
        public ActionResult Izbrisi(long?id, FormCollection fcNotUsed)
        {
            VideoContext _context;

            _context = new VideoContext();

            var film = _context.Film.Where(x => x.ID == id).FirstOrDefault();

            _context.Film.Remove(film);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Film"));
        }
 public void UpdateVideo(Video video)
 {
     using (var videocontext = new VideoContext())
     {
         videocontext.Configuration.ValidateOnSaveEnabled = false;
         foreach (var entity in videocontext.Video.Where(x => x.VideoID == video.VideoID))
         {
             entity.DatePremiere = video.DatePremiere;
             entity.GenreID      = video.GenreID;
             entity.Title        = video.Title;
             entity.GenreID      = video.GenreID;
         }
         videocontext.SaveChanges();
     }
 }
示例#16
0
        /// <summary>
        /// 通过Id获取视频Url
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <CommonResult <VideoDto> > GetOnPalyUrl(ById value)
        {
            var result = new CommonResult <VideoDto>();

            try
            {
                var video = await _context.Videos.Where(x => x.Id == value.Id).FirstAsync();

                if (string.IsNullOrEmpty(video.Url))
                {
                    result.scode  = "200";
                    result.remark = "查询数据成功";
                    result.result = null;

                    return(result);
                }

                var analysisUrls = await _context.AnalysisUrls.ToArrayAsync();

                var analysisUrl = analysisUrls.OrderBy(x => Guid.NewGuid()).First();

                analysisUrl.PlayCount += 1;
                video.PlayCount       += 1;

                _context.SaveChanges();

                VideoDto videoUrl = new VideoDto
                {
                    Url = analysisUrl.Url + video.Url
                };

                result.scode  = "200";
                result.remark = "查询数据成功";
                result.result = videoUrl;
            }
            catch (Exception ex)
            {
                result.scode  = "500";
                result.remark = "服务器端错误:" + ex.Message;
            }

            return(result);
        }
示例#17
0
        public ActionResult Create([Bind(Include = "Id,Profileid,Videotitle,Vlink,Shared,Datein,Like,Dislike,Views,Info")] Video video)
        {
            if (ModelState.IsValid)
            {
                video.Datein  = DateTime.Now;
                video.Dislike = 0;
                video.Like    = 0;
                video.Views   = 0;
                video.Shared  = false;
                var userId = HttpContext.User.Identity.GetUserId();
                if (userId == null)
                {
                    return(RedirectToAction("SharedVideo"));
                }
                Guid g = Guid.Parse(userId);
                var  p = db.Profiles.Where((x) => x.UserId == g).FirstOrDefault();
                video.Profileid = p.Id;
                db.Videos.Add(video);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(video));
        }
示例#18
0
 public void Create(Video video)
 {
     videoContext.Videos.Add(video);
     videoContext.SaveChanges();
 }