using Infragistics.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.SessionState;
using igGrid_DataSourceUrl.Models;

namespace igGrid_DataSourceUrl.Controllers
{
    public class HomeController : Controller
    {
        // Renders the form to create Currency  (Insert new rows in Grid with valid dates and check the dates in POST method inside transaction)
        [HttpGet]
        public ActionResult CreateCurrency()
        {
            ViewBag.Mode = "Create";
            ViewBag.Entity = "Currency";
            ViewBag.cur_cd = "CurrencyCode1";
            return View("CurrencyForm");
        }

      
        /*Insert BREAKPOINT HERE AND CHECK transaction  (Check the dates inside the rows of transaction) */
        /*Insert BREAKPOINT HERE AND CHECK transaction  (Check the dates inside the rows of transaction) */
        [HttpPost]
        public ActionResult CreateCurrency(Currency currencyModel, 
                                            string Mode, 
                                            string entityValue,
                                            List<GridTransaction<CurrencyRate>> transaction)
        {    /*Insert BREAKPOINT HERE AND CHECK transaction & CHECK transaction ^^^^^^^^^^^*/

            //Check transaction's row's dates, All of them would be null i.e (01/01/0001 12:00:00) 
            
            ViewBag.Entity = "Currency";
            if (transaction != null) { /*do something*/  }
            return Json(new { Success = true, successMessage = "Success" }); 

        }


        //Dummy Data
        [GridDataSourceAction]
        public ActionResult CurrencyDetailViewGridData(string cur_cd)
        {
            List<CurrencyRate> currencyRateList = new List<CurrencyRate>();

            for(int i = 1 ; i  <= 2 ; i ++)
            currencyRateList.Add(new CurrencyRate
            {
                cur_cd = "CurrencyCode1",
                cur_rt_buying_rate = i+22,
                cur_rt_from_dt = DateTime.Now.AddDays(i),
                cur_rt_pk = i,
                cur_rt_selling_rate = i+42,
                cur_rt_to_dt = DateTime.Now.AddDays(5+i),
                org_cd = "RPG"
            });


            return View(currencyRateList.AsQueryable());

        }



    }
}
