using System;
using System.IO;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

using CommonHelpers;

namespace MyFlat {

//**************************************************************************************************
partial class HomeController {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// AUTHORIZATION REQUEST PROCESSING ON HOMEPAGE (IN HOME CONTROLLER):

public ActionResult Index() =>
Do(delegate{
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   var app = ProvideWithViewProps();
   if ( !_WasStartupPrinted_ )
   {
      CON.PrintIntensive( Directory.GetCurrentDirectory() );
      _WasStartupPrinted_ = true;
   }
/*
   Win32.MessageBox( IntPtr.Zero,
      //Directory.GetCurrentDirectory(),
      //HThread.CurrentThread.ManagedThreadId.ToString(),
      //HttpContext.Session.Id,
      "MyFlat (Index)", Win32.MB_ICONINFORMATION | Win32.MB_SYSTEMMODAL );
*/
   return app.IsUserSessionOpen ? View( new HomePageModel( this ) ) : View();
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
});

[HttpPost]
public Task<ActionResult> Index(HomePageInput input) =>
Do_A("Index(HomePageInput)",async()=>{
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
   return View( new HomePageModel( this, "Test error." ) );
   return View( HomePageModel.ServerError( this, "Test error (database)." ) );
*/
   try
   {
      if ( input.OpenSession )
         return await OpenUserSession_A( input );
      if ( input.CloseSession )
         return CloseUserSession();
      return View( new HomePageModel( this, IncorrectRequest ) );
   }
   finally
   {
      ProvideWithViewProps();
   }
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
});

//==================================================================================================

public static volatile bool _WasStartupPrinted_;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HomeController
//**************************************************************************************************

} // MyFlat
