public MechanicalAttachmentsControl(MechanicalEquipment mechanicalEquipment)
        {
            mMechanicalEquipment = mechanicalEquipment;

            InitializeComponent();

            CompositionInitializer.SatisfyImports(this);

            ViewModel = new MechanicalEquipmentAttachmentsViewModel(mechanicalEquipment) {View = this};

            ViewModel.UploadComplete += () =>
            {
                RadProgressBar1.Visibility = Visibility.Collapsed;
            };

            ViewModel.Loaded += (s1) =>
                                     {
                                         Utils.ResetOriginalValues(AttachedFilesGridView);
                                         Utils.SetUpChangeEvents(AttachedFilesGridView, EventAggregator, mechanicalEquipment);
                                         DataContext = ViewModel;
                                     };

            ViewModel.ErrorOccurred += (message) =>
            {

                List<string> errors = new List<string>();
                errors.Add(message);
                this.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("", errors));
            };

            ViewModel.CollectionChanged += (count) => OnCollectionChanged(count);
        }
Example #2
0
        public bool GetMechanicalEquipmentType(string typeName, MechanicalEquipment newEquipment, int rowIndex)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                if (MetaData.ImportType == CommonUtils.ImportType.UpdateMechanical)
                {
                    return false;
                }
            }

            if (string.IsNullOrEmpty(typeName))
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Type row  is blank. Skipping.", WorkSheetName, rowIndex));
                return true;
            }

            MechanicalEquipmentType equipmentType = (from x in mExistingMechanicalEquipmentTypes where string.Compare(x.Name, typeName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
            if (equipmentType == null)
            {
                if (CanCreateProperties)
                {
                    equipmentType = new MechanicalEquipmentType {Name = typeName};
                    mExistingMechanicalEquipmentTypes.Add(equipmentType);
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}':Could not match '{2}' MechanicalEquipmentType. Skipping.", WorkSheetName, rowIndex, typeName));
                    return true;
                }
            }

            newEquipment.MechanicalEquipmentType = equipmentType;
            return false;
        }
        public MechanicalEquipmentDocumentsControl(MechanicalEquipment mechanicalEquipment)
        {
            InitializeComponent();

            mViewModel = new MechanicalEquipmentDocumentsViewModel(mechanicalEquipment) {View = this};
            mViewModel.Loaded += ViewModelLoaded;
            mViewModel.CollectionChanged += count => OnCollectionChanged(count);
        }
        public MechanicalEquipmentComponentsControl(MechanicalEquipment mechanicalEquipment)
        {
            if (DesignerProperties.IsInDesignTool) { return; }
            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            viewModel = new MechanicalEquipmentComponentsViewModel(mechanicalEquipment);
            viewModel.CollectionChanged += (count) => OnCollectionChanged(count);

            viewModel.View = this;
            DataContext = viewModel;
        }
        public MechanicalRelatedIssuesViewModel(MechanicalEquipment mechanicalEquipment)
        {
            CompositionInitializer.SatisfyImports(this);
            mMechanicalEquipment = mechanicalEquipment;

            LoadData();

            CreateCommand = new DelegateCommand<object>(AddRelatedIssueHandler, CanCreate);
            LinkCommand = new DelegateCommand<object>(LinkIssueButtonHandler, CanLink);
            ViewCommand = new DelegateCommand<object>(OpenIssueButtonHandler, CanView);
        }
        public MechanicalEquipmentDocumentsViewModel(MechanicalEquipment mechanicalEquipment)
        {
            CompositionInitializer.SatisfyImports(this);
            mMechanicalEquipment = mechanicalEquipment;

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetMechanicalDocumentsCompleted += cmsWebServiceClient_GetMechanicalDocumentsCompleted;
            cmsWebServiceClient.GetMechanicalDocumentsAsync(mechanicalEquipment.Id);

            AddCommand = new DelegateCommand<object>(AddRelatedDocumentHandler, CanAdd);
            DeleteCommand = new DelegateCommand<object>(RemoveRelatedDocumentHandler, CanDelete);
            ViewCommand = new DelegateCommand<object>(ViewRelatedDocumentHandler, CanView);
        }
        public MechanicalRelatedIssuesControl(MechanicalEquipment mechanicalEquipment)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            InitializeComponent();

            MechanicalRelatedIssuesViewModel model = new MechanicalRelatedIssuesViewModel(mechanicalEquipment);
            model.CollectionChanged += (count) => { OnCollectionChanged(count); };
            model.View = this;
            DataContext = model;
        }
        public MechanicalEquipmentAttachmentsViewModel(MechanicalEquipment mechanicalEquipment)
        {
            CompositionInitializer.SatisfyImports(this);

            AddAttachmentCommand = new DelegateCommand<object>(AddFileHandler, CanAdd);
            RemoveAttachmentCommand = new DelegateCommand<object>(RemoveFileHandler, CanDelete);
            ExportButton = new DelegateCommand<object>(ExportButtonHandler, x => true);

            mMechanicalEquipment = mechanicalEquipment;

            Attachments = new ObservableCollection<MechanicalEquipmentAttachment>();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAttachmentTypesCompleted += cmsWebServiceClient_GetAttachmentTypesCompleted;
            cmsWebServiceClient.GetAttachmentTypesAsync();
        }
        private List<UpperEquipment> mAllUpperEquipments; //everytime the Selected Area is bound we need to reset the upper equipment list using the area id selected.

        #endregion Fields

        #region Constructors

        public AddMechanicalEquipmentViewModel()
        {
            CompositionInitializer.SatisfyImports(this);
            Equipment = new MechanicalEquipment();

            var pidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode);
            var specificationDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode);
            var getMechEquipTypesTask = DatabaseLoader.GetMechanicalEquipmentTypes();
            var getUpperEquipmentsTask = DatabaseLoader.GetUpperEquipments();

            List<Task> tasks = new List<Task> { pidDocumentsTask, specificationDocumentsTask, getMechEquipTypesTask, getUpperEquipmentsTask };

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    PandIDDocuments = pidDocumentsTask.Result;
                    RaisePropertyChanged("PandIDDocuments");

                    SpecificationDocuments = specificationDocumentsTask.Result;
                    RaisePropertyChanged("SpecificationDocuments");

                    Types = getMechEquipTypesTask.Result;
                    RaisePropertyChanged("Types");

                    mAllUpperEquipments = getUpperEquipmentsTask.Result;
                    mAllUpperEquipments.Insert(0, new UpperEquipment { Name = CMS.Constants.UpperEquipmentNullName });
                    UpperEquipments = new List<UpperEquipment>(mAllUpperEquipments);
                    RaisePropertyChanged("UpperEquipments");

                    Areas = (from a in CMS.Cache.Areas where a.IsActive && a.SiteId == CMS.AppSetting.DefaultSiteId select a).ToList();
                    RaisePropertyChanged("Areas");

                    OnDataSourceLoaded();
                });

            });

            OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanAdd);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true);
        }
        private void BuildRevisionHistory(MechanicalEquipment equip, CmsEntities cee)
        {
            var latestPrh = (from x in cee.MechanicalEquipmentRevisionHistories
                             where x.MechanicalEquipmentId == equip.Id
                             select x.Revision).ToList();

            if (latestPrh.Count > 0)
            {

                foreach (MechanicalEquipmentRevisionHistory revisionHistory in equip.MechanicalEquipmentRevisionHistories)
                {
                    if (revisionHistory.Id == 0)
                    {
                        revisionHistory.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT;
                        cee.MechanicalEquipmentRevisionHistories.Add(revisionHistory);
                    }
                }
            }
            else
            {
                foreach (MechanicalEquipmentRevisionHistory revisionHistory in equip.MechanicalEquipmentRevisionHistories)
                {
                    if (revisionHistory.Id == 0)
                    {
                        revisionHistory.Revision = VERSIONINCREMENT;
                        cee.MechanicalEquipmentRevisionHistories.Add(revisionHistory);
                    }
                }
            }
        }
Example #11
0
        private void AddInsertRevisionHistory(MechanicalEquipment mechanicalEquipment)
        {
            var revision = new decimal(1.000);

            Cee.MechanicalEquipments.Add(mechanicalEquipment);
            var rvh = new MechanicalEquipmentRevisionHistory
            {
                Date = DateTime.Now,
                UserId = MetaData.UserId,
                Description = string.Format("Import Tool - [Create]  : {0}", MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };

            mechanicalEquipment.MechanicalEquipmentRevisionHistories.Add(rvh);
        }
        private void ViewModel_DataSourceLoaded(object obj)
        {
            DataContext = ViewModel;

            mMechanicalEquipment = ViewModel.Equipment;

            //Components
            mComponentsControl = new MechanicalEquipmentComponentsControl(ViewModel.Equipment);
            mComponentsControl.CollectionChanged += (count) =>
                {
                    mMechanicalEquipment.GeneralEquipmentRelatedItemsCount.PropertyOrComponents = count;
                    SetTabHeadersText();
                };
            ComponentsTab.Content = mComponentsControl;

            //Issues
            mMechanicalRelatedIssuesControl = new MechanicalRelatedIssuesControl(ViewModel.Equipment);
            mMechanicalRelatedIssuesControl.CollectionChanged += (count) =>
                {
                    mMechanicalEquipment.GeneralEquipmentRelatedItemsCount.Issues = count;
                    SetTabHeadersText();
                };
            RelatedIssuesTab.Content = mMechanicalRelatedIssuesControl;

            //Attachements
            mMechanicalAttachmentsControl = new MechanicalAttachmentsControl(ViewModel.Equipment);
            mMechanicalAttachmentsControl.CollectionChanged += (count) =>
                {
                    mMechanicalEquipment.GeneralEquipmentRelatedItemsCount.Attachments = count;
                    SetTabHeadersText();
                };
            AttachmentsTab.Content = mMechanicalAttachmentsControl;

            //Documents Tab
            mDocumentsControl = new MechanicalEquipmentDocumentsControl(ViewModel.Equipment);
            mDocumentsControl.CollectionChanged += (count) =>
                {
                    mMechanicalEquipment.GeneralEquipmentRelatedItemsCount.Documents = count;
                    SetTabHeadersText();
                };

            mDocumentsControl.ControlLoaded += mDocumentsControl_ControlLoaded;
            RoutedEventHandler docsloaded = null;

            docsloaded = (s1, e1) =>
                             {
                                 //This will hook up change events on all controls
                                 Utils.SetUpChangeEvents((UIElement)DocumentsTab.Content, EventAggregator, ViewModel.Equipment);
                                 DocumentsTab.Loaded -= docsloaded;

                                 //GET Tab Counts --------------------------------------------------
                                 CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
                                 cmsWebServiceClient.GetMechanicalRelatedItemsCountCompleted += (s2, e2) =>
                                 {
                                     mMechanicalEquipment.GeneralEquipmentRelatedItemsCount = e2.Result;
                                     SetTabHeadersText();
                                 };
                                 cmsWebServiceClient.GetMechanicalRelatedItemsCountAsync(mMechanicalEquipment.Id);

                             };

            DocumentsTab.Loaded += docsloaded;

            //This will hook up change events on all controls
            Utils.SetUpChangeEvents(EquipmentControl.Content, EventAggregator, ViewModel.Equipment);
            Utils.SetUpChangeEvents((UIElement)ComponentsTab.Content, EventAggregator, ViewModel.Equipment);
            Utils.SetUpChangeEvents((UIElement)RelatedIssuesTab.Content, EventAggregator, ViewModel.Equipment);
            Utils.SetUpChangeEvents((UIElement)AttachmentsTab.Content, EventAggregator, ViewModel.Equipment);

            RoutedEventHandler loaded = null;
            loaded = (s1, e1) =>
                         {
                             //This will hook up change events on all controls
                             Utils.SetUpChangeEvents((UIElement)AttachmentsTab.Content, EventAggregator, ViewModel.Equipment);
                             AttachmentsTab.Loaded -= loaded;
                         };

            AttachmentsTab.Loaded += loaded;
        }
Example #13
0
        private void AddUpdateRevisionHistory(MechanicalEquipment mechanicalEquipment)
        {
            const decimal incrediment = 0.001m;
            var revision = new decimal(1.000);

            List<decimal> foo = (from x in Cee.MechanicalEquipmentRevisionHistories where x.MechanicalEquipmentId == mechanicalEquipment.Id orderby x.Revision descending select x.Revision).ToList();

            if (foo.Count > 0)
            {
                revision = foo[0] + incrediment;
            }

            var rvh = new MechanicalEquipmentRevisionHistory
            {
                Date = DateTime.Now,
                MechanicalEquipmentId = mechanicalEquipment.Id,
                UserId = MetaData.UserId,
                Description = string.Format("Import Tool - [Update]  : {0}", MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };

            mechanicalEquipment.MechanicalEquipmentRevisionHistories.Add(rvh);
        }
Example #14
0
        public void ImportMechanicalEquipment()
        {
            mForm.AddMessage(MessageType.Info, "-------------------- Importing ImportMechanicalEquipment --------------------");
            List<MechEquipment> mechEquipments = (from x in mOldIssuesDataContext.MechEquipments select x).ToList();

            //for (int i = 1; i < 10000; i++)
            //{

            //    CmsEquipmentDatabase.Web.DataModel.CmsEquipment.MobilePlant newMechanicalEquipment = new CmsEquipmentDatabase.Web.DataModel.CmsEquipment.MobilePlant()
            //    {

            //        Tag = "Mechanical Equipment " + i,
            //        //EllipseId = mechEquipment.Name,
            //        MobileTypeId =  new Random().Next(1,3),
            //        OwnerId = new Random().Next(1,6),
            //        AreaId = new Random().Next(1, 38),
            //        HirerId = new Random().Next(1, 5),
            //        Description = "Description " + i,
            //        Notes = "Notes " + i
            //    };
            //    mCee.MobilePlants.AddObject(newMechanicalEquipment);
            //}
            //mCee.SaveChanges();
            //return;

            foreach (var mechEquipment in mechEquipments)
            {
                string[] nameItems = mechEquipment.Name.Split('-');
                if (nameItems.Count() > 2)
                {

                    string areaString = nameItems[1];
                    int areaId = Int32.Parse(areaString);

                    var area = (from x in mCee.Areas where x.AreaNumber == areaId select x).FirstOrDefault();

                    if (area == null)
                    {
                        area = new Area {Name = areaString, AreaNumber = areaId, SiteId = 1};
                        mCee.Areas.AddObject(area);
                        mCee.SaveChanges();
                    }

                    string newName = String.Empty;
                    if (nameItems.Count() == 5)
                    {
                        newName = String.Format("{1}-{2}-{3}-{4}", nameItems[0], nameItems[1], nameItems[2], nameItems[3], nameItems[4]);
                    }
                    else if( nameItems.Count() == 4 )
                    {
                        newName =String.Format("{1}-{2}-{3}", nameItems[0], nameItems[1], nameItems[2], nameItems[3]);
                    }
                    else if( nameItems.Count() == 3 )
                    {
                        newName = String.Format("{1}-{2}", nameItems[0], nameItems[1], nameItems[2]);
                    }
                    else
                    {

                    }

                    MechanicalEquipment newMechanicalEquipment = new MechanicalEquipment()
                                                                     {
                                                                         Name = newName,
                                                                         EllipseId = mechEquipment.Name,
                                                                         MechEquipmentTypeId = (from x in mCee.MechanicalEquipmentTypes
                                                                                                where String.Compare(x.Name, mechEquipment.MechEquipmentCategory.Name, 0) == 0
                                                                                                select x.Id).FirstOrDefault(),
                                                                         AreaId = area.Id,
                                                                         Description = mechEquipment.Description,
                                                                         Notes = mechEquipment.Notes
                                                                     };

                    var mechanicalEquipmentExist = (from x in mCee.MechanicalEquipments where String.Compare(x.Name, newMechanicalEquipment.Name, true) == 0 select x).FirstOrDefault();

                    if (mechanicalEquipmentExist == null)
                    {
                        string message = String.Format("Adding Mechanical Equipment '{0}'", newMechanicalEquipment.Name);
                        mForm.AddMessage(MessageType.Info, message);
                        mCee.MechanicalEquipments.AddObject(newMechanicalEquipment);
                        mCee.SaveChanges();
                    }
                    else
                    {
                        string message = String.Format("Mechanical Equipment '{0}' already exist, skipping", mechanicalEquipmentExist.Name);
                        mForm.AddMessage(MessageType.Warning, message);
                    }
                }
                else
                {
                    string message = String.Format("Mechanical Equipment '{0}' doesnt have corrent name, skipping", mechEquipment.Name);
                    mForm.AddMessage(MessageType.Error, message);
                }
            }

            mCee.SaveChanges();
        }
Example #15
0
        private void InsertData(IList<MechanicalDataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }

            for (int i = 0; i < importData.Count; i++)
            {
                MechanicalDataAdapter adapter = importData[i];

                MechanicalEquipment equipment = (from x in Cee.MechanicalEquipments where x.Name.Equals(adapter.Tag, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

                if (equipment != null)
                {
                    RaiseMessage(CommonUtils.MessageType.Warning, string.Format(BuildDuplicateNameExistsInDbMessage(adapter.Tag, adapter.RowNumber)));
                    continue;
                }

                equipment = new MechanicalEquipment();

                if (adapter.IsActive.HasValue)
                {
                    equipment.IsActive = adapter.IsActive.Value;
                }
                else
                {
                    equipment.IsActive = true; //assume true
                }

                int areaId;
                if (GetAreaFailed(adapter.AreaNumber, adapter.RowNumber, out areaId, false))
                {
                    continue;
                }
                if (areaId > 0)
                {
                    equipment.AreaId = areaId;
                }

                if (GetMechanicalEquipmentType(adapter.EquipmentType, equipment, adapter.RowNumber)) continue;

                equipment.Description = adapter.Description;
                equipment.Notes = adapter.Notes;
                equipment.Name = adapter.Tag;

                //Specification
                if (!string.IsNullOrEmpty(adapter.Specification))
                {
                    int docId;
                    if (GetSpecDocumentFailed(adapter.Specification, out docId, adapter.RowNumber))
                    {
                        continue;
                    }
                    equipment.SpecificationDocumentId = docId;
                }

                //PandID
                if (!string.IsNullOrEmpty(adapter.PandID))
                {
                    int docId;
                    if (GetPIDDocumentFailed(adapter.PandID, out docId, adapter.RowNumber))
                    {
                        continue;
                    }
                    equipment.PandIDDocumentId = docId;
                }

                if (!String.IsNullOrEmpty(adapter.MaintSysId))
                {
                    equipment.MaintSystemId = adapter.MaintSysId;
                }

                if (!adapter.Classified.HasValue)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Classified row  is blank. Skipping.", WorkSheetName, adapter.RowNumber));
                    continue;
                }
                equipment.Classified = adapter.Classified.Value;

                IList<string> tags = (from x in importData select x.Tag).ToList();
                if (DuplicateItemNameFoundInExcell(equipment.Name, tags, adapter.RowNumber))
                {
                    continue;
                }

                tags = (from x in Cee.MechanicalEquipments select x.Name).ToList();

                if (DuplicateItemNameFoundInDatabase(equipment.Name, tags, adapter.RowNumber))
                {
                    continue;
                }

                AddInsertRevisionHistory(equipment);

                mSavedResults.Add(equipment);
            }

            if (mSavedResults.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Equipments were added from from worksheet {0}.", WorkSheetName));
            }
            else
            {
                //SAVE
                Cee.SaveChanges();

                foreach (MechanicalEquipment equipment in mSavedResults)
                {
                    RaiseMessage(CommonUtils.MessageType.Added, string.Format("Processed Equipment '{0}'.", equipment.Name));
                }
            }
        }
        public DbOperationResult<QuickMechanical> SaveMechanicalEquipment(MechanicalEquipment equip, int userId)
        {
            try
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    var originalObject = (from x in cee.MechanicalEquipments
                                              .Include("MechanicalEquipmentComponents")
                                              .Include("MechanicalEquipmentComponents.MechanicalEquipmentComponentType")
                                          where x.Id == equip.Id
                                          select x).FirstOrDefault();

                    if (originalObject != null)
                    {
                        var mechanicalComponentsToBeDeleted = from x in originalObject.MechanicalEquipmentComponents
                                                              where !equip.MechanicalEquipmentComponents.Any(x1 => x1.Id == x.Id)
                                                              select x;

                        BuildRevisionHistory(equip, userId, mechanicalComponentsToBeDeleted, cee);
                        BuildRevisionHistory(equip, cee);

                        foreach (var mechanicalComponent in mechanicalComponentsToBeDeleted)
                        {
                            DeleteMechanicalEquipmentComponent(mechanicalComponent);
                        }

                        SaveMechanicalEquipmentComponents(equip.MechanicalEquipmentComponents.ToList(), userId);
                        SaveMechanicalAttachments(equip.MechanicalEquipmentAttachments.ToList());
                        SaveMechanicalRelatedIssues(equip, cee);
                        SaveMechanicalDocuments(equip, cee);

                        cee.Entry(originalObject).CurrentValues.SetValues(equip);
                        cee.SaveChanges();
                    }
                    else
                    {
                        equip.EquipmentModule = null;
                        equip.MechanicalEquipmentType = null;
                        equip.Unit = null;
                        int areaId = equip.AreaId;
                        equip.Area = null;
                        equip.AreaId = areaId;
                        equip.IsActive = true;

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

                    var quickMechanical = BuildQuickMechanical(cee, equip.Id);

                    return new DbOperationResult<QuickMechanical> { EntityResult = quickMechanical };
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                return BuildOperationalErrorResults<QuickMechanical>(ex);
            }
        }
        private void SaveMechanicalRelatedIssues(MechanicalEquipment mechanicalEquipment, CmsEntities cee)
        {
            //Delete
            List<IssueRelatedMechanicalEquipment> originals = (from x in cee.IssueRelatedMechanicalEquipments where x.MechanicalEquipmentId == mechanicalEquipment.Id select x).ToList();

            originals.ForEach(x => cee.IssueRelatedMechanicalEquipments.Remove(x));

            foreach (IssueRelatedMechanicalEquipment issueRelatedMechanicalEquipment in mechanicalEquipment.IssueRelatedMechanicalEquipments)
            {
                IssueRelatedMechanicalEquipment newObject = new IssueRelatedMechanicalEquipment
                                                                {
                                                                    MechanicalEquipmentId = mechanicalEquipment.Id,
                                                                    IssueId = issueRelatedMechanicalEquipment.IssueId,
                                                                    Notes = issueRelatedMechanicalEquipment.Notes,
                                                                    TestedById = issueRelatedMechanicalEquipment.TestedById,
                                                                    TestedDate = issueRelatedMechanicalEquipment.TestedDate,
                                                                    ImplementedById = issueRelatedMechanicalEquipment.ImplementedById,
                                                                    ImplementedDate = issueRelatedMechanicalEquipment.ImplementedDate
                                                                };

                cee.IssueRelatedMechanicalEquipments.Add(newObject);
            }
        }
        private void SaveMechanicalDocuments(MechanicalEquipment mechanicalEquipment, CmsEntities cee)
        {
            if (mechanicalEquipment.MechanicalDocuments == null) { return; }
            //Delete originals
            List<DocumentEquipment> originals = (from x in cee.DocumentEquipments
                                                 where x.EquipmentId == mechanicalEquipment.Id
                                                 && x.EquipmentTypeId == (int)CommonUtils.EquipmentTypeCode.MECH
                                                 select x).ToList();
            originals.ForEach(x => cee.DocumentEquipments.Remove(x));

            foreach (DocumentEquipment document in mechanicalEquipment.MechanicalDocuments)
            {
                DocumentEquipment newObject = new DocumentEquipment
                {
                    EquipmentId = mechanicalEquipment.Id,
                    DocumentId = document.DocumentId,
                    EquipmentTypeId = (int)CommonUtils.EquipmentTypeCode.MECH
                };

                cee.DocumentEquipments.Add(newObject);
            }
        }
        private static void BuildRevisionHistory(MechanicalEquipment equip, int userId, IEnumerable<MechanicalEquipmentComponent> mechanicalComponentsToBeDeleted, CmsEntities cee)
        {
            MechanicalEquipmentRevisionHistory rh = new MechanicalEquipmentRevisionHistory();

            string[] componentMessages = (from x in mechanicalComponentsToBeDeleted select "Name: " + x.Name + " Type: " + x.MechanicalEquipmentComponentType.Name).ToArray();

            if (componentMessages.Length > 0)
            {
                string removedItems = string.Join(",", componentMessages);

                rh.Description = string.Format("Mechanical Components were removed : {0}", removedItems);
                rh.MechanicalEquipmentId = equip.Id;
                rh.Date = DateTime.Now;
                rh.UserId = userId;
                rh.IsSystemMessage = true;

                var latestPrh = (from x in cee.MechanicalEquipmentRevisionHistories
                                 where x.MechanicalEquipmentId == equip.Id
                                 select x.Revision).ToList();

                if (latestPrh.Count > 0)
                {
                    rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT;
                }
                else
                {
                    rh.Revision = VERSIONINCREMENT;
                }
                cee.MechanicalEquipmentRevisionHistories.Add(rh);
            }
        }