Esempio n. 1
0
        public AddLecturesBindingModel GetLectureBindingModelWithCourseId(int courseId, string userId)
        {
            var isValid = this.db.Courses.Where(x => x.Id == courseId).FirstOrDefault()?.InstructorId == userId;
            if (!isValid)
            {
                return null;
            }
            var model = new AddLecturesBindingModel
            {
                CourseId = courseId
            };

            return model;
        }
Esempio n. 2
0
        public async Task <IActionResult> Add(AddLecturesBindingModel model)
        {
            var userId     = this.userManager.GetUserId(this.User);
            var modelValid = this.lectureService.GetLectureBindingModelWithCourseId(model.CourseId, userId);

            if (!ModelState.IsValid || modelValid == null)
            {
                return(Json("Invalid"));
            }

            try
            {
                var inputAsset = await this.azureMediaService.CreateInputAssetAsync(model.Video);

                var outputAsset = await this.azureMediaService.CreateOutputAssetAsync();

                var transform = await this.azureMediaService.GetOrCreateTransformAsync();

                var job = await this.azureMediaService.SubmitJobAsync(inputAsset.Name, outputAsset.Name, transform.Name);

                await this.azureMediaService.WaitForJobToFinishAsync(transform.Name, job.Name);

                var streamingLocator = await this.azureMediaService.CreateStreamingLocatorAsync(outputAsset.Name);

                var getStreamingUrls = await this.azureMediaService.GetStreamingUrlsAsync(streamingLocator.Name);

                await this.azureMediaService.CleanUpAsync(transform.Name, inputAsset.Name);

                await this.lectureService.SaveLectureDbAsync(model.CourseId, model.Name, outputAsset.Name, getStreamingUrls[2]);

                return(Json("Valid"));
            }
            catch
            {
                throw new InvalidOperationException("Неуспешно добаване в AzureMedia");
            }
        }