public BOVideo Update(BOVideo vid) { using (var uow = facade.UnitOfWork) { var customerFromDb = uow.VideoRepository.Get(vid.Id); // ????? if (customerFromDb == null) { throw new InvalidOperationException("Video not found"); } var videoUpdated = con.Convert(vid); customerFromDb.Title = vid.Title; customerFromDb.About = vid.About; customerFromDb.Owner = vid.Owner; customerFromDb.Address = vid.Address; customerFromDb.Genres = videoUpdated.Genres; //1. Remove All, except the "old" ids we wanna keep (Avoid attached issues) //2. Remove All ids already in database from videoUpdated //3. Add All new VideoGenre not yet seen in the DB uow.Complete(); return(con.Convert(customerFromDb)); } }
public IActionResult Post([FromBody] BOVideo video) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(facade.VideoService.Create(video))); }
public BOVideo Create(BOVideo vid) { using (var uow = facade.UnitOfWork) // using keyword is calling the disposable. Once it exited the curly braces then it will aut. dispose. { var Video = uow.VideoRepository.Create(con.Convert(vid)); uow.Complete(); return(con.Convert(Video)); } }
internal Video Convert(BOVideo videoo) { return(new Video() { Id = videoo.Id, Title = videoo.Title, About = videoo.About, Owner = videoo.Owner }); }
public IActionResult Put(int id, [FromBody] BOVideo video) { if (id != video.Id) { return(StatusCode(405, "Path Id didn't match the Customer's Id in json object")); } try { var videos = facade.VideoService.Update(video); return(Ok(videos)); } catch (Exception e) { return(StatusCode(404, e.Message)); } }
public BOVideo Update(BOVideo cust) { using (var uow = facade.UnitOfWork) { var customerFromDb = uow.VideoRepository.Get(cust.Id); // ????? if (customerFromDb == null) { throw new InvalidOperationException("Video not found"); } customerFromDb.Title = cust.Title; customerFromDb.About = cust.About; customerFromDb.Owner = cust.Owner; uow.Complete(); return(con.Convert(customerFromDb)); } }
internal Video Convert(BOVideo videoo) { if (videoo == null) { return(null); } return(new Video() { Id = videoo.Id, Genres = videoo.Genres?.Select(a => new VideoGenre() { GenreId = a.Id, VideoId = videoo.Id }).ToList(), Title = videoo.Title, About = videoo.About, Owner = videoo.Owner, Address = videoo.Address }); }
public void Post([FromBody] BOVideo video) { }
static void Main(string[] args) { var cust1 = new BOVideo() { Title = "awesome video", About = "c#", Owner = "Robie" }; bllFacade.VideoService.Create(cust1); bllFacade.VideoService.Create(new BOVideo() { Title = "Second video", About = "database", Owner = "Finnur" }); Console.WriteLine($" Id: {cust1.Id} Title: {cust1.Title} About: {cust1.About} Owner: {cust1.Owner}"); string[] menuItems = { "List of videos", "Add video", "Edit video", "Delete video", "Search video", "exit" }; //show menu //wait for selection or // warning and go back to menu var selection = showMenu(menuItems); while (selection != 6) { switch (selection) { case 1: VideosList(); break; case 2: AddCustomers(); break; case 3: EditCostumers(); break; case 4: DeleteCustomers(); break; case 5: SearchVideo(); break; default: break; } selection = showMenu(menuItems); } WriteLine("Bye"); ReadLine(); }