Exemplo n.º 1
0
        public async Task <ActionResult> PostVideos(VideoAttributesViewModel videoAttributesViewModel)
        {
            if (ModelState.IsValid)
            {
                var duplicationCheck = await _videoAttributesService.GetSingleAsync(i => i.Url.ToLower().Contains(videoAttributesViewModel.VideoId.ToLower()));

                if (duplicationCheck == null)
                {
                    var videoAttributes = _mapper.Map <VideoAttributesExtend>(videoAttributesViewModel);
                    videoAttributes.UserId = User.Identity.GetUserId();
                    var friendlyTitle = FriendlyUrlHelper.GetFriendlyTitle(videoAttributes.Title);

                    if (!string.IsNullOrEmpty(videoAttributes.Id))
                    {
                        videoAttributes.Thumbunail = await Fluxy.Core.Helpers.ImageHelpers.GetYouTubeThumbnail(videoAttributesViewModel.VideoId, friendlyTitle);

                        await _videoAttributesService.UpdateAsync(videoAttributes);
                    }
                    else
                    {
                        videoAttributes.Thumbunail = await Fluxy.Core.Helpers.ImageHelpers.GetYouTubeThumbnail(videoAttributesViewModel.VideoId, friendlyTitle);

                        await _videoAttributesService.CreateAsync(videoAttributes);
                    }
                    return(RedirectToAction(ProfileControllerAction.Index));
                }
                else
                {
                    return(RedirectToAction(ProfileControllerAction.Index, routeValues: new { message = Messages.VideoDuplication, userId = string.Empty }));
                }
            }
            return(View(ProfileControllerAction.PostVideos, videoAttributesViewModel));
        }
        public async Task <ActionResult> Create(VideoAttributesViewModel videoAttributesViewModel)
        {
            if (ModelState.IsValid)
            {
                var duplicationCheck = await _videoAttributesService.GetSingleAsync(i => i.Url.ToLower().Contains(videoAttributesViewModel.VideoId.ToLower()));

                if (duplicationCheck == null)
                {
                    var videoAttributes = _mapper.Map <VideoAttributesExtend>(videoAttributesViewModel);
                    videoAttributes.UserId = User.Identity.GetUserId();
                    var friendlyTitle = FriendlyUrlHelper.GetFriendlyTitle(videoAttributes.Title);
                    videoAttributes.Thumbunail = await Fluxy.Core.Helpers.ImageHelpers.GetYouTubeThumbnail(videoAttributesViewModel.VideoId, friendlyTitle);

                    await _videoAttributesService.CreateAsync(videoAttributes);

                    return(RedirectToAction(VideoManagementControllerActions.Index));
                }
                else
                {
                    ViewBag.VideoSettingsId = new SelectList(await _videoSettingsService.GetAllAsync(), "Id", "Name");
                    ViewBag.CategoryId      = new SelectList(await _categoryService.GetAllAsync(), "Id", "Name");
                    ViewBag.LanguageId      = new SelectList(await _languageService.GetAllAsync(), "Id", "Name");
                    Danger("Video already there in our database");
                    return(View(VideoManagementControllerActions.Create, videoAttributesViewModel));
                }
            }

            ViewBag.VideoSettingsId = new SelectList(await _videoSettingsService.GetAllAsync(), "Id", "Name");
            ViewBag.CategoryId      = new SelectList(await _categoryService.GetAllAsync(), "Id", "Name");
            ViewBag.LanguageId      = new SelectList(await _languageService.GetAllAsync(), "Id", "Name");
            return(View(VideoManagementControllerActions.Create, videoAttributesViewModel));
        }