#103: Added method to create song and moving some code around

This commit is contained in:
kdeng00
2024-08-06 19:51:50 -04:00
parent 77030c6347
commit b3b5a975d9
6 changed files with 66 additions and 4 deletions
+32
View File
@@ -112,6 +112,27 @@ public class Song
return includeExtension ? $"{filename}{extension}" : filename;
}
public CreateSongResult Create(Microsoft.AspNetCore.Http.IFormFile file, string filePath, string prompt)
{
if (System.IO.File.Exists(filePath))
{
return CreateSongResult.AlreadyExists;
}
using (var filestream = new FileStream(filePath, FileMode.Create))
{
Console.WriteLine(prompt);
file.CopyTo(filestream);
if (System.IO.File.Exists(filePath))
{
return CreateSongResult.Created;
}
}
return CreateSongResult.NotCreated;
}
private string DetermineFileExtension(AudioFileExtensionsType flag)
{
switch (flag)
@@ -135,11 +156,22 @@ public class Song
return filename;
}
#endregion
}
#region Enums
public enum AudioFileExtensionsType
{
Default = 0,
WAV = 1,
FLAC = 2
}
public enum CreateSongResult
{
NotCreated = 0,
AlreadyExists = 1,
Created = 2
}
#endregion