Exemplo n.º 1
0
        private static List <JobCriteraColumn> BuildJobCriteriaColumns(AdmIntegrationJob job)
        {
            var cols = new List <JobCriteraColumn>();

            foreach (AdmIntegrationJobCriteriaColumn col in job.AdmIntegrationJobCriteriaColumns)
            {
                var mVals = new List <JobCriteriaColumnValue>();
                foreach (AdmIntegrationJobCriteriaColumnValue colVal in col.AdmIntegrationJobCriteriaColumnValues)
                {
                    mVals.Add(new JobCriteriaColumnValue()
                    {
                        Id = colVal.CriteriaID, Value = colVal.CriteriaValue
                    });
                }
                cols.Add(new JobCriteraColumn()
                {
                    ColumnName           = col.ColumnName,
                    ColumnCriteriaValues = mVals
                });
            }
            return(cols);
        }
Exemplo n.º 2
0
        public async Task <GetIntegrationJobDetailsResponse> GetIntegrationJobDetails(GetIntegrationJobDetailsRequest request)
        {
            GetIntegrationJobDetailsResponse model;
            AdmIntegrationJob job = null;

            switch (request.JobId)
            {
            case 0:     // find first
                var view = await _repository.GetAsync <AppView>(v => v.AppObjectID == "Integration" && v.ViewName == "Index");

                if (view != null)
                {
                    var pref = (await _repository.GetListAsync <AppViewsAdmUsersPreference>(p => p.AdmUserID == request.CurrentAdmUserId &&
                                                                                            p.AppViewID == view.AppViewID))
                               .FirstOrDefault();
                    if (pref?.LastViewedID != null)
                    {
                        request.JobId = pref.LastViewedID.Value;
                    }
                }

                if (request.JobId != 0)
                {
                    job = (await _repository.GetListAsync <AdmIntegrationJob>(j => j.AdmIntegrationJobID == request.JobId && !j.IsDeleted))
                          .FirstOrDefault();
                }

                if (job == null)
                {
                    job = (await _repository.GetListAsync <AdmIntegrationJob>())
                          .OrderBy(o => o.Name)
                          .FirstOrDefault(o => !o.IsDeleted);
                }

                break;

            case -1:     //new one
                break;

            default:
                job = await _repository.FindAsync <AdmIntegrationJob>(request.JobId);
                await SaveUserLastViewed(request.JobId, request.CurrentAdmUserId);

                break;
            }

            if (job == null)
            {
                model = new GetIntegrationJobDetailsResponse()
                {
                    JobName        = "",
                    JobDescription = "",
                    TaskModel      = new AdmScheduledTaskItem(),
                    IsImport       = request.IsImport.HasValue && request.IsImport.Value,
                    MapType        = (int)GetMapType(request.MapTypeName),
                    GradeSchoolChangeThreshhold = 10,
                    CNIPsVendorNumber           = "",
                    CNIPsCDSNumber     = "",
                    CNIPsLicenseNumber = "",
                    CNIPsSponsor       = "",
                    CNIPsID            = ""
                };
            }
            else
            {
                model                    = _autoMapper.Map <GetIntegrationJobDetailsResponse>(job);
                model.JobName            = job.Name;
                model.JobDescription     = job.Description;
                model.IsImport           = job.AdmIntegrationMap.IsImport;
                model.JobCriteriaColumns = BuildJobCriteriaColumns(job);
                // krp 2do  - does this work? without recalling the db to populate the AdmIntegrationMap
                model.MapType = job.AdmIntegrationMap.MapType; // GetImportType(job.AdmIntegrationMapID)
                model         = await UpdateModelWithCniPs(model);

                model.TaskModel = new AdmScheduledTaskItem();

                var sched = await _repository.GetAsync <AdmScheduledTask>(t => t.AdmIntegrationJobID == job.AdmIntegrationJobID);

                if (sched != null)
                {
                    model.TaskModel = _autoMapper.Map <AdmScheduledTaskItem>(sched);
                    if (sched.StartTime.HasValue)
                    {
                        model.TaskModel.StartTime =
                            new DateTime(((TimeSpan)sched.StartTime).Ticks);
                    }
                }
            }

            var integrationMaps =
                await _repository.GetListAsync <AdmIntegrationMap>(q =>
                                                                   q.MapType == model.MapType && q.IsImport == model.IsImport);

            model.Maps = _autoMapper.Map <Collection <IntegrationMapItem> >(integrationMaps);

            if (model.Maps.Count == 0 && model.AdmIntegrationMapID == 0 &&
                (model.MapType == (int)IntegrationMapType.Gordon_Foods_Order_Export) ||
                (model.MapType == (int)IntegrationMapType.CNIPs))
            {
                var map = await GetNewMap(model.MapType);

                model.Maps.Add(_autoMapper.Map <IntegrationMapItem>(map));
            }
            return(model);
        }