コード例 #1
0
        private void cmsWebServiceClient_GetIssueTabControlsCompleted(object sender, GetIssueTabControlsCompletedEventArgs e)
        {
            var availableIssueTabControls = e.Result;
            var tabControlStatuses = new List<StatusTypeEnabledControl>();

            foreach (var issueTabControl in availableIssueTabControls)
            {
                //If tabControl exist that means its enabled
                var existingTabControl = mIssueStatus.StatusTypeEnabledControls.FirstOrDefault(x => x.IssueTabControlId == issueTabControl.Id
                                                                                                    && x.IssueStatusId == mIssueStatus.Id && x.IssueTypeId == mIssueType.Id);

                if (existingTabControl != null)
                {
                    existingTabControl.IssueTabControl = issueTabControl;
                    existingTabControl.IsEnabled = true;
                }
                else
                {
                    StatusTypeEnabledControl issueTabControlStatus = new StatusTypeEnabledControl();
                    issueTabControlStatus.IssueTabControl = issueTabControl;
                    issueTabControlStatus.IssueTabControlId = issueTabControl.Id;
                    issueTabControlStatus.IssueStatusId = mIssueStatus.Id;
                    issueTabControlStatus.IssueTypeId = mIssueType.Id;
                    issueTabControlStatus.IsEnabled = false;

                    tabControlStatuses.Add(issueTabControlStatus);
                }
            }

            mIssueStatus.StatusTypeEnabledControls.AddRange(tabControlStatuses);
            RaisePropertyChanged("StatusTypeEnabledControls");
        }
コード例 #2
0
        public IssueStatus SaveIssueStatus(IssueStatus issueStatus)
        {
            IssueStatus issueStatusToUpdate = null;
            try
            {
                using (var cee = new CmsEntities())
                {
                    //Check if the object exist
                    issueStatusToUpdate = (from x in cee.IssueStatuses where x.Id == issueStatus.Id select x).FirstOrDefault();

                    int issueStatusId = issueStatus.Id;

                    if (issueStatusToUpdate == null)
                    {
                        //Create new Issue Status
                        issueStatusToUpdate = new IssueStatus
                        {
                            Name = issueStatus.Name,
                            Ordinal = issueStatus.Ordinal,
                            Code = issueStatus.Name.Replace(" ", ""),
                            IsActive = issueStatus.IsActive,
                            DisableWorkflow = issueStatus.DisableWorkflow
                        };

                        cee.IssueStatuses.Add(issueStatusToUpdate);
                        cee.SaveChanges();
                        issueStatusId = issueStatusToUpdate.Id;
                    }
                    else
                    {
                        //Update existing Status
                        issueStatusToUpdate.Name = issueStatus.Name;
                        issueStatusToUpdate.Ordinal = issueStatus.Ordinal;
                        issueStatusToUpdate.IsActive = issueStatus.IsActive;
                        issueStatusToUpdate.DisableWorkflow = issueStatus.DisableWorkflow;

                        //Delete Rules
                        cee.DeleteWhere<StatusTypeRule>(cee, x => x.StatusId == issueStatus.Id);

                        //Delete Issue Control Statuses
                        cee.DeleteWhere<StatusTypeEnabledControl>(cee, x => x.IssueStatusId == issueStatus.Id);

                        //Delete Issue Available Statuses
                        cee.DeleteWhere<StatusTypeAvailableStatus>(cee, x => x.StatusId == issueStatus.Id);
                    }

                    //Update Rules
                    foreach (StatusTypeRule issueStatusRule in issueStatus.StatusTypeRules)
                    {
                        StatusTypeRule newStatusTypeRule = new StatusTypeRule
                        {
                            RuleName = issueStatusRule.RuleName,
                            StatusId = issueStatusId,
                            IssueTypeId = issueStatusRule.IssueTypeId
                        };
                        issueStatusToUpdate.StatusTypeRules.Add(newStatusTypeRule);
                    }

                    //Update Issue Control Statuses
                    foreach (StatusTypeEnabledControl issueStatuesControl in issueStatus.StatusTypeEnabledControls)
                    {
                        StatusTypeEnabledControl newStatusTypeEnabledControl = new StatusTypeEnabledControl
                        {
                            IssueStatusId = issueStatusId,
                            IssueTypeId = issueStatuesControl.IssueTypeId,
                            IssueTabControlId = issueStatuesControl.IssueTabControlId
                        };
                        issueStatusToUpdate.StatusTypeEnabledControls.Add(newStatusTypeEnabledControl);
                    }

                    //Update Issue Available Statuses
                    foreach (StatusTypeAvailableStatus issueAvailableStatus in issueStatus.StatusTypeAvailableStatuses)
                    {
                        StatusTypeAvailableStatus newStatusTypeAvailableStatus = new StatusTypeAvailableStatus
                        {
                            StatusId = issueStatusId,
                            IssueTypeId = issueAvailableStatus.IssueTypeId,
                            AvailableStatusId = issueAvailableStatus.AvailableStatusId,

                            IsEnabled = issueAvailableStatus.IsEnabled,
                            IsVisible = issueAvailableStatus.IsVisible
                        };
                        issueStatusToUpdate.StatusTypeAvailableStatuses.Add(newStatusTypeAvailableStatus);
                    }
                    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);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, "Error in SaveIssueStatus()");
            }
            return issueStatusToUpdate;
        }