Esempio n. 1
0
        public async Task <IActionResult> AddVideo(AddVideoViewModel model)
        {
            var video = _context.Video.Where(x => x.TripId == model.TripId).ToList();

            if (!video.Any())
            {
                var    filename = Path.Combine(_webhost.WebRootPath, "Video", model.Video.FileName);
                string ext      = Path.GetExtension(model.Video.FileName);
                if (ext == ".mp4" || ext == ".MP4")
                {
                    using (var uploading = new FileStream(filename, FileMode.Create))
                    {
                        await model.Video.CopyToAsync(uploading);

                        var vid = new Video()
                        {
                            Name   = model.Video.FileName,
                            TripId = model.TripId
                        };
                        _context.Video.Add(vid);
                        _context.SaveChanges();
                    }
                    return(RedirectToAction("ShowVideo", new { id = model.TripId }));
                }
                else
                {
                    model.Error = "Plik " + model.Video.FileName + " jest nieprawidłowy. Proszę wskazać plik z rozszerzeniem MP4";
                    return(View(model));
                }
            }
            model.Error = "Do danej wycieczki dodano już wideo. Przykro nam, nie możesz dodać więcej.";
            return(View(model));
        }
        public ActionResult Add()
        {
            var viewModel = new AddVideoViewModel();

            this.SetGalleryNames(viewModel);
            return(View(viewModel));
        }
Esempio n. 3
0
        public IActionResult AddVideo(int id)
        {
            var model = new AddVideoViewModel();

            model.TripId = id;
            return(View(model));
        }
        public void ReturnJsonWithErrorMessage_IfVideoTitleIsNotValid()
        {
            // Arrange
            var galleryName   = "Valid name";
            var videoUrl      = "url";
            var galleryId     = "id";
            var mockedService = new Mock <IVideoService>();

            mockedService.Setup(s => s.GetGalleryNameById(It.IsAny <string>())).Returns(galleryName);
            mockedService.Setup(s => s.AddVideoToGallery(It.IsAny <string>(), It.IsAny <Video>())).Verifiable();

            var mockedVideoFactory = new Mock <IVideoFactory>();
            var mockedDateProvider = new Mock <IDateProvider>();

            var mockedModel = new AddVideoViewModel()
            {
                VideoUrl = videoUrl, GalleryId = galleryId
            };
            var controller = new VideoController(mockedService.Object, mockedVideoFactory.Object, mockedDateProvider.Object);

            controller.ModelState.AddModelError("VideoTitle", "Error");

            // Act
            var     result  = controller.Add(mockedModel) as JsonResult;
            dynamic dResult = result.Data;

            // Assert
            Assert.AreEqual(GlobalMessages.InvalidVideoTitleMessage, dResult.message);
            Assert.AreEqual("error", dResult.status);
            mockedService.Verify(s => s.AddVideoToGallery(It.IsAny <string>(), It.IsAny <Video>()), Times.Never);
            mockedVideoFactory.Verify(f => f.CreateVideo(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()), Times.Never);
            mockedDateProvider.Verify(p => p.GetDate(), Times.Never);
        }
 public AddVideoPage()
 {
     InitializeComponent();
     _viewModel                        = new AddVideoViewModel();
     _viewModel.VideoItem              = new Video();
     _viewModel.VideoItem.AccessLevel  = 0;
     VideoDatePicker.Date              = DateTime.Now.Date;
     VideoTimePicker.Time              = DateTime.Now.TimeOfDay;
     BindingContext                    = _viewModel;
     ProgenyCollectionView.ItemsSource = _viewModel.ProgenyCollection;
 }
        public IActionResult AddVideo(string title, string author, string url, string thumbnail)
        {
            AddVideoViewModel addVideoViewModel = new AddVideoViewModel()
            {
                Title     = title,
                Author    = author,
                Url       = url,
                Thumbnail = thumbnail,
            };

            return(View(addVideoViewModel));
        }
        //main server page
        public IActionResult Index()
        {
            AddVideoViewModel vm          = new AddVideoViewModel();
            IList <Message>   allMessages = context.Messages.ToList();

            ViewBag.allMessages = allMessages;


            IList <video> allVideos = context.Videos.ToList();

            ViewBag.allVideos = allVideos;
            return(View(vm));
        }
        public IActionResult Index(AddVideoViewModel vm)
        {
            if (ModelState.IsValid)
            {
                video newvideo = new video
                {
                    Url   = vm.EyeD,
                    Title = vm.Title
                };
                context.Videos.Add(newvideo);
                context.SaveChanges();
                return(Redirect("/"));
            }
            IList <Message> allMessages = context.Messages.ToList();

            ViewBag.allMessages = allMessages;
            return(Redirect("/"));
        }
        public ActionResult Add(AddVideoViewModel model)
        {
            this.SetGalleryNames(model);
            string galleryName;

            if (model.GalleryId != null)
            {
                galleryName = this.videoService.GetGalleryNameById(model.GalleryId);
            }
            else
            {
                galleryName = model.NewGalleryName;
            }

            if (model.VideoUrl == null || model.VideoUrl.Length == 0)
            {
                return(Json(new { status = "error", message = GlobalMessages.InvalidVideoUrlMessage }));
            }

            if (galleryName == null || galleryName.Length == 0)
            {
                return(Json(new { status = "error", message = GlobalMessages.InvalidGalleryNameMessage }));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var date  = this.dateProvider.GetDate();
                    var url   = model.VideoUrl.Replace("watch?v=", "embed/");
                    var video = this.videoFactory.CreateVideo(model.VideoTitle, url, date);
                    this.videoService.AddVideoToGallery(galleryName, video);
                    this.videoService.Save();
                    return(Json(new { status = "success", message = GlobalMessages.AddVideoSuccessMessage }));
                }
                catch (Exception)
                {
                    return(Json(new { status = "error", message = GlobalMessages.AddVideoErrorMessage }));
                }
            }
            else
            {
                return(Json(new { status = "error", message = GlobalMessages.InvalidVideoTitleMessage }));
            }
        }
        public void CallAddVideoToGalleryFromVideoService_AndReturnSuccessMessage_IfVideoIsAdded()
        {
            // Arrange
            var galleryName   = "Valid name";
            var videoUrl      = "url";
            var galleryId     = "id";
            var videoTitle    = "Title";
            var mockedService = new Mock <IVideoService>();

            mockedService.Setup(s => s.GetGalleryNameById(It.IsAny <string>())).Returns(galleryName).Verifiable();
            mockedService.Setup(s => s.AddVideoToGallery(It.IsAny <string>(), It.IsAny <Video>())).Verifiable();
            mockedService.Setup(s => s.Save()).Verifiable();

            var mockedVideoFactory = new Mock <IVideoFactory>();

            mockedVideoFactory.Setup(f => f.CreateVideo(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>())).Verifiable();

            var mockedDateProvider = new Mock <IDateProvider>();

            mockedDateProvider.Setup(p => p.GetDate()).Verifiable();

            var controller  = new VideoController(mockedService.Object, mockedVideoFactory.Object, mockedDateProvider.Object);
            var mockedModel = new AddVideoViewModel()
            {
                VideoUrl = videoUrl, GalleryId = galleryId, VideoTitle = videoTitle
            };

            // Act
            var     result  = controller.Add(mockedModel) as JsonResult;
            dynamic dResult = result.Data;

            // Assert
            Assert.AreEqual(GlobalMessages.AddVideoSuccessMessage, dResult.message);
            Assert.AreEqual("success", dResult.status);

            mockedService.Verify(s => s.GetGalleryNameById(It.IsAny <string>()), Times.Once);
            mockedService.Verify(s => s.AddVideoToGallery(It.IsAny <string>(), It.IsAny <Video>()), Times.Once);
            mockedService.Verify(s => s.Save(), Times.Once);

            mockedDateProvider.Verify(p => p.GetDate(), Times.Once);

            mockedVideoFactory.Verify(f => f.CreateVideo(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once);
        }
Esempio n. 11
0
        public async Task AddNewVideo(AddVideoViewModel viewModel)
        {
            var category = await _dbContext.Categories
                           .Where(c => c.Id == Guid.Parse(viewModel.CategoryId))
                           .FirstOrDefaultAsync();

            if (category == null)
            {
                throw new ArgumentException("Category does not exists");
            }

            await _dbContext.Videos.AddAsync(new Video
            {
                Category  = category,
                Name      = viewModel.Name,
                YoutubeId = viewModel.YoutubeId
            });

            await _dbContext.SaveChangesAsync();
        }
        public IActionResult AddVideo(AddVideoViewModel addVideoViewModel)
        {
            if (ModelState.IsValid)
            {
                // Add the new video to existing videos

                Video newVideo = new Video
                {
                    Author      = addVideoViewModel.Author,
                    Title       = addVideoViewModel.Title,
                    Url         = addVideoViewModel.Url,
                    Thumbnail   = addVideoViewModel.Thumbnail,
                    ReleaseDays = addVideoViewModel.ReleaseDays
                };

                context.Videos.Add(newVideo);
                context.SaveChanges();

                return(Redirect("/Video"));
            }
            return(View(addVideoViewModel));
        }
        private void SetGalleryNames(AddVideoViewModel model)
        {
            var names = this.videoService.GetAll().ToList();

            model.SetNames(names);
        }