public bool SetPowerCall(int gid, int?pc)
        {
            GeneratingUnit gen = (from g in this.Context.GeneratingUnits.Where(x => x.Id.Equals(gid))
                                  select g).FirstOrDefault();

            gen.PowerCallId = pc;

            this.Context.SubmitChanges();
            return(true);
        }
        public IList <VoltageLevel> GetVoltageLevels(GeneratingUnit generatingUnit)
        {
            //if (!this.Context.VoltageLevels.Any()) return null;
            //return this.Context.VoltageLevels.ToList();

            if (generatingUnit.VoltageLevel != null && generatingUnit.VoltageLevel.Substation != null)
            {
                var voltageLevels = from v in this.Context.VoltageLevels
                                    where v.SubstationId == generatingUnit.VoltageLevel.SubstationId
                                    select v;
                return(voltageLevels != null?voltageLevels.ToList() : null);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Inserts any new GeneratingUnit objects to Db and updates any existing GeneratingUnit objects (based on GeneratingUnit Name)
        /// </summary>
        /// <param name="generatingUnit">GeneratingUnit objects</param>
        public void SaveGeneratingUnit(GeneratingUnit generatingUnit)
        {
            GeneratingUnit currentGeneratingUnit = (from g in this.Context.GeneratingUnits.Where(gen => gen.Id.Equals(generatingUnit.Id))
                                                    select g).FirstOrDefault();


            if (currentGeneratingUnit != null)
            {
                // we are updaing an existing GeneratingUnit
                currentGeneratingUnit.DateUpdated            = DateTime.Now;
                currentGeneratingUnit.UserUpdatedId          = generatingUnit.UserCreatedId;
                currentGeneratingUnit.Description            = generatingUnit.Description;
                currentGeneratingUnit.EnergySourceId         = generatingUnit.EnergySourceId;
                currentGeneratingUnit.GeneratorStatusID      = generatingUnit.GeneratorStatusID;
                currentGeneratingUnit.GeneratorTypeID        = generatingUnit.GeneratorTypeID;
                currentGeneratingUnit.InitialP               = generatingUnit.InitialP;
                currentGeneratingUnit.IsSyncCondenserCapable = generatingUnit.IsSyncCondenserCapable;

                currentGeneratingUnit.ManufacturerId    = generatingUnit.ManufacturerId;
                currentGeneratingUnit.Model             = generatingUnit.Model;
                currentGeneratingUnit.VoltageLevelId    = generatingUnit.VoltageLevelId;
                currentGeneratingUnit.EnergySourceId    = generatingUnit.EnergySourceId;
                currentGeneratingUnit.PowerCallId       = generatingUnit.PowerCallId;
                currentGeneratingUnit.NumberOfPolePairs = generatingUnit.NumberOfPolePairs;
                currentGeneratingUnit.SerialNumber      = generatingUnit.SerialNumber;
                //generatingUnit.Id = currentGeneratingUnit.Id;

                // EMS Data
                currentGeneratingUnit.MaxOperatingP = currentGeneratingUnit.MaxOperatingP;
                currentGeneratingUnit.MinOperatingP = currentGeneratingUnit.MinOperatingP;
                currentGeneratingUnit.NormalPF      = generatingUnit.NormalPF;
                currentGeneratingUnit.ShortPF       = generatingUnit.ShortPF;
                currentGeneratingUnit.LongPF        = currentGeneratingUnit.LongPF;
                currentGeneratingUnit.InitialP      = generatingUnit.InitialP;
                this.Context.SubmitChanges();
            }
            else
            {
                // we are creating a new GeneratingUnit

                this.Context.GeneratingUnits.InsertOnSubmit(generatingUnit);
                this.Context.SubmitChanges();
            }
        }