Example #1
0
        public async Task <ActionResult> ImportMidis(string musicFolderPath = "C:\\music\\midi")
        {
            try
            {
                var styles = Directory.GetDirectories(musicFolderPath);
                foreach (var stylePath in styles)
                {
                    var   styleName = FileSystemUtils.GetLastDirectoryName(stylePath);
                    Style style     = await SongRepository.GetStyleByName(styleName);

                    if (style == null)
                    {
                        style = new Style()
                        {
                            Name = styleName
                        };
                        await SongRepository.AddStyle(style);
                    }
                    var bandsPaths = Directory.GetDirectories(stylePath);
                    foreach (var bandPath in bandsPaths)
                    {
                        var  bandName = FileSystemUtils.GetLastDirectoryName(bandPath);
                        Band band     = await SongRepository.GetBandByName(bandName);

                        if (band == null)
                        {
                            band = new Band()
                            {
                                Name  = bandName,
                                Style = style
                            };
                            await SongRepository.AddBand(band);
                        }
                        var songsPaths = Directory.GetFiles(bandPath);
                        foreach (var songPath in songsPaths)
                        {
                            var songita = await SongRepository.GetSongByNameAndBand(Path.GetFileName(songPath), bandName);

                            if (songita == null)
                            {
                                await ProcesameLaSong(songPath, band, style);
                            }
                        }
                    }
                }
            }
            catch (Exception soreton)
            {
                Log.Error(soreton, $"Exception raised when running ImportMidis");
                return(new StatusCodeResult(500));
            }
            return(Ok(new ApiOKResponse("All files processed")));
        }
        public async Task <ActionResult> PostStyle(Style style)
        {
            if (ModelState.IsValid)
            {
                var stylete = await SongRepository.AddStyle(style);

                return(Ok(new ApiOKResponse(stylete)));
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse(ModelState)));
            }
        }