private SourcingViewModel GetExistingConfiguration(int id)
        {
            SourcingConfigurationMessage existingConfiguration = this.configurer.GetConfiguration(id);
            SourcingViewModel            model = this.MapMessageToViewModel(existingConfiguration);

            return(model);
        }
        public ActionResult ConfirmDeleteConfiguration(int configurationId)
        {
            SourcingConfigurationMessage existingConfiguration = this.configurer.GetConfiguration(configurationId);
            SourcingViewModel            model = this.MapMessageToViewModel(existingConfiguration);

            // ReSharper disable once Mvc.ViewNotResolved
            return(this.View(model));
        }
        private SourcingViewModel MapMessageToViewModel(SourcingConfigurationMessage message)
        {
            var viewModel = new SourcingViewModel();

            viewModel.Id                      = message.SourcingConfigurationId;
            viewModel.Title                   = message.Title;
            viewModel.Description             = message.Description;
            viewModel.IsActive                = message.IsActive;
            viewModel.StaticCriteriaOperator  = message.StaticCriteriaOperator;
            viewModel.DynamicCriteriaOperator = message.DynamicCriteriaOperator;
            viewModel.SourceWorkflow          = new KeyValuePair <int, string>(message.SourceWorkflowId, this.configurationSetupService.GetWorkflowDisplaytext(message.SourceWorkflowId));
            viewModel.SourceRequisition       = new KeyValuePair <int, string>(message.SourceRequisitionId, this.configurationSetupService.GetRequisitionTitle(message.SourceRequisitionId));
            viewModel.SourceFolder            = new KeyValuePair <int, string>(message.SourceFolderId, this.configurationSetupService.GetFolderDisplaytext(message.SourceFolderId));
            viewModel.DestinationWorkflow     = new KeyValuePair <int, string>(message.DestinationWorkflowId, this.configurationSetupService.GetWorkflowDisplaytext(message.DestinationWorkflowId));
            viewModel.DestinationFolder       = new KeyValuePair <int, string>(message.DestinationFolderId, this.configurationSetupService.GetFolderDisplaytext(message.DestinationFolderId));
            viewModel.FieldDefId              = new KeyValuePair <int, string>(message.FieldDefId, this.configurationSetupService.GetRequisitionFieldDisplaytext(message.FieldDefId));

            viewModel.StaticCriteria = new List <StaticCriterionView>();
            foreach (var staticCriterion in message.StaticCriteria)
            {
                var criterion = this.objectMapper.Map <StaticCriterionView>(staticCriterion);
                criterion.Displaytext = this.configurationSetupService.GetCandidateFieldDisplaytext(criterion.SolrFieldName);

                if (criterion.DomainListId > 0)
                {
                    criterion.DomainListValueDisplaytext = this.configurationSetupService.GetDomainListValueDisplaytext(
                        criterion.DomainListId,
                        Convert.ToInt32(criterion.Value));
                }

                if (criterion.StartDate == DateTime.MinValue)
                {
                    criterion.StartDate = null;
                }

                if (criterion.EndDate == DateTime.MinValue)
                {
                    criterion.EndDate = null;
                }

                viewModel.StaticCriteria.Add(criterion);
            }

            viewModel.DynamicCriteria = new List <DynamicCriterionView>();
            foreach (var dynamicCriterion in message.DynamicCriteria)
            {
                var criterion = this.objectMapper.Map <DynamicCriterionView>(dynamicCriterion);
                criterion.CandidateFieldDisplaytext   = this.configurationSetupService.GetCandidateFieldDisplaytext(dynamicCriterion.SolrFieldName);
                criterion.RequisitionFieldDisplaytext = this.configurationSetupService.GetRequisitionFieldDisplaytext(dynamicCriterion.RequisitionFieldId);
                viewModel.DynamicCriteria.Add(criterion);
            }

            return(viewModel);
        }
        public JsonResult AddConfiguration(string model)
        {
            SourcingViewModel            deserializedModel = JsonConvert.DeserializeObject <SourcingViewModel>(model);
            SourcingConfigurationMessage message           = this.objectMapper.Map <SourcingConfigurationMessage>(deserializedModel);

            message.ConfigurationIdValue = this.configurationSetupService.GetConfigurationIdValue(message);
            message.ClientId             = this.contextManager.GetContext().ClientId;

            this.configurer.AddConfiguration(message);
            return(this.Json(new SuccessResponse()));
        }
        public JsonResult UpdateConfiguration(int id, string model)
        {
            SourcingViewModel            deserializedModel = (SourcingViewModel)JsonConvert.DeserializeObject(model, typeof(SourcingViewModel));
            SourcingConfigurationMessage message           = this.objectMapper.Map <SourcingConfigurationMessage>(deserializedModel);

            message.SourcingConfigurationId = id;
            message.ConfigurationIdValue    = this.configurationSetupService.GetConfigurationIdValue(message);
            message.ClientId = this.contextManager.GetContext().ClientId;

            this.configurer.ModifyConfiguration(message);
            return(this.Json(new SuccessResponse()));
        }