Exemplo n.º 1
0
        public async Task <PostJobDetailsResponse> SaveJobDetails(PostJobDetailsRequest request)
        {
            DateTime today = _repository.GetSchoolNow(request.admSiteId);

            if (!string.IsNullOrEmpty(request.FileLocation))
            {
                request.FileLocation = request.FileLocation.Trim();
            }
            if (!string.IsNullOrEmpty(request.FileFtpUserName))
            {
                request.FileFtpUserName = request.FileFtpUserName.Trim();
            }
            if (!string.IsNullOrEmpty(request.FileFtpPassword))
            {
                request.FileFtpPassword = request.FileFtpPassword.Trim();
            }

            if (!request.IsImport &&
                ((request.MapType == IntegrationMapType.Gordon_Foods_Order_Export) ||
                 (request.MapType == IntegrationMapType.CNIPs)) &&
                request.AdmIntegrationMapID == 0)
            {
                var map = await GetNewMap((int)request.MapType);

                request.AdmIntegrationMapID = map.AdmIntegrationMapID;
            }

            var dbJob = request.AdmIntegrationJobID == 0 ? new AdmIntegrationJob() :
                        await _repository.FindAsync <AdmIntegrationJob>(request.AdmIntegrationJobID);

            dbJob.AdmIntegrationJobID = request.AdmIntegrationJobID;
            dbJob.AdmIntegrationMapID = request.AdmIntegrationMapID;
            dbJob.Name        = request.JobName;
            dbJob.Description = request.JobDescription;
            dbJob.IsInactivateObjectsNotInSource = request.IsInactivateObjectsNotInSource;
            dbJob.IsThreshholdNewRecords         = request.IsThreshholdNewRecords;
            dbJob.ThreshholdNewRecordsPercent    = request.ThreshholdNewRecordsPercent;
            dbJob.IsThreshholdErrors             = request.IsThreshholdErrors;
            dbJob.ThreshholdErrorsPercent        = request.ThreshholdErrorsPercent;
            dbJob.IsUpdateOnly    = request.IsUpdateOnly;
            dbJob.IsDCImport      = request.IsDCImport;
            dbJob.IsAppImport     = request.IsAppImport;
            dbJob.IsAutomated     = request.IsAutomated;
            dbJob.FileSourceType  = request.FileSourceType;
            dbJob.FileLocation    = request.FileLocation;
            dbJob.FileFtpUserName = request.FileFtpUserName;
            dbJob.FileFtpPassword = request.FileFtpPassword;
            dbJob.IsOverrideGradeSchoolChangeThreshhold = request.IsOverrideGradeSchoolChangeThreshhold; //PMM 5/3/16

            // The sledgehammer method:
            // we could traverse all the Criteria columns and values, updating existing ones
            // adding new ones and deleting ones no longer used and we'd also have to traverse
            // all the column values within each column, adding new values and removing values.
            // but that's a lot of complicated code. We don't save exports that often so
            // simply deleting what's already in the DB and re-adding everything is
            // soon much simpler.  the only cost is the delete/insert actions on a very small table
            // ....and we're done.  so...........

            //delete all criteria columns and values.

            dbJob.AdmIntegrationJobCriteriaColumns.ToList().ForEach(e =>
            {
                e.AdmIntegrationJobCriteriaColumnValues.ToList().ForEach(e2 => _repository.MarkForDeletion(e2));
                _repository.MarkForDeletion(e);
            });

            //add Criteria Columns and Values from the request
            if (request.JobCriteriaColumns != null && request.JobCriteriaColumns.Any())
            {
                foreach (JobCriteraColumn col in request.JobCriteriaColumns)
                {
                    //create the column, add the values, then add column to the DBJob

                    bool isIdComparison = col.ColumnName == "isActive";  //hard coding this for most jobs so it compares the value.

                    var dbCol = new AdmIntegrationJobCriteriaColumn()
                    {
                        ColumnName     = col.ColumnName,
                        IsIDComparison = isIdComparison
                    };

                    foreach (JobCriteriaColumnValue val in col.ColumnCriteriaValues)
                    {
                        dbCol.AdmIntegrationJobCriteriaColumnValues.Add(
                            new AdmIntegrationJobCriteriaColumnValue()
                        {
                            CriteriaID    = val.Id,
                            CriteriaValue = val.Value ?? ""
                        }
                            );
                    }
                    dbJob.AdmIntegrationJobCriteriaColumns.Add(dbCol);
                }
            }

            if (dbJob.IsAutomated)
            {
                AdmScheduledTask task;
                if (dbJob.AdmScheduledTasks.Count == 0)
                {
                    task = new AdmScheduledTask {
                        CreatedDate = today
                    };
                    dbJob.AdmScheduledTasks.Add(task);
                }
                else
                {
                    task = dbJob.AdmScheduledTasks.First();
                }
                task.AdmScheduledTaskName = dbJob.Name;
                task.AdmScheduledTaskType = ScheduledTaskType.IntegrationJob;
                if (_repository.CurrentAdmUserId != null)
                {
                    task.AdmUserID = (int)_repository.CurrentAdmUserId;
                }
                task.Frequency    = request.TaskModel.Frequency;
                task.StartDate    = request.TaskModel.StartDate;
                task.RunOnStartup = request.TaskModel.RunOnStartup;

                task.IsDeleted = false;
                if (request.TaskModel.StartTime != null)
                {
                    task.StartTime = request.TaskModel.StartTime;
                }
            }
            else
            {
                if (dbJob.AdmScheduledTasks.Count != 0)
                {
                    dbJob.AdmScheduledTasks.First().IsDeleted = true;
                }
            }

            var userInfo = await _repository.FindAsync <AdmUser>(request.AdmUserID);

            var createdBy = userInfo.FirstName + " " + userInfo.LastName;

            if (dbJob.AdmIntegrationJobID == 0)
            {
                dbJob.CreatedBy       = createdBy;
                dbJob.CreatedDateTime = DateTime.Now;
            }
            else
            {
                dbJob.LastModifiedBy       = createdBy;
                dbJob.LastModifiedDateTime = DateTime.Now;
            }
            dbJob = dbJob.AdmIntegrationJobID == 0 ?
                    await _repository.CreateAsync(dbJob) :
                    await _repository.UpdateAsync(dbJob);

            await SaveUserLastViewed(dbJob.AdmIntegrationJobID);

            return(_autoMapper.Map <PostJobDetailsResponse>(dbJob));
        }
Exemplo n.º 2
0
 public async Task <ActionResult <PostJobDetailsResponse> > SaveJobDetails(PostJobDetailsRequest request)
 {
     return(await _integrationJobsLogic.SaveJobDetails(request));
 }