示例#1
0
        public JsonResult SaveVideo(VideoModel video)
        {
            var sessionId = this.Session["SessionID"].ToString();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            if (userSession == null)
            {
                return(Json(new { errorCode = (int)ErrorCode.Redirect, message = Resources.AdminResource.msg_sessionInvalid }, JsonRequestBehavior.AllowGet));
            }

            InsertResponse response = new InsertResponse();

            video.Title = video.Title.Length > 200 ? video.Title.Substring(0, 100) + "..." : video.Title;
            if (!string.IsNullOrEmpty(video.Shortcontent))
            {
                video.Shortcontent = video.Shortcontent.Length > 300 ? video.Shortcontent.Substring(0, 296) + "..." : video.Shortcontent;
            }
            else
            {
                video.Shortcontent = null;
            }
            video.ActionURL   = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(video.Title), UrlSlugger.Get8Digits());
            video.CreatedDate = DateTime.Now;
            video.VideoID     = Guid.NewGuid().ToString();
            video.CreatedBy   = userSession != null ? userSession.UserID : string.Empty;
            response          = _videoService.CreateVideo(video);

            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        private void InitiateCreateVideoMenu()
        {
            Console.Clear();
            Console.WriteLine(
                "| Creating a new video |\n" +
                "|______________________|\n");
            string nameOfNewVideo =
                printerFunctions.AskQuestion("- Enter name of video: ");

            Console.WriteLine();

            Console.WriteLine(
                "- Enter video genre:");
            string genreOfNewVideo = Console.ReadLine();

            var video = _videoService.NewVideo(nameOfNewVideo, genreOfNewVideo);

            video = _videoService.CreateVideo(video);

            Console.Clear();
            Console.WriteLine(
                "| Created video |\n" +
                "|_______________|\n");
            printerFunctions.PrintVideo(video);
        }
 // POST: api/VideoUpload
 public HttpResponseMessage Post(Video video)
 {
     if (ModelState.IsValid)
     {
         _videoUploadService.CreateVideo(video);
         return(Request.CreateResponse(HttpStatusCode.Created, video));
     }
     return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState));
 }
        public IActionResult Create(int id, [FromBody] CreateVideoOptions options)
        {
            var result = videoService.CreateVideo(id, options);

            if (!result.Success)
            {
                return(StatusCode((int)result.ErrorCode,
                                  result.ErrorText));
            }

            return(Json(result.Data));
        }
示例#5
0
        private void AddVideo()
        {
            Console.WriteLine("-Add-");
            Console.WriteLine("Name:");
            string name = Console.ReadLine();

            Console.WriteLine("Genre:");
            string genre = Console.ReadLine();

            videoService.CreateVideo(name, genre);
            ShowVideosList();
            ClearUserConsole();
        }
示例#6
0
        public async Task <IActionResult> Index(List <IFormFile> images, IFormFile audioFile)
        {
            //TODO: ofc here must be something FluentValidation.
            if (images.Count <= 0 || audioFile == null)
            {
                return(StatusCode(500, "Please provide at least 1 image and only one audio file"));
            }

            var          folderName  = fileManagerService.CreateFolder().Data;
            List <Image> savedImages = new List <Image>();
            Audio        savedAudio  = null;

            foreach (var formFile in images)
            {
                if (formFile.Length > 0)
                {
                    var typeOfFile = ExtentionDeterminizer.Determinize(formFile.FileName);

                    using (var ms = new MemoryStream())
                    {
                        formFile.CopyTo(ms);
                        var fileBytes = ms.ToArray();

                        var imageFile = fileManagerService.SaveFile(fileBytes, Path.GetExtension(formFile.FileName), FileTypeEnum.picture, folderName);
                        savedImages.Add(imageFile.Data as Image);
                    }
                }
            }

            using (var ms = new MemoryStream())
            {
                audioFile.CopyTo(ms);
                var fileBytes = ms.ToArray();

                savedAudio = fileManagerService.SaveFile(fileBytes, Path.GetExtension(audioFile.FileName), FileTypeEnum.audio, folderName).Data as Audio;
            }

            var filePath = videoService.CreateVideo(new VideoCreationDTO {
                AudioFile = savedAudio, Images = savedImages, Path = folderName
            });

            if (filePath.Success)
            {
                return(Ok(filePath.Data));
            }

            return(StatusCode(500, "Happened something bad"));
        }
示例#7
0
        public async Task <IActionResult> UploadVideo([FromRoute] int folderId)
        {
            var file = Request.Form.Files[0];

            if (file.Length <= 0)
            {
                return(this.Ok());
            }
            var extension   = Path.GetExtension(file.FileName);
            var createModel = new CreateVideoVm
            {
                UserId          = this.CurrentUserId.Value,
                FileName        = file.FileName.Substring(0, file.FileName.Length - extension.Length),
                FolderId        = folderId,
                Extension       = extension,
                VideoFile       = file.OpenReadStream(),
                VideoAccessType = VideoAccessType.None
            };
            var videoId = await _videoService.CreateVideo(this.CurrentUserId.Value, createModel, _appEnvironment.ContentRootPath);

            return(this.Ok(videoId));
        }