Exemplo n.º 1
0
        public async Task <IActionResult> Post(CreateUserViewModel user)
        {
            try
            {
                #region Get File From Ziggeo
                var video = new Video();
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Get, user.VideoUrl))
                    {
                        var contentStream = await(await client.SendAsync(request)).Content.ReadAsStreamAsync();
                        var bytesFiles    = contentStream.ToBytes();
                        video.File = new CommonFile
                        {
                            File = bytesFiles,
                            Name = user.FileName
                        };
                    }
                #endregion

                #region Save File At azure
                var azureFileService = _azureFileHandlerFactory.GetService(
                    _azureSettings.ConnectionString,
                    _azureSettings.VideoContainer
                    );
                user.AzureVideoUrl = await azureFileService.SaveFileAsync(video.File);

                #endregion

                #region Save User
                var userDal = _userFactory.Get(user);

                _unitOfWork.Users.Add(userDal);
                _unitOfWork.SaveChanges();
                #endregion

                #region Get VideoID
                var videoMedia = await _videoAnalizer.PostVideo(user.AzureVideoUrl);

                #endregion

                return(Json(new { userId = userDal.Id, videoId = videoMedia.Id }));
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e));
            }
        }
Exemplo n.º 2
0
 public async Task <ActionResult> Post(string url)
 {
     return(Json(await _videoAnalizer.PostVideo(url)));
 }