Esempio n. 1
0
        public AlbumContract AcceptImportedAlbum(ImportedAlbumOptions importedAlbum, int[] selectedSongIds)
        {
            PermissionContext.VerifyPermission(PermissionToken.MikuDbImport);

            return HandleTransaction(session => {

                var inspected = Inspect(session, importedAlbum);
                var album = AcceptImportedAlbum(session, importedAlbum.SelectedLanguage, inspected, selectedSongIds);

                return album;

            });
        }
        public ActionResult AcceptImported(InspectedAlbum album, string commit)
        {
            if (commit != "Accept") {

                //var options = albums.Select(a => new ImportedAlbumOptions(a)).ToArray();
                var options = new ImportedAlbumOptions(album);
                var inspectResult = Service.Inspect(options);

                return View("PrepareForImport", inspectResult);

            }

            var ids = new ImportedAlbumOptions(album);
            var selectedSongIds = (album.Tracks != null ? album.Tracks.Where(t => t.Selected).Select(t => t.ExistingSong.Id).ToArray() : new int[] { });

            Service.AcceptImportedAlbum(ids, selectedSongIds);

            TempData.SetSuccessMessage("Imported album approved successfully.");

            return RedirectToAction("Index");
        }
Esempio n. 3
0
		public InspectedAlbum Inspect(ImportedAlbumOptions importedAlbum) {

			ParamIs.NotNull(() => importedAlbum);

			return HandleQuery(session => Inspect(session, importedAlbum));

		}
Esempio n. 4
0
		public AlbumContract[] AcceptImportedAlbums(ImportedAlbumOptions[] importedAlbumIds, int[] selectedSongIds) {

			PermissionContext.VerifyPermission(PermissionToken.MikuDbImport);

			return HandleTransaction(session => {

				var importedAlbums = new List<AlbumContract>(importedAlbumIds.Length);

				foreach (var importedAlbum in importedAlbumIds) {

					var inspected = Inspect(session, importedAlbum);
					var album = AcceptImportedAlbum(session, importedAlbum.SelectedLanguage, inspected, selectedSongIds);

					importedAlbums.Add(album);

				}

				return importedAlbums.ToArray();

			});

		}
Esempio n. 5
0
		private InspectedAlbum Inspect(ISession session, MikuDbAlbum imported, ImportedAlbumOptions options) {

			Album albumMatch;
			var foundAlbums = FindAlbums(session, imported);
			switch (options.MergedAlbumId) {
				case null:
					albumMatch = foundAlbums.FirstOrDefault();
					break;
				case 0:
					albumMatch = null;
					break;
				default:
					albumMatch = session.Load<Album>(options.MergedAlbumId);
					if (!foundAlbums.Contains(albumMatch))
						foundAlbums.Add(albumMatch);
					break;
			}

			var importedContract = new MikuDbAlbumContract(imported);
			var data = importedContract.Data;

			var artists = data.ArtistNames.Concat(data.VocalistNames).Concat(!string.IsNullOrEmpty(data.CircleName) ? new[] { data.CircleName } : new string[] {})
				.Select(a => InspectArtist(session, a))
				.ToArray();

			var matchedArtists = artists.Where(a => a.ExistingArtist != null).Select(a => a.ExistingArtist).ToArray();

			var tracks = data.Tracks.Select(t => InspectTrack(session, t, matchedArtists, albumMatch)).ToArray();

			var result = new InspectedAlbum(importedContract);
			result.MergeTracks = options.MergeTracks ?? true;

			if (albumMatch != null) {
				result.MergedAlbum = new AlbumContract(albumMatch, PermissionContext.LanguagePreference);
				result.MergedAlbumId = albumMatch.Id;
			}

			result.ExistingAlbums = foundAlbums.Select(a => new AlbumContract(a, PermissionContext.LanguagePreference))
				.Concat(new[] { new AlbumContract { Name = "Nothing" } }).ToArray();

			result.Artists = artists.Select(a => a.InspectedArtist).ToArray();
			result.Tracks = tracks;

			return result;

		}
Esempio n. 6
0
		private InspectedAlbum Inspect(ISession session, ImportedAlbumOptions options) {

			var imported = session.Load<MikuDbAlbum>(options.ImportedDbAlbumId);

			return Inspect(session, imported, options);

		}
Esempio n. 7
0
		private InspectedAlbum[] Inspect(ISession session, ImportedAlbumOptions[] importedAlbumIds) {

			return importedAlbumIds.Select(a => Inspect(session, a)).ToArray();

		}