public JsonResult CreateMultiple(List <PlaylistItemDto> playlistItemDtos) { List <PlaylistItemDto> savedPlaylistItemDtos; int count = playlistItemDtos.Count; if (count > 1000) { Session.SetBatchSize(count / 10); } else if (count > 3) { Session.SetBatchSize(count / 3); } using (ITransaction transaction = Session.BeginTransaction()) { List <PlaylistItem> playlistItems = PlaylistItem.Create(playlistItemDtos, PlaylistManager); // Split items into their respective playlists and then save on each. foreach (var playlistGrouping in playlistItems.GroupBy(i => i.Playlist)) { List <PlaylistItem> groupingItems = playlistGrouping.ToList(); playlistGrouping.Key.AddItems(groupingItems); PlaylistItemManager.Save(groupingItems); } savedPlaylistItemDtos = PlaylistItemDto.Create(playlistItems); transaction.Commit(); } return(Json(savedPlaylistItemDtos)); }
public ActionResult UpdateMultiple(List <PlaylistItemDto> playlistItemDtos) { List <PlaylistItemDto> savedPlaylistItemDtos; int count = playlistItemDtos.Count; if (count > 1000) { Session.SetBatchSize(count / 10); } else if (count > 3) { Session.SetBatchSize(count / 3); } using (ITransaction transaction = Session.BeginTransaction()) { List <PlaylistItem> playlistItems = PlaylistItem.Create(playlistItemDtos, PlaylistManager); PlaylistItemManager.Update(playlistItems); savedPlaylistItemDtos = PlaylistItemDto.Create(playlistItems); transaction.Commit(); } return(Json(savedPlaylistItemDtos)); }
/// <summary> /// Create a new Playlist, save it to the DB, then generate N PlaylistItemDtos /// which have the Playlist as their parent. /// </summary> public static List <PlaylistItemDto> CreatePlaylistItemsDto(int itemsToCreate, Guid playlistId = default(Guid)) { if (playlistId == default(Guid)) { User user = CreateUser(); playlistId = user.Playlists.First().Id; } Video video = CreateUnsavedVideoWithId(); VideoDto videoDto = VideoDto.Create(video); List <PlaylistItemDto> playlistItemDtos = new List <PlaylistItemDto>(); for (int i = 0; i < itemsToCreate; i++) { var playlistItemDto = new PlaylistItemDto { PlaylistId = playlistId, Video = videoDto }; playlistItemDtos.Add(playlistItemDto); } return(playlistItemDtos); }
public ActionResult UpdateMultiple(List <PlaylistItemDto> playlistItemDtos) { List <PlaylistItem> playlistItems = PlaylistItem.Create(playlistItemDtos); PlaylistItemManager.Update(playlistItems); List <PlaylistItemDto> savedPlaylistItemDtos = PlaylistItemDto.Create(playlistItems); return(new JsonDataContractActionResult(savedPlaylistItemDtos)); }
public ActionResult Update(PlaylistItemDto playlistItemDto) { PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto); PlaylistItemManager.Update(playlistItem); PlaylistItemDto updatedPlaylistItemDto = PlaylistItemDto.Create(playlistItem); return(new JsonDataContractActionResult(updatedPlaylistItemDto)); }
public ActionResult Update(PlaylistItemDto playlistItemDto) { PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto); PlaylistItemManager.Update(playlistItem); PlaylistItemDto updatedPlaylistItemDto = PlaylistItemDto.Create(playlistItem); return(new JsonServiceStackResult(updatedPlaylistItemDto)); }
public void Patch(Guid id, PlaylistItemDto playlistItemDto) { using (ITransaction transaction = Session.BeginTransaction()) { PlaylistItem playlistItem = PlaylistItemManager.Get(id); playlistItemDto.SetPatchableProperties(playlistItem); PlaylistItemManager.Update(playlistItem); transaction.Commit(); } }
/// <summary> /// Create a new Playlist, save it to the DB, then generate a PlaylistItemDto /// which has the Playlist as its parent. /// </summary> public PlaylistItemDto CreatePlaylistItemDto() { User user = CreateUser(); PlaylistItem playlistItem = CreateUnsavedPlaylistItem(); var playlistItemDto = PlaylistItemDto.Create(playlistItem); playlistItemDto.PlaylistId = user.Playlists.First().Id; return(playlistItemDto); }
public JsonDataContractActionResult Create(PlaylistItemDto playlistItemDto) { PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto); playlistItem.Playlist.AddItem(playlistItem); PlaylistItemManager.Save(playlistItem); PlaylistItemDto savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem); return(new JsonDataContractActionResult(savedPlaylistItemDto)); }
public JsonServiceStackResult Create(PlaylistItemDto playlistItemDto) { PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto); playlistItem.Playlist.AddItem(playlistItem); PlaylistItemManager.Save(playlistItem); PlaylistItemDto savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem); return(new JsonServiceStackResult(savedPlaylistItemDto)); }
public IEnumerable <PlaylistItemDto> CreateMultiple(List <PlaylistItemDto> playlistItemDtos) { List <PlaylistItemDto> savedPlaylistItemDtos; int count = playlistItemDtos.Count; if (count > 1000) { Session.SetBatchSize(count / 10); } else if (count > 500) { Session.SetBatchSize(count / 5); } else if (count > 2) { Session.SetBatchSize(count / 2); } using (ITransaction transaction = Session.BeginTransaction()) { List <PlaylistItem> savedPlaylistItems = new List <PlaylistItem>(); // Split items into their respective playlists and then save on each. foreach (var playlistGrouping in playlistItemDtos.GroupBy(pid => pid.PlaylistId)) { List <PlaylistItemDto> groupedPlaylistItemDtos = playlistGrouping.ToList(); Playlist playlist = PlaylistManager.Get(playlistGrouping.Key); foreach (var playlistItemDto in groupedPlaylistItemDtos) { SongDto songDto = playlistItemDto.Song; PlaylistItem playlistItem = new PlaylistItem(playlistItemDto.Id, playlistItemDto.Title, playlistItemDto.Cid, songDto.Id, songDto.Type, songDto.Title, songDto.Duration, songDto.Author); playlistItemDto.SetPatchableProperties(playlistItem); playlist.AddItem(playlistItem); savedPlaylistItems.Add(playlistItem); } } PlaylistItemManager.Save(savedPlaylistItems); savedPlaylistItemDtos = PlaylistItemDto.Create(savedPlaylistItems); transaction.Commit(); } return(savedPlaylistItemDtos); }
public void CreatePlaylistItem_PlaylistItemDoesntExist_PlaylistItemCreated() { PlaylistItemDto playlistItemDto = Helpers.CreatePlaylistItemDto(); var createdPlaylistItemDto = PlaylistItemController.Create(playlistItemDto); // Make sure we actually get a PlaylistItem DTO back from the Controller. Assert.NotNull(createdPlaylistItemDto); Playlist playlist = PlaylistManager.Get(createdPlaylistItemDto.PlaylistId); // Make sure that the created playlistItem was cascade added to the Playlist Assert.That(playlist.Items.Count(i => i.Id == createdPlaylistItemDto.Id) == 1); }
public static PlaylistItem Create(PlaylistItemDto playlistItemDto, IPlaylistManager playlistManager) { PlaylistItem playlistItem = new PlaylistItem { Cid = playlistItemDto.Cid, Id = playlistItemDto.Id, Playlist = playlistManager.Get(playlistItemDto.PlaylistId), Sequence = playlistItemDto.Sequence, Title = playlistItemDto.Title, Video = Video.Create(playlistItemDto.Video) }; return(playlistItem); }
/// <summary> /// Create a new Folder and Playlist, save them to the DB, then generate a PlaylistItemDto /// which has those entities as its parents. /// </summary> public static PlaylistItemDto CreatePlaylistItemDto() { Guid playlistId = UserManager.CreateUser().Folders.First().Playlists.First().Id; Video video = CreateUnsavedVideoWithId(); VideoDto videoDto = VideoDto.Create(video); var playlistItemDto = new PlaylistItemDto { PlaylistId = playlistId, Video = videoDto }; return(playlistItemDto); }
private async Task <PlaylistItem> GetPlaylistItem(PlaylistItemDto playlistItemDto) { var contentId = new ContentId( playlistItemDto.ExternalId, playlistItemDto.ContentSource, playlistItemDto.ContentType); var content = await _contentRepository.GetAsync(contentId, CancellationToken.None); return(new PlaylistItem( contentId, playlistItemDto.PlaylistItemIndex, content.Title, content.Description)); }
public ActionResult Update(PlaylistItemDto playlistItemDto) { PlaylistItemDto updatedPlaylistItemDto; using (ITransaction transaction = Session.BeginTransaction()) { PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto, PlaylistManager); PlaylistItemManager.Update(playlistItem); updatedPlaylistItemDto = PlaylistItemDto.Create(playlistItem); transaction.Commit(); } return(Json(updatedPlaylistItemDto)); }
public void PatchPlaylistItem_SequenceProvided_SequenceModified() { PlaylistItemDto playlistItemDto = Helpers.CreatePlaylistItemDto(); var createdPlaylistItemDto = PlaylistItemController.Create(playlistItemDto); const double newSequence = 5; PlaylistItemDto patchedPlaylistItemDto = new PlaylistItemDto { Sequence = newSequence }; PlaylistItem playlistItem = PlaylistItemManager.Get(createdPlaylistItemDto.Id); PlaylistItemController.Patch(playlistItem.Id, patchedPlaylistItemDto); Assert.AreEqual(playlistItem.Sequence, newSequence); }
/// <summary> /// Create a new Playlist, save it to the DB, then generate a PlaylistItemDto /// which has the Playlist as its parent. /// </summary> public PlaylistItemDto CreatePlaylistItemDto() { User user = CreateUser(); Guid playlistId = user.Playlists.First().Id; Video video = CreateUnsavedVideoWithId(); VideoDto videoDto = VideoDto.Create(video); var playlistItemDto = new PlaylistItemDto { PlaylistId = playlistId, Video = videoDto }; return(playlistItemDto); }
public void CreatePlaylistItem_PlaylistItemDoesntExist_PlaylistItemCreated() { PlaylistItemDto playlistItemDto = Helpers.CreatePlaylistItemDto(); var result = PlaylistItemController.Create(playlistItemDto); var createdPlaylistItemDto = (PlaylistItemDto)result.Data; // Make sure we actually get a PlaylistItem DTO back from the Controller. Assert.NotNull(createdPlaylistItemDto); NHibernateSessionManager.Instance.Clear(); Playlist playlist = PlaylistDao.Get(createdPlaylistItemDto.PlaylistId); // Make sure that the created playlistItem was cascade added to the Playlist Assert.That(playlist.Items.Count(i => i.Id == createdPlaylistItemDto.Id) == 1); }
public void DeletePlaylistItem_ItemExistsInPlaylist_DeletedSuccessfully() { PlaylistItemDto playlistItemDto = Helpers.CreatePlaylistItemDto(); var result = PlaylistItemController.Create(playlistItemDto); var createdPlaylistItemDto = (PlaylistItemDto)result.Data; // Make sure we actually get a PlaylistItem DTO back from the Controller. Assert.NotNull(createdPlaylistItemDto); Playlist playlist = PlaylistManager.Get(createdPlaylistItemDto.PlaylistId); // Make sure that the created playlistItem was cascade added to the Playlist Assert.That(playlist.Items.Count(i => i.Id == createdPlaylistItemDto.Id) == 1); PlaylistItemController.Delete(createdPlaylistItemDto.Id); }
public JsonDataContractActionResult CreateMultiple(List <PlaylistItemDto> playlistItemDtos) { List <PlaylistItem> playlistItems = PlaylistItem.Create(playlistItemDtos); // Split items into their respective playlists and then save on each. foreach (var playlistGrouping in playlistItems.GroupBy(i => i.Playlist)) { List <PlaylistItem> groupingItems = playlistGrouping.ToList(); Playlist playlist = groupingItems.First().Playlist; playlist.AddItems(groupingItems); PlaylistItemManager.Save(groupingItems); } List <PlaylistItemDto> savedPlaylistItemDtos = PlaylistItemDto.Create(playlistItems); return(new JsonDataContractActionResult(savedPlaylistItemDtos)); }
public JsonResult Create(PlaylistItemDto playlistItemDto) { PlaylistItemDto savedPlaylistItemDto; using (ITransaction transaction = Session.BeginTransaction()) { PlaylistItem playlistItem = PlaylistItem.Create(playlistItemDto, PlaylistManager); playlistItem.Playlist.AddItem(playlistItem); PlaylistItemManager.Save(playlistItem); savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem); transaction.Commit(); } return(Json(savedPlaylistItemDto)); }
public async Task <HttpResponseMessage> PostAsync(int playlistId, [FromBody] PlaylistItemDto model, CancellationToken cancellationToken) { var playlist = await _services.Media.FindByIdAsync(playlistId, cancellationToken); if (playlist == null) { return(Request.CreateFaultResponse(HttpStatusCode.NotFound, "Playlist was not found.")); } if (ProjectIdentity == null || ProjectIdentity.Id != playlist.ContactId) { return(Request.CreateFaultResponse(HttpStatusCode.Forbidden, "Playlist has already been taken.")); } if (ModelState.IsValid) { var entity = new MediaPlaylistItem { PlaylistId = playlistId, Name = model.Name, MediaType = model.MediaType, MediaId = model.MediaId, Duration = model.Duration, PublishDate = model.PublishDate }; await _services.Media.AddItemAsync(entity, cancellationToken); await _services.SaveAsync(cancellationToken); var result = new MediaPlaylistItemResult { Id = entity.Id, SortOrderId = entity.SortOrderId, Name = entity.Name, MediaType = entity.MediaType, MediaId = entity.MediaId, Duration = entity.Duration, PublishDate = entity.PublishDate }; return(Request.CreateResponse(HttpStatusCode.Created, result)); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
/// <summary> /// Create a new Playlist, save it to the DB, then generate N PlaylistItemDtos /// which have the Playlist as their parent. /// </summary> public List <PlaylistItemDto> CreatePlaylistItemsDto(int itemsToCreate, Guid playlistId = default(Guid)) { if (playlistId == default(Guid)) { User user = CreateUser(); playlistId = user.Playlists.First().Id; } PlaylistItem playlistItem = CreateUnsavedPlaylistItem(); List <PlaylistItemDto> playlistItemDtos = new List <PlaylistItemDto>(); for (int i = 0; i < itemsToCreate; i++) { var playlistItemDto = PlaylistItemDto.Create(playlistItem); playlistItemDto.PlaylistId = playlistId; playlistItemDtos.Add(playlistItemDto); } return(playlistItemDtos); }
public PlaylistItemDto Create(PlaylistItemDto playlistItemDto) { PlaylistItemDto savedPlaylistItemDto; using (ITransaction transaction = Session.BeginTransaction()) { Playlist playlist = PlaylistManager.Get(playlistItemDto.PlaylistId); SongDto songDto = playlistItemDto.Song; PlaylistItem playlistItem = new PlaylistItem(playlistItemDto.Id, playlistItemDto.Title, playlistItemDto.Cid, songDto.Id, songDto.Type, songDto.Title, songDto.Duration, songDto.Author); playlistItemDto.SetPatchableProperties(playlistItem); playlist.AddItem(playlistItem); PlaylistItemManager.Save(playlistItem); savedPlaylistItemDto = PlaylistItemDto.Create(playlistItem); transaction.Commit(); } return(savedPlaylistItemDto); }
public static PlaylistItem Create(PlaylistItemDto playlistItemDto) { PlaylistItem playlistItem = Mapper.Map <PlaylistItemDto, PlaylistItem>(playlistItemDto); return(playlistItem); }