using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web.Mvc;

using TimeControlReportEnhancements.Models;

namespace TimeControlReportEnhancements.Controllers
{
    public class HomeController : Controller
    {
        private static ICollection<TimeControlGrid> data;

        public HomeController()
        {
            if (data == null)
            {
                var random = new Random();
                data = Enumerable.Range(1, 100).Select(i => new TimeControlGrid
                {
                    EmpNumber = Convert.ToInt32(i),
                    EmpName = new Employee() { EmpName = "a" + i.ToString(), EmpNumber = i },
                    Dept = new Department() { DeptName = "b" + i.ToString() },
                    ProjectName = new Project() { ProjectName = "c" + i.ToString(), ProjCode = Convert.ToInt32(i.ToString()) },
                    ChargeDesc = new ChargeCode() { ChargeCodeName = "d" + i.ToString() },
                    ProjectCode = new Project() { ProjectName = "c" + i.ToString(), ProjCode = Convert.ToInt32(i.ToString()) },
                    CostCenter = new CostCenter() { CostCenterName = "f" + i.ToString() },
                    Jan = Convert.ToInt32(i),
                    Feb = Convert.ToInt32(i),
                    Mar = Convert.ToInt32(i),
                    Apr = Convert.ToInt32(i),
                    May = Convert.ToInt32(i),
                    Jun = Convert.ToInt32(i),
                    Jul = Convert.ToInt32(i),
                    Aug = Convert.ToInt32(i),
                    Sep = Convert.ToInt32(i),
                    Oct = Convert.ToInt32(i),
                    Nov = Convert.ToInt32(i),
                    Dec = Convert.ToInt32(i),
                    HoursYTD = (Convert.ToInt32(i) * 12)

                }).ToList();

            }
        }
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }

       
        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]      
        public ActionResult GetAllEmployees([DataSourceRequest] DataSourceRequest request)
        {


            return Json(data.ToDataSourceResult(request));
        }
       

        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
        public ActionResult EmployeeDetailsUpdate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<TimeControlGrid> products)
        {
            if (products != null && ModelState.IsValid)
            {
                foreach (var product in products)
                {
                    data.Add(product);
                }
            }



            // return Json(EmpList.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
            return Json(new[] { products }.ToDataSourceResult(request, ModelState));
            //return Json(products.ToDataSourceResult(request, ModelState));
        }

       
        public ActionResult HoursByProject()
        {
            //return Json(ChartDataRepository.SpainElectricityProduction());           

            return View();
        }
        

        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
        public ActionResult CreateEmployeeDetails([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<TimeControlGrid> products)
        {
            var results = new List<TimeControlGrid>();

            if (products != null && ModelState.IsValid)
            {
                foreach (var product in products)
                {
                    data.Add(product);
                    results.Add(product);
                }
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }

        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
        public ActionResult LoadHoursByProject()
        {
            //return Json(ChartDataRepository.SpainElectricityProduction());
           


            List<HoursByProject> EmpList = new List<HoursByProject>();

            int count = 25;
            for (int i = 0; i < 25; i++)
            {
                EmpList.Add(new HoursByProject()
                {
                    Hours = Convert.ToInt32(i),
                    ProjectName ="hours"+i.ToString()
                });
            }
           

            return Json(EmpList, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
        public ActionResult GetProjectNames()
        {
            //return Json(ChartDataRepository.SpainElectricityProduction());
            


            List<Project> EmpList = new List<Project>();
            int count = 25;
            for (int i = 0; i < 25; i++)
            {
                EmpList.Add(new Project()
                {
                    ProjCode = Convert.ToInt32(i),
                    ProjectName = "ProjName" + i.ToString()
                });
            }

           

            return Json(EmpList, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
        public JsonResult GetAllEmloyees()
        {
            //return Json(ChartDataRepository.SpainElectricityProduction());
           


            List<Employee> EmpList = new List<Employee>();

            int count = 25;
            for (int i = 0; i < 25; i++)
            {
                EmpList.Add(new Employee()
                {
                    EmpNumber = Convert.ToInt32(i),
                    EmpName = "empName" + i.ToString()
                });
            }
           

            return Json(EmpList, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
        public JsonResult GetDepartmentNames()
        {
            //return Json(ChartDataRepository.SpainElectricityProduction());
           


            List<Department> DeptList = new List<Department>();
            int count = 25;
            for (int i = 0; i < 25; i++)
            {
                DeptList.Add(new Department()
                {
                    
                    DeptName = "deptName" + i.ToString()
                });
            }         

            return Json(DeptList, JsonRequestBehavior.AllowGet);
        }


        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
        public JsonResult GetChargecodeDesc(string ProjectName)
        {
            //return Json(ChartDataRepository.SpainElectricityProduction());
            
            List<ChargeCode> DeptList = new List<ChargeCode>();
            int count = 25;
            for (int i = 0; i < 25; i++)
            {
                DeptList.Add(new ChargeCode()
                {

                    ChargeCodeName = "chargeName" + i.ToString()
                });
            }

            return Json(DeptList, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
        public JsonResult GetCostCenters()
        {
            //return Json(ChartDataRepository.SpainElectricityProduction());
            


            List<CostCenter> DeptList = new List<CostCenter>();
            int count = 25;
            for (int i = 0; i < 25; i++)
            {
                DeptList.Add(new CostCenter()
                {

                    CostCenterName = "costcenterName" + i.ToString()
                });
            }
          

            return Json(DeptList, JsonRequestBehavior.AllowGet);
        }

       
    }

    
}
