Exemplo n.º 1
0
        public VideoBO Update(VideoBO video)
        {
            using (var uow = facade.UnitOfWork)
            {
                Video vid = uow.VideoRepository.Get(video.ID);
                if (vid != null)
                {
                    var videoUpdated = conv.Convert(video);
                    //uow.VideoRepository.Get(video.ID).Author = video.Author;
                    //uow.VideoRepository.Get(video.ID).Title = video.Title;
                    vid.Author = videoUpdated.Author;
                    vid.Title  = videoUpdated.Title;

                    //uow.VideoRepository.Get(video.ID).Genres = video.Genres;

                    vid.Genres.RemoveAll(vg => !videoUpdated.Genres.Exists(g => g.GenreID == vg.GenreID && g.VideoID == vg.VideoID));

                    videoUpdated.Genres.RemoveAll(vg => vid.Genres.Exists(g => g.GenreID == vg.GenreID && g.VideoID == vg.VideoID));

                    vid.Genres.AddRange(videoUpdated.Genres);

                    uow.Complete();
                    return(conv.Convert(vid));
                }
                else
                {
                    throw new InvalidOperationException("Video not found.");
                }
            }
        }
Exemplo n.º 2
0
 public ActionResult CreateVideo(int id)
 {
     ViewBag.ID = id;
     if (_session.IsLogin)
     {
         Video model = new Video();
         if (id != -1)
         {
             VideoBO cls = new VideoBO();
             model = cls.GetByID(id);
             if (model == null)
             {
                 model = new Video();
             }
             return(View(model));
         }
         else
         {
             return(View(model));
         }
     }
     else
     {
         return(RedirectToAction("index", "admin"));
     }
 }
Exemplo n.º 3
0
 public void CreateVideo(VideoBO v)
 {
     using (var uow = Facade.UnitOfWork) {
         uow.VideoRepository.CreateVideo(conv.Convert(v));
         uow.Complete();
     }
 }
Exemplo n.º 4
0
        internal Video Convert(VideoBO videoBO)
        {
            if (videoBO == null)
            {
                return(null);
            }

            return(new Video()
            {
                Id = videoBO.Id,
                Title = videoBO.Title,
                Genre = videoBO.Genre,
                Duration = videoBO.Duration,

                //? wont do select unless there is something. return null if there s a null
                Producers = videoBO.ProducerIds?.Select(pIds => new VideoProducer()
                {
                    ProducerId = pIds,
                    VideoId = videoBO.Id
                }).ToList()

                            // Producers = videoBO.ProducerIds?.Select(producerId => new CustomerAddress()
                            // {
                            //    ProducerId = producerId,
                            //    VideoId = videoBO.Id
                            //}).ToList(),
            });
        }
Exemplo n.º 5
0
        public ActionResult Video()
        {
            VideoBO cls   = new VideoBO();
            var     model = cls.GetList(m => m.IsActive.Equals(true));

            return(View(model));
        }
Exemplo n.º 6
0
        static void AddCreatedVideo(VideoBO video)
        {
            var newVideo = bllFacade.VideoService.Create(video);

            ShowVideoInformation(newVideo);
            Console.WriteLine($"Video {newVideo.Id} added.");
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var vid1 = new VideoBO
            {
                VideoName = "Gremlins",
                Year      = 1997,
                Genre     = "Horror",
            };
            var vid2 = new VideoBO
            {
                VideoName = "How High",
                Year      = 2007,
                Genre     = "Terrible",
            };

            bllFacade.VideoService.Create(vid1);
            bllFacade.VideoService.Create(vid2);



            string[] menuItems =
            {
                "Show videos",
                "Add a Video",
                "Delete a Video",
                "Edit a Video",
                "Exit"
            };

            var selection = ShowMenu(menuItems);

            while (selection != 5)
            {
                switch (selection)
                {
                case 1:
                    ListVideos();
                    break;

                case 2:
                    AddVideos();
                    break;

                case 3:
                    DeleteVideo();
                    break;

                case 4:
                    EditVideo();
                    break;

                default:
                    Console.WriteLine("Exit..........");
                    break;
                }
                selection = ShowMenu(menuItems);
            }

            Console.ReadLine();
        }
Exemplo n.º 8
0
        public JsonResult SaveVideo(Video video)
        {
            VideoBO cls      = new VideoBO();
            bool    IsResult = cls.Save(video);

            return(Json(new { IsOk = IsResult }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 9
0
        private static VideoBO FindVideoById()
        {
            WriteLine("Enter Q to go back to the menu");
            VideoBO video = null;

            while (video == null)
            {
                int    idSearch;
                string input = ReadLine();

                if (int.TryParse(input, out idSearch))
                {
                    return(bllFacade.VideoService.GetVideoById(idSearch));
                }
                else if (input.ToLower().Equals("q"))
                {
                    break;
                }
                else
                {
                    Write("You have to input the id");
                }
            }
            return(null);
        }
Exemplo n.º 10
0
 private Video Convert(VideoBO vid)
 {
     return(new Video()
     {
         Id = vid.Id,
         Name = vid.Name,
     });
 }
Exemplo n.º 11
0
 public IActionResult Post([FromBody] VideoBO video)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(facade.VideoService.Create(video)));
 }
Exemplo n.º 12
0
 public VideoBO Add(VideoBO video)
 {
     using (var uow = facade.UnitOfWork)
     {
         var vid = uow.VideoRepository.Add(conv.Convert(video));
         uow.Complete();
         return(conv.Convert(vid));
     }
 }
Exemplo n.º 13
0
 public VideoBO Create(VideoBO vid)
 {
     using (var uow = facade.UnitOfWork)
     {
         var newVid = uow.VideoRepository.Create(conv.Convert(vid));
         uow.Complete();
         return(conv.Convert(newVid));
     }
 }
Exemplo n.º 14
0
 public Video Convert(VideoBO vid)
 {
     return(new Video
     {
         Id = vid.Id,
         Name = vid.Name,
         Genre = vid.Genre
     });
 }
Exemplo n.º 15
0
        public void NotPostWithInvalidObject_ReturnBadRequest()
        {
            MockVideoService.Setup(s => s.Create(It.IsAny <VideoBO>())).Returns(new VideoBO());
            var video = new VideoBO();

            _controller.ModelState.AddModelError("", "");
            var result = _controller.Post(video);

            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemplo n.º 16
0
 internal Video Convert(VideoBO vid)
 {
     return(new Video()
     {
         Id = vid.Id,
         VideoLocation = vid.VideoLocation,
         VideoName = vid.VideoName,
         VideoType = vid.VideoType
     });
 }
Exemplo n.º 17
0
 internal Video Convert(VideoBO vid)
 {
     return(new Video()
     {
         Id = vid.Id,
         VideoName = vid.VideoName,
         Genre = vid.Genre,
         VideoDat = vid.VideoDat
     });
 }
Exemplo n.º 18
0
 public VideoBO Create(VideoBO vid)
 {
     //Will automatically call the dispose function at the end
     using (var uow = DALFac.UOW)
     {
         var newVid = uow.VidRepo.Create(Convert(vid));
         uow.Complete();
         return(Convert(newVid));
     }
 }
Exemplo n.º 19
0
 private Video Convert(VideoBO vid)
 {
     return(new Video()
     {
         Id = vid.Id,
         Name = vid.Name,
         Director = vid.Director,
         Duration = vid.Duration
     });
 }
Exemplo n.º 20
0
 internal Video Convert(VideoBO vid)
 {
     return(new Video()
     {
         Id = vid.Id,
         VideoName = vid.VideoName,
         Year = vid.Year,
         Genre = vid.Genre
     });
 }
Exemplo n.º 21
0
 private Video Convert(VideoBO vid)
 {
     return(new Video()
     {
         VideoID = vid.VideoID,
         Title = vid.Title,
         Author = vid.Author,
         Genre = vid.Genre
     });
 }
Exemplo n.º 22
0
 static void ShowVideoInformation(VideoBO video)
 {
     if (video == null)
     {
         Console.WriteLine("The video does not exist. Try again.");
     }
     else
     {
         Console.WriteLine($"{video.Id}   |   {video.Title} | {video.Genre} | {video.Duration}");
     }
 }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            var video1 = new VideoBO()
            {
                Name = "fisk flygter fra brandbil"
            };

            bllFacade.VideoService.Create(video1);

            bllFacade.VideoService.Create(new VideoBO()
            {
                Name = "mand opfinder et nyt for for hjul"
            });

            String[] menuItems =
            {
                "List all Videos",
                "Add Video",
                "Delete Video",
                "Edit Video",
                "Exit\n"
            };

            var selection = ShowMenu(menuItems);

            while (selection != 5)
            {
                switch (selection)
                {
                case 1:
                    ListVideos();
                    break;

                case 2:
                    AddVideos();
                    break;

                case 3:
                    DeleteVideos();
                    break;

                case 4:
                    EditVideos();
                    break;

                default:
                    break;
                }
                selection = ShowMenu(menuItems);
            }
            Console.WriteLine("See ya!");

            Console.ReadLine();
        }
Exemplo n.º 24
0
        public void PostWithValidObject()
        {
            MockVideoService.Setup(s => s.Create(It.IsAny <VideoBO>())).Returns(new VideoBO());

            var video = new VideoBO {
                Id = 1, Title = "Die Hard"
            };
            var result = _controller.Post(video);

            Assert.IsType <CreatedResult>(result);
        }
Exemplo n.º 25
0
 internal Video Convert(VideoBO video)
 {
     if (video == null)
     {
         return(null);
     }
     return(new Video()
     {
         Id = video.Id,
         Name = video.Name,
         //Genre = new GenreConverter().Convert(video.Genre)
     });
 }
Exemplo n.º 26
0
 internal Video Convert(VideoBO vid)
 {
     if (vid == null)
     {
         return(null);
     }
     return(new Video()
     {
         Id = vid.Id,
         Title = vid.Title,
         GenreId = vid.Genre != null ? vid.Genre.Id : vid.GenreId
     });
 }
Exemplo n.º 27
0
 public VideoBO Create(VideoBO video)
 {
     if (video == null)
     {
         return(null);
     }
     using (var unitOfWork = _facade.UnitOfWork)
     {
         var createdVideo = unitOfWork.VideoRepository.Create(_converter.Convert(video));
         unitOfWork.Complete();
         return(_converter.Convert(createdVideo));
     }
 }
Exemplo n.º 28
0
 internal Video Convert(VideoBO video)
 {
     if (video == null)
     {
         return(null);
     }
     return(new Video()
     {
         Title = video.Title,
         Id = video.Id,
         PricePeDay = video.PricePeDay
     });
 }
Exemplo n.º 29
0
 internal Video Convert(VideoBO vid)
 {
     if (vid == null)
     {
         return(null);
     }
     return(new Video()
     {
         Id = vid.Id,
         Name = vid.Name,
         GenreId = vid.GenreId
     });
 }
Exemplo n.º 30
0
 internal Video Convert(VideoBO vid)
 {
     if (vid == null)
     {
         return(null);
     }
     return(new Video()
     {
         Id = vid.Id,
         Genre = vid.Genre,
         Title = vid.Title,
         PricePerDay = vid.PricePerDay
     });
 }
Exemplo n.º 31
0
 public JsonResult GetVideo()
 {
     if (_session.IsLogin)
     {
         string jsonData = "[]";
         VideoBO _cls = new VideoBO();
         var data = _cls.GetAll();
         if (data != null)
             jsonData = new JavaScriptSerializer().Serialize(data);
         return Json(jsonData, JsonRequestBehavior.AllowGet);
     }
     else
         RedirectToAction("index", "admin");
     return Json("[]", JsonRequestBehavior.AllowGet);
 }
 private void RemoverVideo(DirectEventArgs e)
 {
     try
     {
         VideoVO video = new VideoBO().SelectById(e.ExtraParams["id"].ToInt32());
         new VideoBO(video).DeleteUpdate();
         LoadPagina();
     }
     catch (Exception ex)
     {
         base.MostrarMensagem("Erro", "Erro ao tentar remover video.", "");
     }
 }
Exemplo n.º 33
0
 public ActionResult CreateVideo(int id)
 {
     ViewBag.ID = id;
     if (_session.IsLogin)
     {
         Video model = new Video();
         if (id != -1)
         {
             VideoBO cls = new VideoBO();
             model = cls.GetByID(id);
             if (model == null)
                 model = new Video();
             return View(model);
         }
         else
             return View(model);
     }
     else
         return RedirectToAction("index", "admin");
 }
Exemplo n.º 34
0
 public JsonResult DeleteVideo(int id)
 {
     if (_session.IsLogin)
     {
         VideoBO _cls = new VideoBO();
         var IsResult = _cls.Delete(id);
         return Json(new { IsOk = IsResult }, JsonRequestBehavior.AllowGet);
     }
     else
         RedirectToAction("index", "admin");
     return Json(new { IsOk = false }, JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 35
0
 public ActionResult Video()
 {
     VideoBO cls = new VideoBO();
     var model = cls.GetList(m => m.IsActive.Equals(true));
     return View(model);
 }
Exemplo n.º 36
0
 public JsonResult SaveVideo(Video video)
 {
     VideoBO cls = new VideoBO();
     bool IsResult = cls.Save(video);
     return Json(new { IsOk = IsResult }, JsonRequestBehavior.AllowGet);
 }