public ActionResult DelData(PowerUsageModel model) { try { int mm = model.month; int yy = model.year; int cid = 0; if (model.CompID != null && model.CompID != 0) { cid = Convert.ToInt32(model.CompID); } PowerUsageModel objModel = new PowerUsageModel(); PowerUsageService objService = new PowerUsageService(); List <PowerUsageModel> objListSC = new List <PowerUsageModel>(); objListSC = objService.getPUDataByMMYY(mm, yy, cid); objModel.ListPowerData = new List <PowerUsageModel>(); objModel.ListPowerData.AddRange(objListSC); foreach (var i in objModel.ListPowerData) { int id = i.PUID; objModel = objService.getByID(id); Dbcontext.PowerUsageMasters.Remove(Dbcontext.PowerUsageMasters.Find(id)); Dbcontext.SaveChanges(); } int c = objListSC.Count(); TempData["Msg"] = c + "Record Deleted."; } catch (Exception ex) { TempData["Msg"] = "Record Not Deleted. " + ex; return(View("Error")); } return(RedirectToAction("Index")); }
public ActionResult Index(HttpPostedFileBase[] file, PowerUsageModel model) { PowerUsageModel objModel = new PowerUsageModel(); PowerUsageService objService = new PowerUsageService(); int mm = model.month; int yy = model.year; List <PowerUsageModel> objListSC = new List <PowerUsageModel>(); int cid = 0; if (Session["CompID"] != null) { cid = Convert.ToInt32(Session["CompID"].ToString()); } objListSC = objService.getPUDataByMMYY(mm, yy, cid); objModel.ListPowerData = new List <PowerUsageModel>(); objModel.ListPowerData.AddRange(objListSC); System.Threading.Thread.Sleep(5000); List <PowerUsageModel> lstAppData = new List <PowerUsageModel>(); PowerUsageModel objAppoint = new PowerUsageModel(); PowerUsageService objAppService = new PowerUsageService(); lstAppData = objAppService.getPUDataByMMYY(mm, yy, 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("yyyy-MM-dd") + " " + e.LastReading, }; var rows = powerDataList.ToArray(); 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("MMMM-yyyy"), }; var rowsPU = powerDataListPU.ToArray(); if (rowsPU.Count() > 0) { ViewBag.last = rowsPU[0].lastreading; } 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(model.year); 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 = 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 Json(objModel.ListPowerData, JsonRequestBehavior.AllowGet); //var jsonResult = Json(objModel.ListPowerData, JsonRequestBehavior.AllowGet); //jsonResult.MaxJsonLength = int.MaxValue; //return jsonResult; //return PartialView("_Data", objModel); return(View(objModel)); }