//
        // GET: /APIPowerUsage/

        //public ActionResult Index()
        //{
        //    return View();
        //}

        public IEnumerable <PowerUsageModel> Get(int id)
        {
            PowerUsageModel        objModel   = new PowerUsageModel();
            PowerUsageService      objService = new PowerUsageService();
            List <PowerUsageModel> lstticker  = new List <PowerUsageModel>();

            lstticker = objService.getPUData(id);
            objModel.ListPowerData = new List <PowerUsageModel>();
            objModel.ListPowerData.AddRange(lstticker);
            return(objModel.ListPowerData);
        }
        public ActionResult Index()
        {
            PowerUsageService      objService = new PowerUsageService();
            PowerUsageModel        objModel   = new PowerUsageModel();
            List <PowerUsageModel> objList    = new List <PowerUsageModel>();
            int cid = 0;

            if (Session["CompID"] != null)
            {
                cid = Convert.ToInt32(Session["CompID"].ToString());
            }
            objList = objService.getPUData(cid);
            objModel.ListPowerData = new List <PowerUsageModel>();
            objModel.ListPowerData.AddRange(objList);


            List <PowerUsageModel> lstAppData    = new List <PowerUsageModel>();
            PowerUsageModel        objAppoint    = new PowerUsageModel();
            PowerUsageService      objAppService = new PowerUsageService();


            lstAppData = objAppService.getPUData(cid);

            var powerDataList = from e in lstAppData
                                select new
            {
                //id = e.PUID,
                label = e.DataSuite + "(" + e.RackID + ")",
                //rackid=e.RackID,
                y = e.PowerContracted,
                //pu=e.PowerUsed,
                //ou=e.OverUnder,
                lastreading = e.LastReading.Value.ToString("MMMM-yyyy"),
            };
            var rows = powerDataList.ToArray();

            if (rows.Count() > 0)
            {
                ViewBag.last = rows[0].lastreading;
            }
            string pc  = JsonConvert.SerializeObject(rows);
            string pcf = pc.Replace("[", string.Empty).Replace("]", string.Empty);

            ViewBag.DataPointsPC = pcf;

            var powerDataListPU = from e in lstAppData
                                  select new
            {
                //id = e.PUID,
                label = e.DataSuite + "(" + e.RackID + ")",
                //rackid=e.RackID,
                y = e.PowerUsed,
                //pu=e.PowerUsed,
                //ou=e.OverUnder,
                //lastreading = e.LastReading.Value.ToString("yyyy-MM-dd") + " " + e.LastReading,
            };
            var    rowsPU = powerDataListPU.ToArray();
            string pu     = JsonConvert.SerializeObject(rowsPU);;
            string puf    = pu.Replace("[", string.Empty).Replace("]", string.Empty);

            ViewBag.DataPointsPU = puf;

            List <PowerUsageModel> lstTotalPU = new List <PowerUsageModel>();
            //string year = Convert.ToString(System.DateTime.Now.Year);
            string year = "";

            if (objList.Count > 0)
            {
                year = objList[0].LastReading.Value.ToString("yyyy");
            }
            lstTotalPU = objService.getTotalPU(year, cid);
            objModel.ListTotalTickets = new List <PowerUsageModel>();
            objModel.ListTotalTickets.AddRange(lstTotalPU);

            var TTPCList = from e in lstTotalPU
                           select new
            {
                //id = e.PUID,
                label = e.TTmonth,
                //rackid=e.RackID,
                y = e.TotalPC,
                //pu=e.PowerUsed,
                //ou=e.OverUnder,
                year = e.TTyear,
            };
            var rowTT = TTPCList.ToArray();

            if (rowTT.Count() > 0)
            {
                ViewBag.Year = rowTT[0].year;
            }
            string ttpc  = JsonConvert.SerializeObject(rowTT);
            string ttpcf = ttpc.Replace("[", string.Empty).Replace("]", string.Empty);

            ViewBag.TTPC = ttpcf;


            var TTPUList = from e in lstTotalPU
                           select new
            {
                //id = e.PUID,
                label = e.TTmonth,
                //rackid=e.RackID,
                y = e.TotalPU,
            };
            var    rowsTTPU = TTPUList.ToArray();
            string ttpu     = JsonConvert.SerializeObject(rowsTTPU);
            string ttpuf    = ttpu.Replace("[", string.Empty).Replace("]", string.Empty);

            ViewBag.TTPU = ttpuf;

            UserService         objServiceComp = new UserService();
            List <CompanyModel> ListComp       = new List <CompanyModel>();

            ListComp          = objServiceComp.getActiveComp();
            objModel.ListComp = new List <CompanyModel>();
            objModel.ListComp.AddRange(ListComp);

            return(View(objModel));
        }