public JsonResult newIndicatorAtPRdbl(Int16 fiscalYear, Int16 areaID, Int16 coeID, Int16 coeID2)
        {
            Indicators indicator = new Indicators();
            Indicators indicator2 = new Indicators();

            indicator = db.Indicators.Create();
            indicator2 = db.Indicators.Create();
            db.Indicators.Add(indicator);
            db.Indicators.Add(indicator2);
            db.SaveChanges();
            indicator.Area_ID = areaID;
            indicator2.Area_ID = areaID;

            var type = indicator.GetType();
            var property = type.GetProperty(Helpers.FiscalYear.FYStrFull("FY_Color_ID", fiscalYear));
            property.SetValue(indicator, Convert.ChangeType(1, property.PropertyType), null);
            var type2 = indicator2.GetType();
            var property2 = type.GetProperty(Helpers.FiscalYear.FYStrFull("FY_Color_ID", fiscalYear));
            property2.SetValue(indicator2, Convert.ChangeType(1, property2.PropertyType), null);

            indicator.Indicator = "";
            indicator.Indicator_Link = indicator2.Indicator_ID;
            db.Entry(indicator).State = EntityState.Modified;
            db.SaveChanges();
            indicator2.Indicator = "";
            indicator2.Indicator_Link = indicator.Indicator_ID;
            db.Entry(indicator2).State = EntityState.Modified;
            db.SaveChanges();

            var newMap = new Indicator_CoE_Maps();
            newMap.Indicator_ID = indicator.Indicator_ID;
            newMap.CoE_ID = coeID;
            newMap.Fiscal_Year = fiscalYear;
            db.Indicator_CoE_Maps.Add(newMap);
            db.SaveChanges();

            var newMap2 = new Indicator_CoE_Maps();
            newMap2.Indicator_ID = indicator2.Indicator_ID;
            newMap2.CoE_ID = coeID2;
            newMap2.Fiscal_Year = fiscalYear;
            db.Indicator_CoE_Maps.Add(newMap2);
            db.SaveChanges();

            var colorID = (Int16)newMap.Indicator.GetType().GetProperty(FiscalYear.FYStrFull("FY_", fiscalYear) + "Color_ID").GetValue(newMap.Indicator, null);

            return Json(new { indicatorID = indicator.Indicator_ID, mapID = newMap.Map_ID, newAreaID = indicator.Area_ID, colorID = colorID,
                              indicatorID2 = indicator2.Indicator_ID, mapID2 = newMap2.Map_ID, newAreaID2 = indicator2.Area_ID, colorID2 = colorID
                            }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult newIndicatorAtPR(Int16 fiscalYear, Int16 areaID, Int16 coeID, Int16 indicatorID, Int16? newIndicatorID)
        {
            Indicators indicator = new Indicators();

            if (newIndicatorID.HasValue)
            {
                indicator = db.Indicators.FirstOrDefault(x => x.Indicator_ID == newIndicatorID);
            }
            else
            {
                indicator = db.Indicators.Create();//new Indicators();
                db.Indicators.Add(indicator);
                db.SaveChanges();
                indicator.Area_ID = areaID;

                var type = indicator.GetType();
                var property = type.GetProperty(Helpers.FiscalYear.FYStrFull("FY_Color_ID", fiscalYear));
                property.SetValue(indicator, Convert.ChangeType(1, property.PropertyType), null);

                indicator.Indicator = "";
                db.Entry(indicator).State = EntityState.Modified;
                //db.Indicators.Add(indicator);
                db.SaveChanges();
            }

            var newMap = new Indicator_CoE_Maps();
            newMap.Indicator_ID = indicator.Indicator_ID;

            int number = 0;
            if (indicatorID != 0)
            {
                if (db.Indicator_CoE_Maps.Where(x => x.CoE_ID == coeID && x.Fiscal_Year == fiscalYear).FirstOrDefault(x => x.Indicator_ID == indicatorID) != null)
                {
                    number = db.Indicator_CoE_Maps.Where(x => x.CoE_ID == coeID && x.Fiscal_Year == fiscalYear).FirstOrDefault(x => x.Indicator_ID == indicatorID).Number + 1;
                }
                else
                {
                    number = 0;
                }
            }
            newMap.Number = (Int16)number;

            var allMaps = db.Indicator_CoE_Maps.ToList();
            foreach (var map in allMaps.OrderBy(x => x.Number).Where(x => x.CoE_ID == coeID && x.Fiscal_Year == x.Fiscal_Year && x.Number >= number))
            {
                map.Number++;
                db.Entry(map).State = EntityState.Modified;
                db.SaveChanges();
            }
            newMap.CoE_ID = coeID;
            newMap.Fiscal_Year = fiscalYear;
            db.Indicator_CoE_Maps.Add(newMap);
            db.SaveChanges();

            var colorID = (Int16)newMap.Indicator.GetType().GetProperty(FiscalYear.FYStrFull("FY_", fiscalYear) + "Color_ID").GetValue(newMap.Indicator, null);

            return Json(new { indicatorID = indicator.Indicator_ID, mapID = newMap.Map_ID, newAreaID = indicator.Area_ID, colorID = colorID}, JsonRequestBehavior.AllowGet);
        }