public ActionResult AddTvShow(FormCollection collection, IPrincipal iuser) { int seasonId; try { seasonId = Convert.ToInt32(collection["Season"]); } catch (FormatException) { return(View("NotFound")); } Season season = MediaService.Instance.GetSeasonById(seasonId); UserTV_Show userTvShow = new UserTV_Show(); userTvShow.Season = season; User user = MembershipDao.Instance.GetCurrentUser(iuser.Identity.Name); userTvShow.User = user; userTvShow.MediaStatus = Models.UserMediaStatusEnum.NichtVerborgt.ToString(); userTvShow.StoragePlace = collection["Storage"]; userTvShow.StorageType = collection["Device"]; UserMediaService.Instance.AddTvShow(userTvShow); return(RedirectToAction("TVShow", "Media", new { id = season.TV_Show.Id })); }
public static UserTV_Show generateUserTV_Show(Season season) { UserTV_Show userTV_Show = new UserTV_Show(); userTV_Show.Season = season; userTV_Show.StorageType = "BlueRay"; userTV_Show.StoragePlace = "Arbeitszimmer"; userTV_Show.MediaStatus = "NichtVerborgt"; return(userTV_Show); }
public static UserTV_Show generateUserTV_Show() { UserTV_Show userTV_Show = new UserTV_Show(); userTV_Show.Season = new Season { Number = 1, Id = 666, TV_Show = generateTV_Show(false) }; userTV_Show.StorageType = "BlueRay"; userTV_Show.StoragePlace = "Arbeitszimmer"; userTV_Show.MediaStatus = "NichtVerborgt"; return(userTV_Show); }
protected void AddUserTV_Shows(int count) { MediaLibContainer context = ContextHelper <MediaLibContainer> .GetCurrentContext(); for (int i = 1; i <= count; i++) { UserTV_Show userTV_Show = TestUtil.generateUserTV_Show(); userTV_Show.User = context.UserSet.First <User>(); userTV_Show.Season.TV_Show = context.MediaSet.OfType <TV_Show>().First <TV_Show>(); context.UserMediaSet.AddObject(userTV_Show); addedUserMedia.Add(userTV_Show); } context.SaveChanges(); }
public void DeleteTvShowShouldReturnNotAuthorizedView() { AddUserTV_Shows(2); MediaLibContainer context = ContextHelper <MediaLibContainer> .GetCurrentContext(); UserTV_Show userTV_Show = context.UserMediaSet.OfType <UserTV_Show>().First <UserTV_Show>(); MediathekController mediathekController = new MediathekController(userMediaService); IPrincipal notOwner = new GenericPrincipal(new GenericIdentity("notOwner", "Forms"), null); ViewResult result = mediathekController.DeleteTvShow(userTV_Show.Id, notOwner) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("NotAuthorized", result.ViewName); }
public IQueryable <UserTV_Show> GetTvShowByUserMedia(UserTV_Show media) { var medien = UserTvShowDaoEF.Instance.GetByUserMedia(media); if (!media.Season.TV_Show.Title.Equals(string.Empty)) { medien = medien.Where(r => r.Season.TV_Show.Title.Contains(media.Season.TV_Show.Title)); } if (media.Season.Number != 0) { medien = medien.Where(r => r.Season.Number == media.Season.Number); } if (!media.StorageType.Equals(string.Empty)) { medien = medien.Where(r => r.StorageType.Equals(media.StorageType)); } return(medien); }
public ActionResult DeleteTvShow(int id, IPrincipal user) { UserTV_Show userTvShow = userMediaService.GetTvShowById(id); if (userTvShow == null) { return(View("NotFound")); } TV_Show tvShow = userTvShow.Season.TV_Show; if (userTvShow.User.Username != user.Identity.Name) { return(View("NotAuthorized")); } userMediaService.DeleteTvShow(userTvShow); return(RedirectToAction("TVShow", "Media", new { id = tvShow.Id })); }
public void DeleteTvShowShouldReturnRedirectToResult() { AddUserTV_Shows(3); MediaLibContainer context = ContextHelper <MediaLibContainer> .GetCurrentContext(); UserTV_Show userTV_Show = context.UserMediaSet.OfType <UserTV_Show>().First <UserTV_Show>(); int expectedTV_ShowId = userTV_Show.Season.TV_Show.Id; MediathekController mediathekController = new MediathekController(); RedirectToRouteResult result = mediathekController.DeleteTvShow(userTV_Show.Id, fakeUser) as RedirectToRouteResult; addedUserMedia.Remove(userTV_Show); Assert.IsNotNull(result); object tv_ShowId; Assert.IsTrue(result.RouteValues.TryGetValue("id", out tv_ShowId)); Assert.AreEqual(expectedTV_ShowId, (int)tv_ShowId); }
public static void ClassInitialize(TestContext testContext) { userBook = TestUtil.generateUserBook(); userBook.Book.Id = 4; userBook.Id = 1; userMovie = TestUtil.generateUserMovie(); userMovie.Movie.Id = 5; userMovie.Id = 2; userTV_Show = TestUtil.generateUserTV_Show(); userTV_Show.Season.Id = 6; userTV_Show.Id = 3; user = new User(); user.Username = "******"; userBook.User = user; userMovie.User = user; userTV_Show.User = user; fakeUser = new GenericPrincipal(new GenericIdentity(user.Username, "Forms"), null); }
public PartialViewResult FilterUserTvShow(string username, FormCollection collection, IPrincipal user) { UserTV_Show show = new UserTV_Show(); show.Season = new Season(); show.Season.TV_Show = new TV_Show(); show.Season.TV_Show.Title = collection["TitleBox"]; string seasonNr = collection["SeasonList"]; string borrowedFrom = collection["BorrowedFromCheckBox"]; string borrowedTo = collection["BorrowedToCheckBox"]; string finalUsername = string.Empty; if (!seasonNr.Equals(string.Empty)) { show.Season.Number = Int32.Parse(seasonNr); } if (username == null) { finalUsername = user.Identity.Name; } else { finalUsername = username; } show.User = MembershipService.Instance.GetCurrentUser(finalUsername); List <BorrowedDetails> borrowedShows = new List <BorrowedDetails>(); foreach (var i in UserMediaService.Instance.GetAllBorrowedFromMediaByUser(finalUsername).ToList()) { if (i.UserMedia.GetType() == typeof(UserTV_Show) && i.DateOfReturn > DateTime.Now) { borrowedShows.Add(i); } } if (borrowedTo.Contains("true")) { show.MediaStatus = UserMediaStatusEnum.Verborgt.ToString(); } show.StoragePlace = collection["StoragePlaceList"]; show.StorageType = collection["TypeList"]; List <UserMedia> shows = new List <UserMedia>(); if (borrowedFrom.Equals("false")) { shows.AddRange(UserMediaService.Instance.GetTvShowByUserMedia(show).ToList()); } if (borrowedTo.Equals("false")) { List <UserMedia> borrowedUserShows = new List <UserMedia>(); List <BorrowedDetails> finalBorrowList = new List <BorrowedDetails>(); foreach (var sh in borrowedShows) { show.User = null; borrowedUserShows.AddRange(UserMediaService.Instance.GetTvShowByUserMedia(show).ToList()); foreach (var b in borrowedUserShows) { if (sh.UserMedia.Id == b.Id) { finalBorrowList.Add(sh); } } } ProfileMediaViewModel model = new ProfileMediaViewModel(shows, user.Identity.Name, finalBorrowList); return(PartialView("../User/UserTvShowView", model)); } ProfileMediaViewModel modelWithoutBorrowed = new ProfileMediaViewModel(shows, user.Identity.Name, new List <BorrowedDetails>()); return(PartialView("../User/UserTvShowView", modelWithoutBorrowed)); }
public void DeleteTvShow(UserTV_Show media) { UserTvShowDaoEF.Instance.Delete(media); }
public void AddTvShow(UserTV_Show media) { UserTvShowDaoEF.Instance.Add(media); }