using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using Alvas.Audio;
using System.IO;
using Microsoft.AspNetCore.Http;

namespace WebCs.Pages
{
    public class IndexModel : PageModel
    {
        private readonly ILogger<IndexModel> _logger;

        public IndexModel(ILogger<IndexModel> logger)
        {
            _logger = logger;
        }
        public IEnumerable<string> Files { get; set; }
        public void OnGet()
        {
        }
        [BindProperty]
        public IFormFile Upload { get; set; }
        public async Task<IActionResult> OnPostAsync()
{
    // // Perform an initial check to catch FileUpload class attribute violations.
    // if (!ModelState.IsValid)
    // {
    //     return Page();
    // }
// _environment.ContentRootPath
    var filePath = Path.Combine(@"wwwroot\Audio", Upload.FileName);

    using (var fileStream = new FileStream(filePath, FileMode.Create))
    {
        // await FileUpload.UploadPublicSchedule.CopyToAsync(fileStream);
        await Upload.CopyToAsync(fileStream);
    }
    Console.WriteLine("Upload");
    return RedirectToPage("./Index");
}

    }
}
