using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JtkMainServer.Managers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace JtkMainServer.Pages.MyPage.ChargeCash {
    public class DoneModel : PageModel {
        public IActionResult OnGet() {
            var loginUserId = HttpContext.Session.GetString("LoggedInUserId");
            ViewData["LoggedinUserId"] = loginUserId;
            ViewData["UserTotalCash"] = DbManager.GetUser(loginUserId)?.Cash;

            if (string.IsNullOrWhiteSpace(loginUserId)) {
                // 로그인 안 했을 시, 로그인 페이지로
                HttpContext.Session.SetString("RequestedPage", "MyPage/ChargeCash/Index");
                return RedirectToPage("/Login");
            }
            
            var chargedAmount = HttpContext.Session.GetInt32("ChargedAmount");
            if (chargedAmount == null) {
                return RedirectToPage("./Index");
            } else {
                ViewData["ChargedAmount"] = chargedAmount.Value;
                HttpContext.Session.Remove("charged_amount");
                return Page();
            }
        }
        public IActionResult OnPost() {
            return OnGet();
        }
    }
}