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

using CommonHelpers;

using MyFlat.DB;

namespace MyFlat {

//**************************************************************************************************
partial class HomeController {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// “AMUSING”-PAGE REQUEST PROCESSING (IN HOME CONTROLLER):

public ActionResult Amusing() =>
Do(delegate{
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   var app = ProvideWithViewProps();
   return View();
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
});

[HttpPost]
public Task<ActionResult> Amusing(AmusingPageInput input) =>
Do_A("Amusing(AmusingPageInput)",async()=>{
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   var app = ProvideWithViewProps();
   if ( input.GetMonthList )
   {
/*
      try {
         throw new ApplicationException( "Test exception About (#1)." ); }
      catch (Exception e) {
         throw new ApplicationException( "Test exception About (#2).", e ); }
*/
      CON.PrintOperation(HLocal.TEXT(
         "Performing months query",
         "Выполнение запроса месяцев" ));
/*
      // In case of unexpected exception — debug version will show details (through ASP error info):
      var list = GetMonthList_Query.PERFORM();
*/
      var list = GetMonthList_Query.EmptyResult; // instead of explicit result-type indication
      var err = await Attempt_A(async()=>{
         list = await GetMonthList_Query.PERFORM_A(); });
      if ( err != null )
         return View( AmusingPageModel.ServerError( this, err ) );
         // Database error details will only be shown in “Expose” (development environment).
      return View( new AmusingPageModel( this, list ) );
   }
   else
      CON.PrintError(HLocal.TEXT(
         "Incorrect POST-method parameter(s).",
         "Некорректный(е) параметр(ы) для POST-метода." ));
   return new BadRequestResult();
//-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
});

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

} // MyFlat
