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)); }
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 <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)); }
/// <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 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 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 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)); }
/// <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); }