Пример #1
0
        public void AssignIssueToPipe(int pipeId, int issueId)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                IssueRelatedPipe pi = new IssueRelatedPipe();
                pi.PipeId = pipeId;
                pi.IssueId = issueId;

                cee.IssueRelatedPipes.Add(pi);
                cee.SaveChanges();
            }
        }
        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 mPipe.IssueRelatedPipes
                                            where x.IssueId == issue.Id
                                                  && x.PipeId == mPipe.Id
                                            select x).FirstOrDefault();

                            if (existing == null)
                            {
                                IssueRelatedPipe ird = new IssueRelatedPipe
                                {
                                    IssueId = issue.Id,
                                    Issue = issue,
                                    PipeId = mPipe.Id,
                                    Pipe = mPipe
                                };

                                mPipe.ModifiedObjects.RelatedIssuesModified = true;
                                mPipe.IssueRelatedPipes.Add(ird);

                            }
                        }

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

                            Utils.OnCollectionChanged(EventAggregator, mPipe, "PipeRelatedIssuesViewModel", true);

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

            //Save
            foreach (IssueRelatedPipe pipeIssue in issue.IssueRelatedPipes.ToList())
            {
                IssueRelatedPipe newIssueRelatedPipe = new IssueRelatedPipe
                {
                    IssueId = pipeIssue.IssueId,
                    PipeId = pipeIssue.PipeId,
                    Notes = pipeIssue.Notes
                };

                if (pipeIssue.Implemented)
                {
                    if (pipeIssue.ImplementedById.HasValue)
                    {
                        newIssueRelatedPipe.Implemented = pipeIssue.Implemented;
                        newIssueRelatedPipe.ImplementedById = pipeIssue.ImplementedById;
                        newIssueRelatedPipe.ImplementedDate = pipeIssue.ImplementedDate;
                    }
                }

                if (pipeIssue.Tested)
                {
                    if (pipeIssue.TestedById != null)
                    {
                        newIssueRelatedPipe.Tested = pipeIssue.Tested;
                        newIssueRelatedPipe.TestedById = pipeIssue.TestedById;
                        newIssueRelatedPipe.TestedDate = pipeIssue.TestedDate;
                    }
                }

                originalIssue.IssueRelatedPipes.Add(newIssueRelatedPipe);
            }
        }
        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;

                    IssueRelatedPipe issueRelatedPipe = (from x in mPipe.IssueRelatedPipes
                                                                     where x.IssueId == newIssue.Id
                                                                           && x.PipeId == mPipe.Id
                                                                     select x).FirstOrDefault();
                    if (issueRelatedPipe == null)
                    {
                        IssueRelatedPipe ird = new IssueRelatedPipe
                        {
                            IssueId = newIssue.Id,
                            Issue = newIssue,
                            PipeId = mPipe.Id,
                            Pipe = mPipe
                        };

                        mPipe.IssueRelatedPipes.Add(ird);
                        mPipe.ModifiedObjects.RelatedIssuesModified = true;

                        LoadData();

                        Utils.OnCollectionChanged(EventAggregator, mPipe, "PipeRelatedIssuesViewModel", true);

                        OnCollectionChanged();
                    }

                }
            };

            aid.Show();
        }
        private void AddButtonHandler(object parameter)
        {
            AddRelatedPipeDialog dialog = new AddRelatedPipeDialog();
            dialog.Show();
            dialog.Closed +=
                (s1, e1) =>
                {
                    if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                    {
                        List<QuickPipe> toAdd = dialog.SelectedPipes.ToList();

                        foreach (QuickPipe newQuickPipe in toAdd)
                        {
                            IssueRelatedPipe issueRelatedPipe = (from x in mIssue.IssueRelatedPipes
                                                                 where x.PipeId == newQuickPipe.Id && x.IssueId == mIssue.Id
                                                                 select x).FirstOrDefault();
                            if (issueRelatedPipe == null)
                            {

                                IssueRelatedPipe irp = new IssueRelatedPipe
                                {
                                    IssueId = mIssue.Id,
                                    PipeId = newQuickPipe.Id,
                                    Pipe = new Pipe
                                        {
                                            FormattedName = newQuickPipe.Name,
                                            IsActive = newQuickPipe.IsActive
                                        }
                                };
                                mIssue.IssueRelatedPipes.Add(irp);
                            }
                        }

                        RaiseChangeEvent();
                        OnCollectionChanged();

                        RaisePropertyChanged("IssueRelatedPipes");
                    }
                };
        }