Пример #1
0
        public async Task <Movie> CreateMovieFromCreateViewModelAsync(CreateMovieViewModel model)
        {
            var newTitle = _mapper.Map <CreateTitleViewModel>(model);
            var title    = await _titleService.CreateTitleFromCreateViewModelAsync(newTitle);

            if (title == null)
            {
                return(null);
            }

            var videoInfo = new VideoInfo();

            var videos = model.VideoPaths.Select(path => new MovieVideo()
            {
                Id        = Path.GetFileNameWithoutExtension(path),
                Location  = path,
                VideoInfo = videoInfo
            }).ToList();

            var newMovie = new Movie
            {
                TitleId = title.Id
            };

            newMovie.Videos           = videos;
            newMovie.Location         = Path.GetDirectoryName(videos.First().Location);
            newMovie.ThumbnailsAmount = Directory.GetFiles(Path.Combine(wwwRoot, newMovie.Location, "Thumbnails"), "*", SearchOption.TopDirectoryOnly).Length;

            if (await CreateMovieAsync(newMovie))
            {
                return(newMovie);
            }

            return(null);
        }