Exemple #1
0
 public ActionResult add(VideoAddViewModel _model)
 {
     if (ModelState.IsValid)
     {
         Video video = new Video()
         {
             Title      = _model.Title,
             CommentNum = 0,
             ZanNum     = 0,
             CreateTime = DateTime.Now,
             Img        = _model.Img,
             Src        = _model.Src
         };
         video = videoBll.Add(video);
         if (video.Id > 0)
         {
             return(RedirectToAction("list"));
         }
         else
         {
             ModelState.AddModelError("", "添加失败!");
         }
     }
     return(View());
 }
Exemple #2
0
        public async Task <ActionResult> Add(VideoAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                var file  = model.Video;
                var video = new Video()
                {
                    Name = model.Name, Order = 1, Course = db.Courses.Find(model.CourseId)
                };
                db.Videos.Add(video);
                await db.SaveChangesAsync();

                int id   = video.Course.Id;
                var path = AddCourseFile(file, "video", "Videos", id);
                if (path != null)
                {
                    video.Path = path;
                    await db.SaveChangesAsync();
                }
                return(RedirectToAction("View", "Course", new { id = model.CourseId }));
            }
            return(View(model));
        }
Exemple #3
0
        public async Task <ActionResult> Edit(VideoAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                var video = await db.Videos.FindAsync(model.Id);

                if (video == null)
                {
                    return(View("Error"));
                }
                video.Name = model.Name;
                var file = model.Video;
                var path = AddCourseFile(file, "video", "Videos", video.Course.Id);
                if (path != null)
                {
                    video.Path = path;
                }
                await db.SaveChangesAsync();

                return(RedirectToAction("View", "Course", new { id = model.CourseId }));
            }
            return(View(model));
        }