public void SetUp() { repository = new FakeSongListRepository(); userWithSongList = new User("User with songlist", "123", "*****@*****.**", PasswordHashAlgorithms.Default); permissionContext = new FakePermissionContext(new UserWithPermissionsContract(userWithSongList, ContentLanguagePreference.Default)); imagePersister = new InMemoryImagePersister(); queries = new SongListQueries(repository, permissionContext, new FakeEntryLinkFactory(), imagePersister, imagePersister, new FakeUserIconFactory()); song1 = new Song(TranslatedString.Create("Project Diva desu.")) { Id = 1 }; song2 = new Song(TranslatedString.Create("World is Mine")) { Id = 2 }; repository.Add(userWithSongList); repository.Add(song1, song2); songListContract = new SongListForEditContract { Name = "Mikunopolis Setlist", Description = "MIKUNOPOLIS in LOS ANGELES - Hatsune Miku US debut concert held at Nokia Theatre for Anime Expo 2011 on 2nd July 2011.", SongLinks = SongInListEditContracts(song1, song2) }; }
private SongList CreateSongList(IDatabaseContext <SongList> ctx, SongListForEditContract contract, UploadedFileContract uploadedFile) { var user = GetLoggedUser(ctx); var newList = new SongList(contract.Name, user); newList.Description = contract.Description ?? string.Empty; newList.EventDate = contract.EventDate; if (EntryPermissionManager.CanManageFeaturedLists(permissionContext)) { newList.FeaturedCategory = contract.FeaturedCategory; } ctx.Save(newList); var songDiff = newList.SyncSongs(contract.SongLinks, c => ctx.OfType <Song>().Load(c.Song.Id)); ctx.OfType <SongInList>().Sync(songDiff); SetThumb(newList, uploadedFile); ctx.Update(newList); ctx.AuditLogger.AuditLog(string.Format("created song list {0}", entryLinkFactory.CreateEntryLink(newList)), user); var archived = Archive(ctx, newList, new SongListDiff(), EntryEditEvent.Created, contract.UpdateNotes); if (newList.FeaturedList) { AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), newList, EntryEditEvent.Created, archived); } return(newList); }
private SongList CreateSongList(IRepositoryContext <SongList> ctx, SongListForEditContract contract, UploadedFileContract uploadedFile) { var user = GetLoggedUser(ctx); var newList = new SongList(contract.Name, user); newList.Description = contract.Description; if (EntryPermissionManager.CanManageFeaturedLists(permissionContext)) { newList.FeaturedCategory = contract.FeaturedCategory; } ctx.Save(newList); var songDiff = newList.SyncSongs(contract.SongLinks, c => ctx.OfType <Song>().Load(c.SongId)); ctx.OfType <SongInList>().Sync(songDiff); SetThumb(newList, uploadedFile); ctx.Update(newList); ctx.AuditLogger.AuditLog(string.Format("created song list {0}", entryLinkFactory.CreateEntryLink(newList)), user); Archive(ctx, newList, new SongListDiff(), EntryEditEvent.Created); return(newList); }
public ActionResult <int> Post(SongListForEditContract list) { if (list == null) { return(BadRequest()); } return(_queries.UpdateSongList(list, null)); }
public int Post(SongListForEditContract list) { if (list == null) { throw new HttpBadRequestException(); } return(queries.UpdateSongList(list, null)); }
public SongListEdit(SongListForEditContract contract) : this() { ParamIs.NotNull(() => contract); CurrentName = contract.Name; Description = contract.Description; FeaturedCategory = contract.FeaturedCategory; Id = contract.Id; Name = contract.Name; SongLinks = contract.SongLinks; CanCreateFeaturedLists = EntryPermissionManager.CanManageFeaturedLists(MvcApplication.LoginManager); }
public void AddSongToList(int listId, int songId, string newListName = null) { if (listId != 0) { Service.AddSongToList(listId, songId); } else if (!string.IsNullOrWhiteSpace(newListName)) { var contract = new SongListForEditContract { Name = newListName, SongLinks = new[] { new SongInListEditContract { SongId = songId, Order = 1 } } }; songListQueries.UpdateSongList(contract, null); } }
/// <summary> /// Creates a song list. /// </summary> /// <param name="list">Song list properties.</param> /// <returns>int?</returns> public int?SongListApiPost(SongListForEditContract list) { // verify the required parameter 'list' is set if (list == null) { throw new ApiException(400, "Missing required parameter 'list' when calling SongListApiPost"); } var path = "/api/songLists"; path = path.Replace("{format}", "json"); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(list); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling SongListApiPost: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling SongListApiPost: " + response.ErrorMessage, response.ErrorMessage); } return((int?)ApiClient.Deserialize(response.Content, typeof(int?), response.Headers)); }
public void AddSongToList(int listId, int songId, string notes = null, string newListName = null) { if (listId != 0) { Service.AddSongToList(listId, songId, notes ?? string.Empty); } else if (!string.IsNullOrWhiteSpace(newListName)) { var contract = new SongListForEditContract { Name = newListName, SongLinks = new[] { new SongInListEditContract { Song = new SongForApiContract { Id = songId }, Order = 1, Notes = notes ?? string.Empty } } }; _songListQueries.UpdateSongList(contract, null); } }
public int UpdateSongList(SongListForEditContract contract, UploadedFileContract uploadedFile) { ParamIs.NotNull(() => contract); PermissionContext.VerifyPermission(PermissionToken.EditProfile); return(repository.HandleTransaction(ctx => { var user = GetLoggedUser(ctx); SongList list; if (contract.Id == 0) { list = CreateSongList(ctx, contract, uploadedFile); } else { list = ctx.Load(contract.Id); var diff = new SongListDiff(); EntryPermissionManager.VerifyEdit(PermissionContext, list); if (list.Description != contract.Description) { diff.Description.Set(); list.Description = contract.Description ?? string.Empty; } if (list.Name != contract.Name) { diff.Name.Set(); list.Name = contract.Name; } if (EntryPermissionManager.CanManageFeaturedLists(PermissionContext) && list.FeaturedCategory != contract.FeaturedCategory) { diff.FeaturedCategory.Set(); list.FeaturedCategory = contract.FeaturedCategory; } if (list.EventDate != contract.EventDate) { diff.SetChanged(SongListEditableFields.EventDate); list.EventDate = contract.EventDate; } if (list.Status != contract.Status) { diff.Status.Set(); list.Status = contract.Status; } var songDiff = list.SyncSongs(contract.SongLinks, c => ctx.OfType <Song>().Load(c.Song.Id)); if (songDiff.Changed) { diff.Songs.Set(); } ctx.OfType <SongInList>().Sync(songDiff); if (uploadedFile != null) { diff.Thumbnail.Set(); SetThumb(list, uploadedFile); } ctx.Update(list); ctx.AuditLogger.AuditLog( string.Format("updated song list {0} ({1})", entryLinkFactory.CreateEntryLink(list), diff.ChangedFieldsString), user); var archived = Archive(ctx, list, diff, EntryEditEvent.Updated, contract.UpdateNotes); if (list.FeaturedList) { AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), list, EntryEditEvent.Updated, archived); } } return list.Id; })); }