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
    {
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }

       
        [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]      
        public ActionResult GetAllEmployees([DataSourceRequest] DataSourceRequest request)
        {
            List<TimeControlGrid> EmpList = new List<TimeControlGrid>();
            int count = 25;
            for (int i = 0; i < 25; i++)
            {
                EmpList.Add(new TimeControlGrid()
                {
                    EmpNumber = Convert.ToInt32(i),
                    EmpName = new Employee() { EmpName = "a" + i.ToString(), EmpNumber = i },
                    Dept = "b" + i.ToString(),
                    ProjectName = "c" + i.ToString(),
                    ChargeDesc = "d" + i.ToString(),
                    ProjectCode = "e" + i.ToString(),
                    CostCenter = "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) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i))
                });
            }

            return Json(EmpList.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
        }
       

        [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)
            //    {
            //        productService.Update(product);
            //    }
            //}
           


            List<TimeControlGrid> EmpList = new List<TimeControlGrid>();
            int count = 25;
            for(int i=0;i<25;i++)
            {
                EmpList.Add (new TimeControlGrid()
                {
                    EmpNumber = Convert.ToInt32(i),
                    EmpName = new Employee() { EmpName = "a" + i.ToString(), EmpNumber = i },
                    Dept = "b" + i.ToString(),
                    ProjectName = "c" + i.ToString(),
                    ChargeDesc = "d" + i.ToString(),
                    ProjectCode = "e" + i.ToString(),
                    CostCenter = "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) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i) + Convert.ToInt32(i))
                });
            }
           

            return Json(EmpList.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
            //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)
        {
            //if (product != null && ModelState.IsValid)
            //{
            //    productService.Create(product);
            //}

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

        [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);
        }

       
    }

    
}
