private void LinkIssueButtonHandler(object parameter)
        {
            AddRelatedIssueDialog dialog = new AddRelatedIssueDialog();
            dialog.Show();
            dialog.Closed +=
                (s1, e1) =>
                {
                    if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                    {
                        List<Issue> toAdd = dialog.SelectedIssues.ToList();

                        foreach (var issue in toAdd)
                        {
                            var existing = (from x in mMobilePlant.IssueRelatedMobilePlants
                                            where x.IssueId == issue.Id
                                                  && x.MobilePlantId == mMobilePlant.Id
                                            select x).FirstOrDefault();

                            if (existing == null)
                            {
                                IssueRelatedMobilePlant ird = new IssueRelatedMobilePlant
                                {
                                    IssueId = issue.Id,
                                    Issue = issue,
                                    MobilePlantId = mMobilePlant.Id,
                                    MobilePlant = mMobilePlant
                                };

                                mMobilePlant.IssueRelatedMobilePlants.Add(ird);

                            }
                        }

                        if (toAdd.Any())
                        {
                            LoadData();

                            Utils.OnCollectionChanged(EventAggregator, mMobilePlant, "MobilePlantRelatedIssuesViewModel", true);

                            OnCollectionChanged();
                        }
                    }
                };
        }
        private void AddRelatedIssueHandler(object parameter)
        {
            AddIssueDialog aid = new AddIssueDialog();

            aid.Closed += (s1, e1) =>
            {
                //Hadle dialog closed
                if (aid.DialogResult.HasValue && aid.DialogResult.Value)
                {
                    Issue newIssue = aid.Issue;

                    IssueRelatedMobilePlant IssueRelatedMobilePlant = (from x in mMobilePlant.IssueRelatedMobilePlants
                                                                     where x.IssueId == newIssue.Id
                                                                           && x.MobilePlantId == mMobilePlant.Id
                                                                     select x).FirstOrDefault();
                    if (IssueRelatedMobilePlant == null)
                    {
                        IssueRelatedMobilePlant ird = new IssueRelatedMobilePlant
                        {
                            IssueId = newIssue.Id,
                            Issue = newIssue,
                            MobilePlantId = mMobilePlant.Id,
                            MobilePlant = mMobilePlant
                        };

                        mMobilePlant.IssueRelatedMobilePlants.Add(ird);

                        LoadData();

                        Utils.OnCollectionChanged(EventAggregator, mMobilePlant, "MobilePlantRelatedIssuesViewModel", true);

                        OnCollectionChanged();
                    }

                }
            };

            aid.Show();
        }
Пример #3
0
        private void SaveIssueRelatedMobilePlants(Issue issue, Issue originalIssue, CmsEntities cee)
        {
            log.Verbose("SaveIssueRelatedMobilePlants()");
            //Delete IssueRelatedMobilePlantEquipment
            cee.DeleteWhere<IssueRelatedMobilePlant>(cee, x => x.IssueId == issue.Id);

            cee.Configuration.AutoDetectChangesEnabled = false;

            //Save SaveIssueRelatedMobilePlantEquipments
            foreach (IssueRelatedMobilePlant mobilePlant in issue.IssueRelatedMobilePlants.ToList())
            {
                var newMobilePlantEquipment = new IssueRelatedMobilePlant
                {
                    IssueId = issue.Id,
                    MobilePlantId = mobilePlant.MobilePlantId,
                    Notes = mobilePlant.Notes
                };

                if (mobilePlant.Implemented && mobilePlant.ImplementedById.HasValue)
                {
                    newMobilePlantEquipment.Implemented = true;
                    newMobilePlantEquipment.ImplementedById = mobilePlant.ImplementedById;
                    newMobilePlantEquipment.ImplementedDate = mobilePlant.ImplementedDate;
                }

                if (mobilePlant.Tested && mobilePlant.TestedById.HasValue)
                {
                    newMobilePlantEquipment.Tested = true;
                    newMobilePlantEquipment.TestedById = mobilePlant.ImplementedById;
                    newMobilePlantEquipment.TestedDate = mobilePlant.ImplementedDate;
                }

                originalIssue.IssueRelatedMobilePlants.Add(newMobilePlantEquipment);
            }
            cee.Configuration.AutoDetectChangesEnabled = true;
        }
Пример #4
0
        private void SaveMobilePlantRelatedIssues(MobilePlant mobilePlant, CmsEntities cee)
        {
            //Delete original
            List<IssueRelatedMobilePlant> originals =
                (from x in cee.IssueRelatedMobilePlants where x.MobilePlantId == mobilePlant.Id select x).ToList();
            originals.ForEach(x => cee.IssueRelatedMobilePlants.Remove(x));

            foreach (IssueRelatedMobilePlant relatedMobilePlant in mobilePlant.IssueRelatedMobilePlants)
            {
                IssueRelatedMobilePlant newObject = new IssueRelatedMobilePlant
                                                            {
                                                                MobilePlantId = mobilePlant.Id,
                                                                IssueId = relatedMobilePlant.IssueId,
                                                                Notes = relatedMobilePlant.Notes,
                                                                TestedById = relatedMobilePlant.TestedById,
                                                                TestedDate = relatedMobilePlant.TestedDate,
                                                                ImplementedById = relatedMobilePlant.ImplementedById,
                                                                ImplementedDate = relatedMobilePlant.ImplementedDate
                                                            };

                cee.IssueRelatedMobilePlants.Add(newObject);
            }
        }
        private void AddButtonHandler(object parameter)
        {
            AddIssueDialog aid = new AddIssueDialog();

            aid.Closed += (s1, e1) =>
                              {
                                  //Hadle dialog closed
                                  if (aid.DialogResult.HasValue && aid.DialogResult.Value)
                                  {
                                      Issue newIssue = aid.Issue;

                                      IssueRelatedMobilePlant issueRelated = (from x in mMobilePlant.IssueRelatedMobilePlants
                                                                              where x.IssueId == newIssue.Id
                                                                                    && x.MobilePlantId == mMobilePlant.Id
                                                                              select x).FirstOrDefault();
                                      if (issueRelated == null)
                                      {
                                          IssueRelatedMobilePlant ird = new IssueRelatedMobilePlant
                                                                            {
                                                                                IssueId = newIssue.Id,
                                                                                Issue = newIssue,
                                                                                MobilePlantId = mMobilePlant.Id,
                                                                                MobilePlant = mMobilePlant
                                                                            };

                                          mMobilePlant.IssueRelatedMobilePlants.Add(ird);
                                          MobilePlantIssues.Add(ird);

                                          RaisePropertyChanged("MobilePlantIssues");
                                          Utils.OnCollectionChanged(EventAggregator, mMobilePlant, "MobilePlantIssuesViewModel", true);

                                          OnCollectionChanged();
                                      }

                                      //open created issue in a new tab
                                      EventAggregator.GetEvent<PrismEvents.OpenTabPrismEvent>().Publish(newIssue);
                                  }
                              };

            aid.Show();
        }