Example #1
0
        public void Update(VideoAddDto dto)
        {
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoEntity> bs
                    = new BaseService <VideoEntity>(ctx);

                bool exists = bs.GetAll().Any(u => u.Title == dto.Title && u.Id != dto.Id);

                if (exists)
                {
                    throw new ArgumentException("该视频已经存在:" + dto.Title);
                }
                var entity = dto.EntityMap();

                DbEntityEntry <VideoEntity> entry = ctx.Entry <VideoEntity>(entity);
                entry.State = EntityState.Modified;
                ctx.SaveChanges();

                //ctx.Videos.Attach(entity);
                //ctx.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

                //ctx.SaveChanges();
            }
        }
        public ActionResult Edit(VideoAddDto dto)
        {
            if (dto.Id <= 0)
            {
                dto.AdminUserId = long.Parse(Session[Keys.AdminId].ToString());
                VideoService.AddNew(dto);

                AdminLogService.AddNew($"添加视频信息:{dto.Title}");
                return(Json(new AjaxResult {
                    Result = true, Msg = "视频添加成功"
                }));
            }
            VideoService.Update(dto);

            AdminLogService.AddNew($"修改视频信息:{dto.Title}");
            return(Json(new AjaxResult {
                Result = true, Msg = "视频修改成功"
            }));
        }
Example #3
0
        public long AddNew(VideoAddDto dto)
        {
            VideoEntity videoEntity = dto.EntityMap();

            videoEntity.CreateDateTime = DateTime.Now;
            using (YersDbContext ctx = new YersDbContext())
            {
                BaseService <VideoEntity> bs
                    = new BaseService <VideoEntity>(ctx);

                if (bs.GetAll().Any(m => m.Title == videoEntity.Title))
                {
                    throw new ArgumentException("该视频标题已存在,请检查");
                }

                ctx.Videos.Add(videoEntity);

                ctx.SaveChanges();

                return(videoEntity.Id);
            }
        }
        public ActionResult Edit(long id = 0)
        {
            var courseTypeList = IdNameService.GetByTypeName("课程类型").Select(m => new { text = m.Name, value = m.Id });

            ViewBag.CourseTypeList = JsonConvert.SerializeObject(courseTypeList);

            var videoTypeList = new List <IdNameDto>().Select(m => new { text = m.Name, value = m.Id });

            ViewBag.VideoTypeList = JsonConvert.SerializeObject(videoTypeList);
            VideoAddDto model;

            if (id <= 0)
            {
                model = new VideoAddDto();
            }
            else
            {
                model = VideoService.GetById(id);
            }
            ViewBag.Model = JsonConvert.SerializeObject(model);
            return(View(model));
        }
Example #5
0
        public async Task <Guid> AddVideo(VideoAddDto videoDto)
        {
            User user = await _unit.UserRepository.GetUserById(videoDto.UserId);

            Video video = new Video
            {
                Id            = Guid.NewGuid(),
                Name          = videoDto.Name,
                Description   = videoDto.Description,
                Views         = 0,
                User          = user,
                PhotoPath     = videoDto.PhotoPath,
                VideoPath     = videoDto.VideoPath,
                DayOfCreation = DateTime.Now,
            };

            await _unit.VideoRepository.AddVideo(video);

            await _unit.SaveAsync();

            return(video.Id);
        }
        public async Task <ActionResult> AddVideo([FromForm] VideoAddDto model)
        {
            model.UserId = User.Identity.Name;
            var    files = HttpContext.Request.Form.Files;
            string path  = Path.Combine(Directory.GetCurrentDirectory(), "UsersContent");

            for (int i = 0; i < 2; i++)
            {
                string save = Guid.NewGuid().ToString();
                if (files[i].FileName.Contains(".jpg") || files[i].FileName.Contains(".jpeg"))
                {
                    model.PhotoPath = save + ".jpg";
                    using (var stream = System.IO.File.Create(Path.Combine(path, "VideosPhotos", model.PhotoPath)))
                    {
                        await files[i].CopyToAsync(stream);
                    }
                }
                if (files[i].FileName.Contains(".png"))
                {
                    model.PhotoPath = save + ".png";
                    using (var stream = System.IO.File.Create(Path.Combine(path, "VideosPhotos", model.PhotoPath)))
                    {
                        await files[i].CopyToAsync(stream);
                    }
                }
                if (files[i].FileName.Contains(".mp4"))
                {
                    model.VideoPath = save + ".mp4";
                    using (var stream = System.IO.File.Create(Path.Combine(path, "UsersVideos", model.VideoPath)))
                    {
                        await files[i].CopyToAsync(stream);
                    }
                }
            }

            Guid videoId = await _videoService.AddVideo(model);

            return(Ok(videoId));
        }
Example #7
0
 public static VideoEntity EntityMap(this VideoAddDto model)
 {
     return(Mapper.Map <VideoEntity>(model));
 }