public ActionResult GetProductionUnitDetailPopUp(int id) { var db = new ApplicationDbContext(); var productionUnits = db.ProductionUnits.Where(p => p.Id == id) .Include(p => p.owner.preferedMoment) .Include(p => p.productionUnitType) .Include(p => p.productionUnitStatus).ToList(); var productionUnit = productionUnits.FirstOrDefault(); if (productionUnit == null) { return(Json("")); } var options = db.OptionLists.Include(o => o.productionUnit) .Include(o => o.option) .Where(o => o.productionUnit.Id == productionUnit.Id) .Select(o => o.option); var optionList = string.Empty; if (options.Count() > 0) { options.ToList().ForEach(o => { optionList += o.name + "/"; }); } var averageMonthlyProduction = PerformanceManager.GetEstimatedMonthlyProduction(productionUnit.productionUnitType.Id); var onlineSinceWeeks = Math.Round((DateTime.Now - productionUnit.startDate).TotalDays / 7); var averageMonthlySparedCO2 = PerformanceManager.GetEstimatedMonthlySparedCO2(averageMonthlyProduction); var results = new object(); results = new { AverageMonthlySparedCO2 = averageMonthlySparedCO2, OnlineSinceWeeks = onlineSinceWeeks, AverageMonthlyProduction = averageMonthlyProduction, PioneerCitizenName = productionUnit.owner.pioneerCitizenName, PioneerCitizenNumber = productionUnit.owner.pioneerCitizenNumber, ProductionUnitStartDate = productionUnit.startDate, ProductionUnitInfo = productionUnit.info, ProductionUnitTypeName = productionUnit.productionUnitType.name, ProductionUnitTypeImage = productionUnit.productionUnitType.imagePath, ProductionUnitStatus = productionUnit.productionUnitStatus.name, PhoneNumber = productionUnit.owner.phoneNumber == null ? "00 33 3 67 37 00 56" : productionUnit.owner.phoneNumber, ContactMail = productionUnit.owner.contactMail == null ? "*****@*****.**" : productionUnit.owner.contactMail, PicturePath = productionUnit.picturePath == null ? "NoImage.png" : productionUnit.picturePath, PreferedMoment = productionUnit.owner.preferedMoment == null ? "" : productionUnit.owner.preferedMoment.name, Location = productionUnit.owner.location == null ? "" : productionUnit.owner.location, ProductionUnitOptions = optionList, }; return(Json(results)); }