Exemplo n.º 1
0
        public async Task <IActionResult> Upload([FromForm] VideoUploadViewModel viewModel)
        {
            try
            {
                if (viewModel.VideoFile != null)
                {
                    var uploadFolder = _configuration["UploadFolder:Video"];
                    var uploadPath   = Path.Combine(environment.WebRootPath, uploadFolder);

                    if (!Directory.Exists(uploadPath))
                    {
                        Directory.CreateDirectory(uploadPath);
                    }

                    VideoUploadDto dto = MapToDto(viewModel);

                    await _videoService.UploadVideo(dto, uploadPath);
                }
            }
            catch (Exception Ex)
            {
                return(Json(new ResultViewModel {
                    IsSucces = false, Message = Ex.Message
                }));
            }

            return(Json(new ResultViewModel {
                IsSucces = true, Message = "File uploaded"
            }));
        }
Exemplo n.º 2
0
        public bool UploadVideos(VideoUploadViewModel videoUploadViewModel)
        {
            var round = dbContext.EventRounds.FirstOrDefault(x => x.EventType == videoUploadViewModel.Video.EventTypeId && x.EventStage == EventStages.Backstage);

            if (round != null)
            {
                videoUploadViewModel.Video.CompetitionRound         = Convert.ToInt32(round.Id);
                videoUploadViewModel.Video.CreatedDate              = DateTime.Now.ToAppDateTime();
                videoUploadViewModel.Video.CompetitionQualifiedDate = DateTime.Now.ToAppDateTime();
                videoUploadViewModel.Video.IsActive   = false;
                videoUploadViewModel.Video.Eventstage = 200;
                dbContext.Video.Add(videoUploadViewModel.Video);
                dbContext.SaveChanges();
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        //Move to mapper class !
        private VideoUploadDto MapToDto(VideoUploadViewModel viewModel)
        {
            VideoUploadDto dto = new VideoUploadDto
            {
                VideoFile = viewModel.VideoFile,
                VideoName = viewModel.VideoName
            };

            foreach (var gender in viewModel.VideoGenders)
            {
                dto.VideoGenders.Add(new VideoGendersDto()
                {
                    GenderName = gender.GenderName, Id = gender.Id
                });
            }

            return(dto);
        }
Exemplo n.º 4
0
        public ActionResult Create(VideoUploadViewModel video)
        {
            if (ModelState.IsValid)
            {
                foreach (HttpPostedFileBase file in video.Files)
                {
                    byte[] bytes;
                    using (BinaryReader br = new BinaryReader(file.InputStream))
                    {
                        bytes = br.ReadBytes(file.ContentLength);
                    }

                    Video v = new Video
                    {
                        name        = video.name,
                        location    = video.location,
                        data        = bytes,
                        contentType = file.ContentType
                    };

                    if (video.catList.Count() > 0)
                    {
                        foreach (int catId in video.catList)
                        {
                            Cat c = db.Cats.Find(catId);
                            Video_Cat_Junction catVideo = new Video_Cat_Junction
                            {
                                video_id = v.id,
                                cat_id   = catId
                            };
                            db.Video_Cat_Junction.Add(catVideo);
                        }
                    }
                    ;

                    db.Videos.Add(v);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(video));
        }
Exemplo n.º 5
0
        public JsonResult VideoUpload(VideoUploadViewModel video)
        {
            if (ModelState.IsValid)
            {
                byte[] bytes;
                using (BinaryReader br = new BinaryReader(video.Files[0].InputStream))
                {
                    bytes = br.ReadBytes(video.Files[0].ContentLength);
                }

                Video v = new Video
                {
                    name        = video.name,
                    location    = video.location,
                    data        = bytes,
                    contentType = video.Files[0].ContentType
                };

                if (video.catList.Count() > 0)
                {
                    foreach (int catId in video.catList)
                    {
                        Cat c = db.Cats.Find(catId);
                        Video_Cat_Junction catVideo = new Video_Cat_Junction
                        {
                            video_id = v.id,
                            cat_id   = catId
                        };
                        db.Video_Cat_Junction.Add(catVideo);
                    }
                }
                ;

                db.Videos.Add(v);
                db.SaveChanges();
                return(Json("success", JsonRequestBehavior.DenyGet));
            }

            return(Json("failed", JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Index(VideoUploadViewModel videoUploadViewModel)
        {
            if (_authContext.User != null)
            {
                videoUploadViewModel.Video.UserId = _authContext.User.User.Id;

                if (!_tokenService.CheckIsTokenValid(videoUploadViewModel.Video.TokenUniqueId, 1))
                {
                    videoUploadViewModel.Video.DeveloperMessage = "Token is not valid";
                }
                var uploads = Path.Combine(_appEnvironment.WebRootPath, "Uploads\\Videos");
                var files   = HttpContext.Request.Form.Files;
                foreach (var file in files)
                {
                    if (file != null && file.Length > 0)
                    {
                        if (file.Length > 0)
                        {
                            var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName);
                            using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                videoUploadViewModel.Video.VideoPath = fileName;
                            }
                        }
                    }
                }

                var thumblineName = Path.ChangeExtension(videoUploadViewModel.Video.VideoPath, "jpg");
                CreateAndSaveVideoThumbnail(videoUploadViewModel.Video.VideoPath, Path.Combine(uploads, thumblineName));
                videoUploadViewModel.Video.VideoThumblinePath = thumblineName;
                _videoService.UploadVideos(videoUploadViewModel);
            }

            return(await Task.Run(() => Index()));
        }
 public ActionResult Create(VideoUploadViewModel model)
 {
     return this.CreateFromModel(model);
 }