public AddEditMilestoneDelayDialog(IssueMilestoneDelay issueMilestoneDelay)
        {
            InitializeComponent();

            CompositionInitializer.SatisfyImports(this);

            Title = "Edit Milestone Delay";
            AddEditMilestoneDelayViewModel viewModel = new AddEditMilestoneDelayViewModel(issueMilestoneDelay) {View = this};
            viewModel.Loaded += () =>{DataContext = viewModel;};
        }
        public AddEditMilestoneDelayViewModel(IssueMilestoneDelay issueMilestoneDelay)
        {
            mInAddMode = false;
            mIssueMilestoneDelay = issueMilestoneDelay;
            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetIssueMilestoneDelayTypesCompleted += cmsWebServiceClient_GetIssueMilestoneDelayTypesCompleted;
            cmsWebServiceClient.GetIssueMilestoneDelayTypesAsync();

            OkButtonCommand = new DelegateCommand<object>(OkButtonHandler, CanExecuteOkButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CanelButtonHandler, CanExecuteOkButtonHandler);
        }
Example #3
0
        private static void SaveMilestones(Issue issue, CmsEntities cee)
        {
            log.Verbose("SaveMilestones()");
            try
            {
                var originalMilestones = (from x in cee.IssueMilestones.Include("IssueMilestoneDelays") where x.IssueId == issue.Id select x).ToList();

                //gather db delays
                List<IssueMilestoneDelay> dbIssueMilestoneDelays = new List<IssueMilestoneDelay>();
                foreach (var original in originalMilestones)
                {
                    if (original.IssueMilestoneDelays != null && original.IssueMilestoneDelays.Any())
                    {
                        dbIssueMilestoneDelays.AddRange(original.IssueMilestoneDelays);
                    }
                }

                //gather memory delays
                List<IssueMilestoneDelay> memoryMilestoneDelays = new List<IssueMilestoneDelay>();
                foreach (var mem in issue.IssueMilestones)
                {
                    if (mem.IssueMilestoneDelays != null && mem.IssueMilestoneDelays.Any())
                    {
                        memoryMilestoneDelays.AddRange(mem.IssueMilestoneDelays);
                    }
                }

                foreach (var delay in dbIssueMilestoneDelays)
                {
                    var match = (from x in memoryMilestoneDelays where x.Id == delay.Id select x).FirstOrDefault();

                    if (match == null)
                    {
                        //DELETE delay
                        cee.IssueMilestoneDelays.Remove(delay);
                        cee.SaveChanges();
                    }
                }

                foreach (var original in originalMilestones)
                {
                    var milestone = (from x in issue.IssueMilestones where original.Id == x.Id select x).FirstOrDefault();

                    if (milestone == null)
                    {
                        //delete MILESTONE
                        cee.IssueMilestones.Remove(original);
                        cee.SaveChanges();
                    }
                }

                foreach (IssueMilestone milestone in issue.IssueMilestones.OrderBy(x => x.Ordinal))
                {

                    var matchMilestone = (from x in cee.IssueMilestones where x.Id == milestone.Id select x).FirstOrDefault();
                    bool isNewMilestone = false;
                    if (matchMilestone == null)
                    {
                        isNewMilestone = true;
                        matchMilestone = new IssueMilestone { IssueId = issue.Id };
                        cee.IssueMilestones.Add(matchMilestone);
                    }

                    matchMilestone.Ordinal = milestone.Ordinal;
                    matchMilestone.AccumulatedDelay = milestone.AccumulatedDelay;
                    matchMilestone.ActualStart = milestone.ActualStart;
                    matchMilestone.ActualEnd = milestone.ActualEnd;
                    matchMilestone.AssignedToId = milestone.AssignedToId;

                    if (isNewMilestone)
                    {
                        if (milestone.PlannedPreviousMilestone != null)
                        {
                            //get previous milestone based on the Ordinal
                            var previousMilestone = (from x in cee.IssueMilestones
                                                     where
                                                         x.IssueId == milestone.PlannedPreviousMilestone.IssueId &&
                                                         x.Ordinal == milestone.PlannedPreviousMilestone.Ordinal &&
                                                         x.Description == milestone.PlannedPreviousMilestone.Description &&
                                                         x.AssignedToId == milestone.PlannedPreviousMilestone.AssignedToId
                                                     select x).FirstOrDefault();
                            if (previousMilestone != null)
                            {
                                matchMilestone.PlannedPreviousMilestoneId = previousMilestone.Id;
                            }
                        }

                        if (milestone.ActualPreviousMilestone != null)
                        {
                            //get previous milestone based on the Ordinal
                            var previousMilestone = (from x in cee.IssueMilestones
                                                     where
                                                         x.IssueId == milestone.ActualPreviousMilestone.IssueId &&
                                                         x.Ordinal == milestone.ActualPreviousMilestone.Ordinal &&
                                                         x.Description == milestone.ActualPreviousMilestone.Description &&
                                                         x.AssignedToId == milestone.ActualPreviousMilestone.AssignedToId
                                                     select x).FirstOrDefault();
                            if (previousMilestone != null)
                            {
                                matchMilestone.ActualPreviousMilestoneId = previousMilestone.Id;
                            }
                        }
                    }
                    else
                    {
                        matchMilestone.PlannedPreviousMilestoneId = milestone.PlannedPreviousMilestoneId;
                        matchMilestone.ActualPreviousMilestoneId = milestone.ActualPreviousMilestoneId;
                    }

                    matchMilestone.Description = milestone.Description;
                    matchMilestone.PlannedStart = milestone.PlannedStart;
                    matchMilestone.PlannedEnd = milestone.PlannedEnd;
                    matchMilestone.MilestoneTypeId = milestone.MilestoneTypeId;
                    matchMilestone.PercentageComplete = milestone.PercentageComplete;
                    cee.SaveChanges();

                    //save / update delays
                    foreach (IssueMilestoneDelay delay in milestone.IssueMilestoneDelays)
                    {
                        var matchDelay = (from x in cee.IssueMilestoneDelays where x.Id == delay.Id select x).FirstOrDefault();

                        if (matchDelay == null)
                        {
                            matchDelay = new IssueMilestoneDelay();
                            cee.IssueMilestoneDelays.Add(matchDelay);
                        }

                        matchDelay.IssueMilestoneId = matchMilestone.Id;
                        matchDelay.Delay = delay.Delay;
                        matchDelay.IssueMilestoneDelayTypeId = delay.IssueMilestoneDelayTypeId;
                        matchDelay.DelayCause = delay.DelayCause;
                        matchDelay.CorrectiveAction = delay.CorrectiveAction;
                    } //end for loop on milestones
                    cee.SaveChanges();
                }
            }
            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);
                    }
                }
            }
        }