public DbOperationResult SaveControlSystemAlarmMappingCentums(List<ControlSystemAlarmMappingCentum> centums)
        {
            var result = new DbOperationResult();
            try
            {
                using (var cee = new CmsEntities())
                {
                    foreach (var centum in centums)
                    {
                        var dbMatch = (from x in cee.ControlSystemAlarmMappingCentums
                                       where x.Id == centum.Id
                                       select x).FirstOrDefault();

                        if (dbMatch != null)
                        {
                            //Update
                            cee.Entry(dbMatch).CurrentValues.SetValues(centum);
                            cee.SaveChanges();
                        }
                        else
                        {
                            //insert
                            cee.ControlSystemAlarmMappingCentums.Add(centum);
                            cee.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                result.ServerErrorMessages.Add(string.Format("Could not Save ControlSystemAlarmMappingCentum record.{0}{1}", Environment.NewLine, ex.Message));
            }
            return result;
        }
Exemplo n.º 2
0
        public Role SaveRole(Role role)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                Role dbRole = (from x in cee.Roles where x.Name == role.Name select x).FirstOrDefault();

                if (dbRole != null)
                {
                    cee.Entry(dbRole).CurrentValues.SetValues(role);
                }
                else
                {
                    cee.Roles.Add(role);
                }
                cee.SaveChanges();
            }
            return role;
        }
Exemplo n.º 3
0
        public PipeProperty SavePipeProperty(PipeProperty pipeProperty)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                PipeProperty original = (from x in cee.PipeProperties where x.Id == pipeProperty.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.PipeProperties.Add(pipeProperty);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(pipeProperty);
                }

                cee.SaveChanges();
            }
            return pipeProperty;
        }
Exemplo n.º 4
0
        public DbOperationResult<QuickInstrument> SaveInstrument(Instrument equip, int userId)
        {
            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    Instrument originalObject = (from x in cee.Instruments
                                                              .Include("InstrumentComponents")
                                                              .Include("InstrumentComponents.InstrumentComponentType")
                                                              .Include("CalibrationComponents")
                                                              .Include("CalibrationComponents.CalibrationComponentType")
                                                 where x.Id == equip.Id
                                                 select x).FirstOrDefault();

                    if (originalObject != null)
                    {
                        IEnumerable<InstrumentComponent> instrumentComponentsToBeDeleted = (from x in originalObject.InstrumentComponents
                                                                                            where !equip.InstrumentComponents.Any(x1 => x1.Id == x.Id)
                                                                                            select x);

                        bool hasRevHist = false;
                        var rh = BuildRevisionHistory(equip, userId, instrumentComponentsToBeDeleted, cee, out hasRevHist);

                        foreach (var instrumentComponent in instrumentComponentsToBeDeleted)
                        {
                            DeleteInstrumentComponent(instrumentComponent);
                        }

                        IEnumerable<CalibrationComponent> calibrationComponentsToBeDeleted = (from x in originalObject.CalibrationComponents
                                                                                              where !equip.CalibrationComponents.Any(x1 => x1.Id == x.Id )
                                                                                              select x);

                        BuildRevisionHistory(equip, userId, calibrationComponentsToBeDeleted, rh, hasRevHist, cee);

                        BuildRevisionHistory(equip, cee);

                        foreach (var calibrationComponent in calibrationComponentsToBeDeleted)
                        {
                            DeleteCalibrationComponent(calibrationComponent);
                        }

                        SaveInstrumentComponents(equip.InstrumentComponents.ToList(), userId);
                        SaveCalibrationComponents(equip.CalibrationComponents.ToList());
                        SaveInstrumentAttachments(equip.InstrumentAttachments.ToList());
                        SaveInstrumentRelatedIssues(equip, cee);
                        SaveInstrumentDocuments(equip, cee);

                        cee.Entry(originalObject).CurrentValues.SetValues(equip);
                        cee.SaveChanges();
                    }
                    else
                    {
                        equip.InstrumentType = null;
                        equip.Area = null;
                        equip.IsActive = true;
                        equip.VerificationFrequencyId = 1;

                        cee.Instruments.Add(equip);
                        cee.SaveChanges();
                    }

                    QuickInstrument quickInstrument = BuildQuickInstrument(cee, equip.Id);

                    return new DbOperationResult<QuickInstrument> { EntityResult = quickInstrument };
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                return BuildOperationalErrorResults<QuickInstrument>(ex);
            }
        }
Exemplo n.º 5
0
        public InstrumentProperty SaveInstrumentProperty(InstrumentProperty instrumentProperty)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                InstrumentProperty original = (from x in cee.InstrumentProperties where x.Id == instrumentProperty.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.InstrumentProperties.Add(instrumentProperty);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(instrumentProperty);
                }

                cee.SaveChanges();
            }
            return instrumentProperty;
        }
Exemplo n.º 6
0
        public DbOperationResult<ElectricalEquipmentProperty> SaveElectricalEquipmentProperty(ElectricalEquipmentProperty controlSystemProperty)
        {
            DbOperationResult<ElectricalEquipmentProperty> dbOperationResult = new DbOperationResult<ElectricalEquipmentProperty>();

            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    ElectricalEquipmentProperty original = (from x in cee.ElectricalEquipmentProperties where x.Id == controlSystemProperty.Id select x).FirstOrDefault();

                    if (original == null)
                    {
                        cee.ElectricalEquipmentProperties.Add(controlSystemProperty);
                    }
                    else
                    {
                        cee.Entry(original).CurrentValues.SetValues(controlSystemProperty);
                    }

                    cee.SaveChanges();
                    dbOperationResult.EntityResult = controlSystemProperty;
                }

            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                dbOperationResult.ServerErrorMessages = BuildOperationalErrorResults(ex).ServerErrorMessages;
                return dbOperationResult;
            }
            return dbOperationResult;
        }
Exemplo n.º 7
0
        public DbOperationResult<QuickElectrical> SaveElectricalEquipment(ElectricalEquipment equip, int userId)
        {
            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    var originalObject = (from x in cee.ElectricalEquipments
                                                       .Include("ElectricalEquipmentComponents")
                                                       .Include("ElectricalEquipmentComponents.ElectricalEquipmentComponentType")
                                          where x.Id == equip.Id
                                          select x).FirstOrDefault();

                    if (originalObject != null)
                    {
                        IEnumerable<ElectricalEquipmentComponent> electricalComponentsToBeDeleted = from x in originalObject.ElectricalEquipmentComponents
                                                                                                    where !equip.ElectricalEquipmentComponents.Any(x1 => x1.Id == x.Id)
                                                                                                    select x;

                        BuildRevisonHistory(equip, userId, electricalComponentsToBeDeleted, cee);

                        BuildRevisionHistory(equip, cee);

                        foreach (var electricalComponent in electricalComponentsToBeDeleted)
                        {
                            DeleteElectricalEquipmentComponent(electricalComponent);
                        }

                        SaveElectricalEquipmentComponents(equip.ElectricalEquipmentComponents.ToList(), cee, equip.Id, userId);

                        SaveElectricalAttachments(equip.ElectricalEquipmentAttachments.ToList());
                        SaveElectricalRelatedIssues(equip, cee);
                        SaveElectricalDocuments(equip, cee);

                        cee.Entry(originalObject).CurrentValues.SetValues(equip);
                        cee.SaveChanges();

                    }
                    else
                    {
                        equip.ElectricalEquipmentType = null;
                        equip.Area = null;
                        equip.IsActive = true;

                        cee.ElectricalEquipments.Add(equip);
                        cee.SaveChanges();
                    }

                    QuickElectrical quickElectrical = BuildQuickElectrical(cee, equip.Id);

                    return new DbOperationResult<QuickElectrical> { EntityResult = quickElectrical };
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                return BuildOperationalErrorResults<QuickElectrical>(ex);
            }
        }
        private void SaveControlSystemTuningParemeters(List<ControlSystemComponent> controlSystemComponents)
        {
            using (var cee = new CmsEntities())
            {
                foreach (var controlSystemComponent in controlSystemComponents)
                {
                    foreach (var controlSystemTuningPropertyValue in controlSystemComponent.ControlSystemTuningPropertyValues)
                    {
                        var qq = (from x in cee.ControlSystemTuningPropertyValues
                                  where x.Id == controlSystemTuningPropertyValue.Id
                                  select x).FirstOrDefault();

                        if (qq != null)
                        {
                            cee.Entry(qq).CurrentValues.SetValues(controlSystemTuningPropertyValue);
                        }
                        else
                        {
                            cee.ControlSystemTuningPropertyValues.Add(controlSystemTuningPropertyValue);
                        }
                    }
                    cee.SaveChanges();
                }
            }
        }
Exemplo n.º 9
0
        public bool SaveMechanicalEquipmentComponents(List<MechanicalEquipmentComponent> mechanicalComponents, int userId)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                foreach (var mechanicalComponent in mechanicalComponents)
                {
                    var q = (from x in cee.MechanicalEquipmentComponents
                             where x.Id == mechanicalComponent.Id
                             select x).FirstOrDefault();

                    if (q != null)
                    {

                        if (q.LastInspectedDate != mechanicalComponent.LastInspectedDate)
                        {
                            MechanicalEquipmentRevisionHistory rv = new MechanicalEquipmentRevisionHistory
                            {
                                MechanicalEquipmentId = mechanicalComponent.MechanicalEquipmentId,
                                Date = DateTime.Now,
                                UserId = userId,
                                Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.",mechanicalComponent.Name,  q.LastInspectedDate, mechanicalComponent.LastInspectedDate),
                                IsSystemMessage = true
                            };

                            AddMechanicalRevisionHistoryInternal(rv, cee);
                        }

                        //Update Mechanical Componet
                        cee.Entry(q).CurrentValues.SetValues(mechanicalComponent);
                    }
                    else
                    {
                        q = new MechanicalEquipmentComponent();
                        q.MechanicalEquipmentId = mechanicalComponent.MechanicalEquipmentId;
                        q.MechanicalEquipmentComponentTypeId = mechanicalComponent.MechanicalEquipmentComponentTypeId;
                        q.Name = mechanicalComponent.Name;
                        q.Ordinal = mechanicalComponent.Ordinal;
                        q.NextInspectionDate = mechanicalComponent.NextInspectionDate;
                        q.LastInspectedById = mechanicalComponent.LastInspectedById;
                        q.LastInspectedDate = mechanicalComponent.LastInspectedDate;
                        q.LastModifiedById = mechanicalComponent.LastModifiedById;
                        q.LastModifiedDate = mechanicalComponent.LastModifiedDate;
                        q.Description = mechanicalComponent.Description;
                        q.ManufacturerId = mechanicalComponent.ManufacturerId;
                        q.ModelId = mechanicalComponent.ModelId;

                        //Add new Mechanical Component
                        cee.MechanicalEquipmentComponents.Add(q);
                    }

                    foreach (var mechanicalComponentPropertyValue in mechanicalComponent.MechanicalPropertyValues)
                    {
                        var qq = (from x in cee.MechanicalPropertyValues
                                  where x.Id == mechanicalComponentPropertyValue.Id
                                  select x).FirstOrDefault();

                        if (qq != null)
                        {
                            cee.Entry(qq).CurrentValues.SetValues(mechanicalComponentPropertyValue);
                        }
                        else
                        {
                            cee.MechanicalPropertyValues.Add(mechanicalComponentPropertyValue);
                        }
                    }
                    cee.SaveChanges();
                }
            }
            return true;
        }
Exemplo n.º 10
0
        public ControlSystemTuningProperty SaveControlSystemTuningProperty(ControlSystemTuningProperty controlSystemTuningProperty)
        {
            using (var cee = new CmsEntities())
            {
                var original = (from x in cee.ControlSystemTuningProperties where x.Id == controlSystemTuningProperty.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.ControlSystemTuningProperties.Add(controlSystemTuningProperty);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(controlSystemTuningProperty);
                }

                cee.SaveChanges();
            }
            return controlSystemTuningProperty;
        }
Exemplo n.º 11
0
        private void SaveControlSystemTestingProperties(ControlSystem controlSystem)
        {
            using (var cee = new CmsEntities())
            {
                foreach (var propertyValue in controlSystem.ControlSystemTestingPropertyValues)
                {
                    var qq = (from x in cee.ControlSystemTestingPropertyValues
                              where x.Id == propertyValue.Id
                              select x).FirstOrDefault();

                    if (qq != null)
                    {
                        cee.Entry(qq).CurrentValues.SetValues(propertyValue);
                    }
                    else
                    {
                        cee.ControlSystemTestingPropertyValues.Add(propertyValue);
                    }

                    cee.SaveChanges();
                }
            }
        }
Exemplo n.º 12
0
        public DbOperationResult<ControlSystemTestingProperty> SaveControlSystemTestingProperty(ControlSystemTestingProperty property)
        {
            DbOperationResult<ControlSystemTestingProperty> result = new DbOperationResult<ControlSystemTestingProperty>();

            try
            {
                using (var cee = new CmsEntities())
                {
                    var original = (from x in cee.ControlSystemTestingProperties where x.Id == property.Id select x).FirstOrDefault();

                    if (original == null)
                    {
                        cee.ControlSystemTestingProperties.Add(property);
                        cee.SaveChanges();
                        result.EntityResult = property;
                    }
                    else
                    {
                        cee.Entry(original).CurrentValues.SetValues(property);
                        cee.SaveChanges();
                        result.EntityResult = original;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                result.ServerErrorMessages.Add(string.Format("Could not Save Control System  Testing Property.{0}{1}", Environment.NewLine, ex.Message));
            }
            return result;
        }
Exemplo n.º 13
0
        public DbOperationResult SaveControlSystemInterlocks(List<Interlock> controlSystemInterlocks)
        {
            var result = new DbOperationResult();

            using (var cee = new CmsEntities())
            {
                try
                {
                    foreach (var interlock in controlSystemInterlocks)
                    {
                        var q = (from x in cee.Interlocks
                                 where x.Id == interlock.Id
                                 select x).FirstOrDefault();

                        if (q != null)
                        {
                            //Update Interlock
                            cee.Entry(q).CurrentValues.SetValues(interlock);
                        }
                        else
                        {
                            q = new Interlock
                            {
                                ControlSystemId = interlock.ControlSystemId,
                                InterlockTypeId = interlock.InterlockTypeId,
                                Number = interlock.Number,
                                Cause = interlock.Cause,
                                Ordinal = interlock.Ordinal,
                                LastModifiedById = interlock.LastModifiedById,
                                LastModifiedDate = interlock.LastModifiedDate,
                                Description = interlock.Description
                            };

                            //Add new Interlock
                            cee.Interlocks.Add(q);
                        }

                        foreach (var interlockPropertyValue in interlock.InterlockPropertyValues)
                        {
                            var qq = (from x in cee.InterlockPropertyValues
                                      where x.Id == interlockPropertyValue.Id
                                      select x).FirstOrDefault();

                            if (qq != null)
                            {
                                cee.Entry(qq).CurrentValues.SetValues(interlockPropertyValue);
                            }
                            else
                            {
                                cee.InterlockPropertyValues.Add(interlockPropertyValue);
                            }
                        }
                        SaveInterlockRisks(interlock, cee);
                        cee.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    result.ServerErrorMessages.Add(String.Format("Error Saving Control System Interlocks: {0}", ex.Message));
                }
            }
            return result;
        }
Exemplo n.º 14
0
        public DbOperationResult SaveControlSystemComponents(List<ControlSystemComponent> controlSystemComponents)
        {
            var result = new DbOperationResult();

            using (var cee = new CmsEntities())
            {
                try
                {
                    foreach (var controlSystemComponent in controlSystemComponents)
                    {
                        var q = (from x in cee.ControlSystemComponents
                                 where x.Id == controlSystemComponent.Id
                                 select x).FirstOrDefault();

                        if (q != null)
                        {
                            //Update ControlSystem Componet
                            q.ControlSystemId = controlSystemComponent.ControlSystemId;
                            q.ControlSystemComponentTypeId = controlSystemComponent.ControlSystemComponentTypeId;
                            q.Name = controlSystemComponent.Name;
                            q.Ordinal = controlSystemComponent.Ordinal;
                            q.NextInspectionDate = controlSystemComponent.NextInspectionDate;
                            q.LastInspectedById = controlSystemComponent.LastInspectedById;
                            q.LastInspectedDate = controlSystemComponent.LastInspectedDate;
                            q.LastModifiedById = controlSystemComponent.LastModifiedById;
                            q.LastModifiedDate = controlSystemComponent.LastModifiedDate;
                            q.Description = controlSystemComponent.Description;
                            q.ManufacturerId = controlSystemComponent.ManufacturerId;
                            q.ModelId = controlSystemComponent.ModelId;
                        }
                        else
                        {
                            q = new ControlSystemComponent();
                            q.ControlSystemId = controlSystemComponent.ControlSystemId;
                            q.ControlSystemComponentTypeId = controlSystemComponent.ControlSystemComponentTypeId;
                            q.Name = controlSystemComponent.Name;
                            q.Ordinal = controlSystemComponent.Ordinal;
                            q.NextInspectionDate = controlSystemComponent.NextInspectionDate;
                            q.LastInspectedById = controlSystemComponent.LastInspectedById;
                            q.LastInspectedDate = controlSystemComponent.LastInspectedDate;
                            q.LastModifiedById = controlSystemComponent.LastModifiedById;
                            q.LastModifiedDate = controlSystemComponent.LastModifiedDate;
                            q.Description = controlSystemComponent.Description;
                            q.ManufacturerId = controlSystemComponent.ManufacturerId;
                            q.ModelId = controlSystemComponent.ModelId;

                            //Add new ControlSystem Component
                            cee.ControlSystemComponents.Add(q);
                        }

                        foreach (var controlSystemComponentPropertyValue in controlSystemComponent.ControlSystemPropertyValues)
                        {
                            var qq = (from x in cee.ControlSystemPropertyValues
                                      where x.Id == controlSystemComponentPropertyValue.Id
                                      select x).FirstOrDefault();

                            if (qq != null)
                            {
                                cee.Entry(qq).CurrentValues.SetValues(controlSystemComponentPropertyValue);
                            }
                            else
                            {
                                cee.ControlSystemPropertyValues.Add(controlSystemComponentPropertyValue);
                            }
                        }
                        cee.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    result.ServerErrorMessages.Add(String.Format("Error moving components: {0}", ex.Message));
                }
            }
            return result;
        }
Exemplo n.º 15
0
        private void SaveMobilePlantComponents(IEnumerable<MobilePlantComponent> mobilePlantComponents, CmsEntities cee, int mobilePlantEquipmentId, int userId)
        {
            foreach (var mobilePlantComponent in mobilePlantComponents)
            {
                var q = (from x in cee.MobilePlantComponents
                         where x.Id == mobilePlantComponent.Id
                         select x).FirstOrDefault();

                if (q != null)
                {
                    if (q.LastInspectedDate != mobilePlantComponent.LastInspectedDate)
                    {
                        MobilePlantRevisionHistory rv = new MobilePlantRevisionHistory
                        {
                            MobilePlantId = mobilePlantEquipmentId,
                            Date = DateTime.Now,
                            UserId = userId,
                            Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", mobilePlantComponent.Name, q.LastInspectedDate, mobilePlantComponent.LastInspectedDate),
                            IsSystemMessage = true
                        };
                        AddMobilePlantRevisionHistoryInternal(rv, cee);
                    }

                    //Update
                    cee.Entry(q).CurrentValues.SetValues(mobilePlantComponent);

                }
                else
                {
                    //Add new
                    q = new MobilePlantComponent();
                    q.MobilePlantId = mobilePlantComponent.MobilePlantId;
                    q.MobilePlantComponentTypeId = mobilePlantComponent.MobilePlantComponentTypeId;
                    q.Name = mobilePlantComponent.Name;
                    q.Ordinal = mobilePlantComponent.Ordinal;
                    q.NextInspectionDate = mobilePlantComponent.NextInspectionDate;
                    q.LastInspectedById = mobilePlantComponent.LastInspectedById;
                    q.LastInspectedDate = mobilePlantComponent.LastInspectedDate;
                    q.LastModifiedById = mobilePlantComponent.LastModifiedById;
                    q.LastModifiedDate = mobilePlantComponent.LastModifiedDate;
                    q.Description = mobilePlantComponent.Description;
                    q.ManufacturerId = mobilePlantComponent.ManufacturerId;
                    q.ModelId = mobilePlantComponent.ModelId;

                    cee.MobilePlantComponents.Add(q);
                }

                foreach (var mobilePlantComponentPropertyValue in mobilePlantComponent.MobilePlantPropertyValues)
                {
                    var qq = (from x in cee.MobilePlantPropertyValues
                              where x.Id == mobilePlantComponentPropertyValue.Id
                              select x).FirstOrDefault();

                    if (qq != null)
                    {
                        cee.Entry(qq).CurrentValues.SetValues(mobilePlantComponentPropertyValue);
                    }
                    else
                    {
                        cee.MobilePlantPropertyValues.Add(mobilePlantComponentPropertyValue);
                    }
                }
            }
        }
Exemplo n.º 16
0
        public MechanicalEquipmentProperty SaveMechanicalEquipmentProperty(MechanicalEquipmentProperty controlSystemProperty)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                MechanicalEquipmentProperty original = (from x in cee.MechanicalEquipmentProperties where x.Id == controlSystemProperty.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.MechanicalEquipmentProperties.Add(controlSystemProperty);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(controlSystemProperty);
                }

                cee.SaveChanges();
            }
            return controlSystemProperty;
        }
Exemplo n.º 17
0
        public DbOperationResult<DocumentVersion> SaveDocumentVersion(DocumentVersion documentVersion, int userId)
        {
            DbOperationResult<DocumentVersion> result = new DbOperationResult<DocumentVersion>();

            using (CmsEntities cee = new CmsEntities())
            {
                DocumentVersion originalObject = (from x in cee.DocumentVersions where x.Id == documentVersion.Id select x).FirstOrDefault();

                if (originalObject != null)
                {

                    cee.Entry(originalObject).CurrentValues.SetValues(documentVersion);

                    if (documentVersion.AutoIncrement)
                    {
                        IncrementVersionNumber(originalObject, cee, true);
                        originalObject.AutoIncrement = false; // keeping this false so next time the contro is loaded it is re-set to false by default. the property has done it's job already.
                    }

                    cee.SaveChanges();

                    result.EntityResult = (from x in cee.DocumentVersions.Include("User") where x.Id == documentVersion.Id select x).FirstOrDefault();
                }
            }

            return result;
        }
Exemplo n.º 18
0
        public DbOperationResult SaveAccruals(List<FinancialAccrual> accruals, List<IssueFinancialOtherAccrual> otherAccruals, string projectDefinition, DateTime date)
        {
            var result = new DbOperationResult();
            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    //Delete existing IssueFinancialOtherAccrual
                    cee.DeleteWhere<IssueFinancialOtherAccrual>(cee, x => x.ProjectDefinition == projectDefinition && x.Date == date);

                    //Save Accruals
                    foreach (var accrual in accruals)
                    {
                        var original = (from x in cee.FinancialAccruals where x.Id == accrual.Id select x).FirstOrDefault();

                        if (original == null)
                        {
                            cee.FinancialAccruals.Add(accrual);
                        }
                        else
                        {
                            cee.Entry(original).CurrentValues.SetValues(accrual);
                        }
                    }

                    //Save Other Accruals
                    foreach (var otherAccrual in otherAccruals)
                    {
                        var original = (from x in cee.IssueFinancialOtherAccruals where x.Id == otherAccrual.Id select x).FirstOrDefault();

                        if (original == null)
                        {
                            cee.IssueFinancialOtherAccruals.Add(otherAccrual);
                        }
                        else
                        {
                            cee.Entry(original).CurrentValues.SetValues(otherAccrual);
                        }
                    }

                    cee.SaveChanges();
                }
                result.HasErrors = false;
                return result;
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var validationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        log.Error("", ex, "Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
                return BuildOperationalErrorResults(ex);
            }
            catch (Exception ex)
            {
                log.Error("", ex, "Error occured in SaveAccruals()");
                return BuildOperationalErrorResults(ex);
            }
        }
Exemplo n.º 19
0
        private void SaveElectricalEquipmentComponents(IEnumerable<ElectricalEquipmentComponent> electricalComponents, CmsEntities cee, int electricalEquipmentId, int userId)
        {
            foreach (var electricalComponent in electricalComponents)
            {
                var dbMatch = (from x in cee.ElectricalEquipmentComponents
                               where x.Id == electricalComponent.Id
                               select x).FirstOrDefault();

                if (dbMatch != null)
                {
                    if (dbMatch.LastInspectedDate != electricalComponent.LastInspectedDate)
                    {
                        ElectricalEquipmentRevisionHistory rv = new ElectricalEquipmentRevisionHistory
                        {
                            ElectricalEquipmentId = electricalEquipmentId,
                            Date = DateTime.Now,
                            UserId = userId,
                            Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", electricalComponent.Name, dbMatch.LastInspectedDate, electricalComponent.LastInspectedDate)
                        };
                        rv.IsSystemMessage = true;
                        AddElectricalRevisionHistoryInternal(rv, cee);
                    }

                    //Update Electrical Componet
                    cee.Entry(dbMatch).CurrentValues.SetValues(electricalComponent);
                }
                else
                {
                    dbMatch = new ElectricalEquipmentComponent
                    {
                        ElectricalEquipmentId = electricalComponent.ElectricalEquipmentId,
                        ElectricalEquipmentComponentTypeId = electricalComponent.ElectricalEquipmentComponentTypeId,
                        Name = electricalComponent.Name,
                        Ordinal = electricalComponent.Ordinal,
                        NextInspectionDate = electricalComponent.NextInspectionDate,
                        LastInspectedById = electricalComponent.LastInspectedById,
                        LastInspectedDate = electricalComponent.LastInspectedDate,
                        LastModifiedById = electricalComponent.LastModifiedById,
                        LastModifiedDate = electricalComponent.LastModifiedDate,
                        Description = electricalComponent.Description,
                        ManufacturerId = electricalComponent.ManufacturerId,
                        ModelId = electricalComponent.ModelId
                    };

                    //Add new Electrical Component
                    cee.ElectricalEquipmentComponents.Add(dbMatch);
                }

                foreach (var electricalComponentPropertyValue in electricalComponent.ElectricalPropertyValues)
                {
                    var qq = (from x in cee.ElectricalPropertyValues
                              where x.Id == electricalComponentPropertyValue.Id
                              select x).FirstOrDefault();

                    if (qq != null)
                    {
                        cee.Entry(qq).CurrentValues.SetValues(electricalComponentPropertyValue);
                    }
                    else
                    {
                        cee.ElectricalPropertyValues.Add(electricalComponentPropertyValue);
                    }
                }
            }
        }
Exemplo n.º 20
0
        public DbOperationResult<QuickIssue> SaveIssue(Issue issue)
        {
            //issueModifications is a helper class for sending email.
            var issueModifications = new IssueModifications { Issue = issue };

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                EmailNotification emailNotificationObject;
                using (var transaction = new TransactionScope())
                {
                    using (var cee = new CmsEntities())
                    {
                        cee.Configuration.AutoDetectChangesEnabled = false;
                        cee.Configuration.ValidateOnSaveEnabled = false;

                        User modifiedByUser = (from x in cee.Users where x.Id == issue.ModifiedById select x).FirstOrDefault();
                        if (modifiedByUser == null)
                        {
                            throw new NullReferenceException(string.Format("Save Issue Failed: Cannot find a user in db using Id {0}", issue.ModifiedById));
                        }
                        log.Info("Saving Issue Id {0}. User = '******'", issue.Id, modifiedByUser.FirstLastName);
                        cee.Configuration.LazyLoadingEnabled = true;
                        Issue originalIssue = (from x in cee.Issues
                            .Include("IssueStatus")
                            .Include("IssuePriority")
                            .Include("IssueType")
                            .Include("IssueClassification")
                            .Include("CurrentlyAssignedToUser")
                                               where x.Id == issue.Id
                                               select x).FirstOrDefault();
                        issueModifications.OriginalIssue = originalIssue;

                        issue.ModifiedDate = DateTime.Now;
                        List<IssueResponse> responses = ProcessIssueRevisionHistory(originalIssue, issue, cee, issueModifications);
                        responses.Reverse();

                        if (originalIssue != null)
                        {
                            //We are updating the ISSUE
                            emailNotificationObject = GetEmailNotificationObject(issueModifications, modifiedByUser, cee);

                            //Save only changed objects
                            SaveIssueRelatedObjects(issue, originalIssue, cee, modifiedByUser.Id);

                            //Update current issue
                            cee.Entry(originalIssue).CurrentValues.SetValues(issue);
                            responses.ForEach(x => originalIssue.IssueResponses.Add(x));

                        }
                        else
                        {
                            emailNotificationObject = GetEmailNotificationObject(issueModifications, modifiedByUser, cee);

                            int classificaitonId = issue.IssueClassificationId.HasValue ? issue.IssueClassificationId.Value : 0;
                            int? subtTypeId = issue.IssueSubTypeId;
                            int currentlyAssignedToUserId = issue.CurrentlyAssignedToId;

                            //We are creating new ISSUE
                            issue.IsActive = true; //default;
                            issue.CurrentlyAssignedToUser = null;
                            issue.InitiatedByUser = null;

                            issue.IssueClassification = null;
                            issue.IssueClassificationId = classificaitonId;
                            issue.IssueSubType = null;
                            issue.IssueSubTypeId = subtTypeId;
                            issue.IssuePriority = null;
                            issue.IssueStatus = null;
                            issue.IssueType = null;
                            issue.IssuePriority = null;
                            issue.ModifiedByUser = null;
                            issue.OriginallyAssignedToUser = null;

                            issue.CurrentlyAssignedToId = currentlyAssignedToUserId;
                            //SaveIssueCloseouts(issue, issue, cee);
                            AddStandardActions(issue, cee);
                            cee.Issues.Add(issue);
                            responses.ForEach(x => issue.IssueResponses.Add(x));
                        }

                        cee.SaveChanges();
                        transaction.Complete();

                        if (emailNotificationObject != null)
                        {
                            emailNotificationObject.HasResponse = responses.Any();
                        }
                    }
                }

                if (emailNotificationObject != null)
                {
                    emailNotificationObject.IssueId = issue.Id;
                    StartEmailPlugin(emailNotificationObject);
                }

                sw.Stop();
                log.Verbose("Took {0} seconds to save IssueId '{1}'", sw.Elapsed.TotalSeconds, issue.Id);
                return new DbOperationResult<QuickIssue> { EntityResult = BuildReturnQuickIssue(issue) };
            }
            catch (Exception ex)
            {
                string errorMsg = string.Format("Error occured while saving Issue Id {0}", issue.Id);
                log.Error("", ex, errorMsg);

                return BuildOperationalErrorResults<QuickIssue>(ex);
            }
        }
Exemplo n.º 21
0
        public CalibrationProperty SaveCalibrationProperty(CalibrationProperty calibrationProperty)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                CalibrationProperty original = (from x in cee.CalibrationProperties where x.Id == calibrationProperty.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.CalibrationProperties.Add(calibrationProperty);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(calibrationProperty);
                }

                cee.SaveChanges();
            }
            return calibrationProperty;
        }
Exemplo n.º 22
0
        public IssueKpiVarianceCode SaveKpiVarianceCode(IssueKpiVarianceCode kpiVarianceCode)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                var original = (from x in cee.IssueKpiVarianceCodes where x.Id == kpiVarianceCode.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.IssueKpiVarianceCodes.Add(kpiVarianceCode);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(kpiVarianceCode);
                }

                cee.SaveChanges();
            }
            return kpiVarianceCode;
        }
Exemplo n.º 23
0
        public DbOperationResult SaveInstrumentComponents(List<InstrumentComponent> instrumentComponents, int userId)
        {
            DbOperationResult result = new DbOperationResult();

            using (CmsEntities cee = new CmsEntities())
            {
                try
                {
                    foreach (var instrumentComponent in instrumentComponents)
                    {
                        var q = (from x in cee.InstrumentComponents
                                 where x.Id == instrumentComponent.Id
                                 select x).FirstOrDefault();

                        if (q != null)
                        {

                            if (q.LastInspectedDate != instrumentComponent.LastInspectedDate)
                            {
                                InstrumentRevisionHistory rv = new InstrumentRevisionHistory
                                {
                                    InstrumentId = instrumentComponent.InstrumentId,
                                    Date = DateTime.Now,
                                    UserId = userId,
                                    Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", instrumentComponent.Name, q.LastInspectedDate, instrumentComponent.LastInspectedDate),
                                    IsSystemMessage = true
                                };
                                AddInstrumentRevisionHistoryInternal(rv, cee);
                            }

                            //Update Instrument Componet
                            cee.Entry(q).CurrentValues.SetValues(instrumentComponent);
                        }
                        else
                        {
                            q = new InstrumentComponent();
                            q.InstrumentId = instrumentComponent.InstrumentId;
                            q.InstrumentComponentTypeId = instrumentComponent.InstrumentComponentTypeId;
                            q.Name = instrumentComponent.Name;
                            q.Ordinal = instrumentComponent.Ordinal;
                            q.NextInspectionDate = instrumentComponent.NextInspectionDate;
                            q.LastInspectedById = instrumentComponent.LastInspectedById;
                            q.LastInspectedDate = instrumentComponent.LastInspectedDate;
                            q.LastModifiedById = instrumentComponent.LastModifiedById;
                            q.LastModifiedDate = instrumentComponent.LastModifiedDate;
                            q.Description = instrumentComponent.Description;
                            q.ManufacturerId = instrumentComponent.ManufacturerId;
                            q.ModelId = instrumentComponent.ModelId;

                            //Add new Instrument Component
                            cee.InstrumentComponents.Add(q);
                        }

                        foreach (var instrumentComponentPropertyValue in instrumentComponent.InstrumentPropertyValues)
                        {
                            var qq = (from x in cee.InstrumentPropertyValues
                                      where x.Id == instrumentComponentPropertyValue.Id
                                      select x).FirstOrDefault();

                            if (qq != null)
                            {
                                cee.Entry(qq).CurrentValues.SetValues(instrumentComponentPropertyValue);
                            }
                            else
                            {
                                cee.InstrumentPropertyValues.Add(instrumentComponentPropertyValue);
                            }
                        }
                        cee.SaveChanges();
                    }
                }
                catch (Exception ex)
                {

                    result.ServerErrorMessages.Add(String.Format("Error moving components: {0}", ex.Message));
                }
            }
            return result;
        }
Exemplo n.º 24
0
        public IssueRisk SaveRisks(List<IssueRisk> risks, bool isCopyOfInitial)
        {
            IssueRisk highestRisk = null;

            using (var cee = new CmsEntities())
            {
                int highestRating = 0;

                int issueid = risks[0].IssueId;
                int riskType = risks[0].RiskTypeId;

                if (isCopyOfInitial)
                {
                    //Delete Existing
                    List<IssueRisk> foo = (from x in cee.IssueRisks where x.IssueId == issueid && x.RiskTypeId == riskType select x).ToList();
                    foo.ForEach(x => cee.IssueRisks.Remove(x));
                }

                foreach (IssueRisk risk in risks)
                {
                    IssueRisk originalRisk = null;

                    if (!isCopyOfInitial)
                    {
                        originalRisk = (from x in cee.IssueRisks
                                        where x.Id == risk.Id
                                        select x).FirstOrDefault();
                    }

                    if (originalRisk != null)
                    {
                        risk.Id = originalRisk.Id; //need to set this to allow following lines to work...
                        cee.Entry(originalRisk).CurrentValues.SetValues(risk);
                    }
                    else
                    {
                        risk.Issue = null;
                        risk.IssueRiskType = null;
                        risk.IssueRiskCategory = null;
                        risk.IssueRiskLikelihood = null;
                        risk.IssueRiskConsequence = null;
                        risk.IssueRiskMatrix = null;
                        cee.IssueRisks.Add(risk);
                    }
                    cee.SaveChanges();

                    //Find the highest risk
                    IssueRisk savedRisk =
                        (from x in cee.IssueRisks
                            .Include("IssueRiskMatrix")
                            .Include("IssueRiskMatrix.IssueRiskRating")
                         where x.Id == risk.Id
                         select x).FirstOrDefault();
                    if (savedRisk != null && savedRisk.IssueRiskMatrix.RiskRatingNumber > highestRating)
                    {
                        highestRating = savedRisk.IssueRiskMatrix.RiskRatingNumber;
                        highestRisk = savedRisk;
                    }
                }
            }
            return highestRisk;
        }
Exemplo n.º 25
0
        private void SaveCalibrationComponents(IEnumerable<CalibrationComponent> calibrationComponents)
        {
            bool isInsert = false;

            using (CmsEntities cee = new CmsEntities())
            {
                foreach (var calibrationComponent in calibrationComponents)
                {
                    CalibrationComponent match = (from x in cee.CalibrationComponents
                                                  where x.Id == calibrationComponent.Id
                                                  && x.Id > 0
                                                  select x).FirstOrDefault();

                    if (match != null)
                    {
                        //Update Calibration Componet
                        cee.Entry(match).CurrentValues.SetValues(calibrationComponent);
                    }
                    else
                    {
                        isInsert = true;

                        match = new CalibrationComponent
                        {
                            InstrumentId = calibrationComponent.InstrumentId,
                            CalibrationComponentTypeId = calibrationComponent.CalibrationComponentTypeId,
                            Name = calibrationComponent.Name,
                            Ordinal = calibrationComponent.Ordinal,
                            NextInspectionDate = calibrationComponent.NextInspectionDate,
                            LastInspectedById = calibrationComponent.LastInspectedById,
                            LastInspectedDate = calibrationComponent.LastInspectedDate,
                            LastModifiedById = calibrationComponent.LastModifiedById,
                            LastModifiedDate = calibrationComponent.LastModifiedDate,
                            Description = calibrationComponent.Description,
                            Notes = calibrationComponent.Notes
                        };

                        //Add new Calibration Component
                        cee.CalibrationComponents.Add(match);
                    }
                    //delete all Calibration Component Attachments

                    cee.DeleteWhere<CalibrationComponentAttachment>(cee,x=>x.CalibrationComponentId == match.Id);

                    //Add current Calibration Component Attachments
                    foreach (var attachment in calibrationComponent.CalibrationComponentAttachments)
                    {
                        match.CalibrationComponentAttachments.Add(new CalibrationComponentAttachment {CalibrationComponentId = attachment.CalibrationComponentId, AttachmentId = attachment.AttachmentId});
                    }

                    foreach (var calibrationComponentPropertyValue in calibrationComponent.CalibrationComponentPropertyValues)
                    {
                        var qq = (from x in cee.CalibrationComponentPropertyValues
                                  where x.Id == calibrationComponentPropertyValue.Id
                                  select x).FirstOrDefault();

                        if (qq != null)
                        {
                            cee.Entry(qq).CurrentValues.SetValues(calibrationComponentPropertyValue);
                        }
                        else
                        {
                            cee.CalibrationComponentPropertyValues.Add(calibrationComponentPropertyValue);
                        }
                    }
                    cee.SaveChanges();

                    if (isInsert)
                    {
                        //https://jira.issgroup.com.au/browse/BODCMS-998
                        SendNewCalibrationComponentEmail(match);
                    }

                }
            }
        }
Exemplo n.º 26
0
        private void SaveIssueTracking(Issue issue, Issue originalIssue, CmsEntities cee)
        {
            log.Verbose("SaveIssueTracking()");

            IssueTracking originalIssueTracking = (from x in cee.IssueTrackings where x.Id == issue.IssueTrackingId select x).FirstOrDefault();

            if (originalIssueTracking == null)
            {
                if (issue.IssueTracking != null)
                {
                    var newIssueTracking = new IssueTracking
                    {
                        Budgeted = issue.IssueTracking.Budgeted,
                        FundingType = issue.IssueTracking.FundingType,
                        EstimatedCost = issue.IssueTracking.EstimatedCost,
                        Effort = issue.IssueTracking.Effort,
                        Return = issue.IssueTracking.Return,
                        Scoped = issue.IssueTracking.Scoped,
                        ScopedUserId = issue.IssueTracking.ScopedUserId,
                        ScopedDate = issue.IssueTracking.ScopedDate,
                        PeerReviewed = issue.IssueTracking.PeerReviewed,
                        PeerReviewedUserId = issue.IssueTracking.PeerReviewedUserId,
                        PeerReviewedDate = issue.IssueTracking.PeerReviewedDate,
                        ScopedEstimate = issue.IssueTracking.ScopedEstimate,
                        ScopedActual = issue.IssueTracking.ScopedActual,
                        PeerReviewEstimate = issue.IssueTracking.PeerReviewEstimate,
                        PeerReviewActual = issue.IssueTracking.PeerReviewActual,
                        ImplementedEstimate = issue.IssueTracking.ImplementedEstimate,
                        ImplementedActual = issue.IssueTracking.ImplementedActual,
                        TestedEstimate = issue.IssueTracking.TestedEstimate,
                        TestedActual = issue.IssueTracking.TestedActual,
                        DocumentedEstimate = issue.IssueTracking.DocumentedEstimate,
                        DocumentedActual = issue.IssueTracking.DocumentedActual
                    };

                    cee.IssueTrackings.Add(newIssueTracking);
                    cee.SaveChanges();

                    issue.IssueTrackingId = newIssueTracking.Id;
                }
            }
            else
            {
                cee.Entry(originalIssueTracking).CurrentValues.SetValues(issue.IssueTracking);
                cee.SaveChanges();
            }
        }
Exemplo n.º 27
0
        public DbOperationResult<QuickPipe> SavePipe(Pipe pipe, int userId)
        {
            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    var originalPipe = (from x in cee.Pipes
                                                     .Include("Area")
                                                     .Include("PipeComponents")
                                                     .Include("PipeComponents.PipeComponentType")
                                        where x.Id == pipe.Id
                                        select x).FirstOrDefault();

                    pipe.Area = null;
                    pipe.PipeClass = null;
                    pipe.PipeSize = null;
                    pipe.PipeFluidCode = null;
                    pipe.PipeCategory = null;
                    pipe.PipeSpecialFeature = null;

                    if (originalPipe != null)
                    {
                        DeletePipeAddHistory(pipe, userId, originalPipe, cee);

                        //Save only changed objects
                        if (pipe.ModifiedObjects.PipeComponentsModified)
                        {
                            SavePipeComponents(pipe, cee, pipe.Id, userId);
                        }
                        if (pipe.ModifiedObjects.AttachmentsModified)
                        {
                            UpdatePipeAttachments(pipe, cee);
                        }
                        if (pipe.ModifiedObjects.DocumentationsModified)
                        {
                            SavePipeDocuments(pipe, cee);
                        }
                        if (pipe.ModifiedObjects.RelatedIssuesModified)
                        {
                            SavePipeRelatedIssues(pipe, cee);
                        }
                        if (pipe.ModifiedObjects.PipeAttachmentsModified)
                        {
                            SavePipeAttachments(originalPipe.PipeAttachments);
                        }

                        BuildRevisionHistory(pipe, cee);

                        cee.Entry(originalPipe).CurrentValues.SetValues(pipe);
                        cee.SaveChanges();
                    }
                    else
                    {
                        pipe.IsActive = true;
                        cee.Pipes.Add(pipe);
                        cee.SaveChanges();
                    }

                    var quickPipe = BuildQuickPipe(cee, pipe.Id);
                    return new DbOperationResult<QuickPipe> { EntityResult = quickPipe };
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());

                return BuildOperationalErrorResults<QuickPipe>(ex);
            }
        }
Exemplo n.º 28
0
        public MobilePlantProperty SaveMobilePlantProperty(MobilePlantProperty mobilePlantProperty)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                MobilePlantProperty original = (from x in cee.MobilePlantProperties where x.Id == mobilePlantProperty.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.MobilePlantProperties.Add(mobilePlantProperty);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(mobilePlantProperty);
                }

                cee.SaveChanges();
            }
            return mobilePlantProperty;
        }
Exemplo n.º 29
0
        private void SavePipeComponents(Pipe pipe, CmsEntities cee, int pipeId, int userId)
        {
            foreach (var pipeComponent in pipe.PipeComponents)
            {
                var q = (from x in cee.PipeComponents
                         where x.Id == pipeComponent.Id
                         select x).FirstOrDefault();

                if (q != null)
                {
                    if (q.LastInspectedDate != pipeComponent.LastInspectedDate)
                    {
                        PipeRevisionHistory rv = new PipeRevisionHistory
                        {
                            PipeId = pipeId,
                            Date = DateTime.Now,
                            UserId = userId,
                            Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", pipeComponent.Name, q.LastInspectedDate, pipeComponent.LastInspectedDate),
                            IsSystemMessage = true
                        };

                        AddPipeRevisionHistoryInternal(rv, cee);
                    }

                    //Update Pipe Componet
                    cee.Entry(q).CurrentValues.SetValues(pipeComponent);
                }
                else
                {
                    q = new PipeComponent
                    {
                        PipeId = pipeComponent.PipeId,
                        PipeComponentTypeId = pipeComponent.PipeComponentTypeId,
                        SpecialFeature = pipeComponent.SpecialFeature,
                        Ordinal = pipeComponent.Ordinal,
                        Description = pipeComponent.Description,
                        SubArea = pipeComponent.SubArea,
                        Number = pipeComponent.Number,
                        DrawingId = pipeComponent.DrawingId,
                        NextInspectionDate = pipeComponent.NextInspectionDate,
                        LastInspectedById = pipeComponent.LastInspectedById,
                        LastInspectedDate = pipeComponent.LastInspectedDate,
                        LastModifiedDate = pipeComponent.LastModifiedDate,
                        LastModifiedById = pipeComponent.LastModifiedById,
                        ManufacturerId = pipeComponent.ManufacturerId,
                        ModelId = pipeComponent.ModelId,
                        AreaId = pipeComponent.AreaId
                    };

                    //Add new Pipe Component
                    cee.PipeComponents.Add(q);
                }

                foreach (var pipeComponentPropertyValue in pipeComponent.PipePropertyValues)
                {
                    var qq = (from x in cee.PipePropertyValues
                              where x.Id == pipeComponentPropertyValue.Id
                              select x).FirstOrDefault();

                    if (qq != null)
                    {
                        cee.Entry(qq).CurrentValues.SetValues(pipeComponentPropertyValue);
                    }
                    else
                    {
                        cee.PipePropertyValues.Add(pipeComponentPropertyValue);
                    }
                }
            }
            cee.SaveChanges();
        }
Exemplo n.º 30
0
        public DbOperationResult<ControlSystemAlarmMappingCentum> SaveControlSystemAlarmMappingCentum(ControlSystemAlarmMappingCentum mappingCentum)
        {
            var result = new DbOperationResult<ControlSystemAlarmMappingCentum>();

            try
            {
                using (var cee = new CmsEntities())
                {
                    //check uniquness
                    var duplicateCheck = (from x in cee.ControlSystemAlarmMappingCentums
                                          where x.ColourId == mappingCentum.ColourId
                                                && x.PropertyId == mappingCentum.PropertyId
                                                && x.PriorityId == mappingCentum.PriorityId
                                                && x.Id != mappingCentum.Id
                                          select x).FirstOrDefault();

                    if (duplicateCheck != null)
                    {
                        throw new DuplicateNameException("This Alarm Property-Priority-Property combination already exists.  Existing Id: " + duplicateCheck.Id);
                    }

                    var original = (from x in cee.ControlSystemAlarmMappingCentums where x.Id == mappingCentum.Id select x).FirstOrDefault();

                    if (original == null)
                    {
                        cee.ControlSystemAlarmMappingCentums.Add(mappingCentum);
                        cee.SaveChanges();
                        result.EntityResult = GetControlSystemAlarmMappingCentumsInternal(mappingCentum.Id, cee);
                    }
                    else
                    {
                        cee.Entry(original).CurrentValues.SetValues(mappingCentum);
                        cee.SaveChanges();
                        result.EntityResult = GetControlSystemAlarmMappingCentumsInternal(original.Id, cee);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                result.ServerErrorMessages.Add(string.Format("Could not Save Alarm Property-Colour-Prioritiy record.{0}{1}", Environment.NewLine, ex.Message));
            }
            return result;
        }