Esempio n. 1
0
        public async Task UpdateJobAsync(Job2Dto dto)
        {
            var jobEntity = _dbContext.Job.FirstOrDefault(x => x.Id == dto.Job.JobId);

            _mapper.Map(dto.Job, jobEntity);
            jobEntity.DateModified = DateTime.UtcNow;
            jobEntity.ModifiedBy   = GetCurrentUserEmail();

            JobCreatedIntegrationEvent jobUpdatedEvent = null;

            //TODO: Verify when we change the BillTo from Vendor to Account.. bill to Type is being changed.
            await ResilientTransaction.New(_dbContext).ExecuteAsync(async() =>
            {
                _dbContext.Job.Update(jobEntity);
                await _dbContext.SaveChangesAsync();

                UpdateTransferee(dto);
                UpdatePhone(dto);
                UpdateTransfereeEmail(dto);
                UpdateAddress(dto);

                jobUpdatedEvent        = jobEntity.FromJob <JobCreatedIntegrationEvent>();
                jobUpdatedEvent.UserId = GetCurrentUserEmail();

                await _eventLogService.SaveEventAsync(jobUpdatedEvent);
            });

            // Publish the integration event through the event bus
            _eventBus.Publish(jobUpdatedEvent);
            await _eventLogService.MarkEventAsPublishedAsync(jobUpdatedEvent.Id);

            _logger.LogInformation("Job object updated");
        }
Esempio n. 2
0
        public void SaveJob(JobItem job)
        {
            var result = new JobItem();

            try
            {
                _logger.LogTrace("Saving the Job", job);
                if (!string.IsNullOrEmpty(job.Id))
                {
                    Expression <Func <JobItem, bool> > expr = (x => x.Id == job.Id);
                    if (_jobRepository.Exists(expr))
                    {
                        result = _jobRepository.Update(job);
                    }
                    else
                    {
                        result = _jobRepository.Add(job);
                    }
                }
                else
                {
                    result = _jobRepository.Add(job);
                }

                JobCreatedIntegrationEvent test = new JobCreatedIntegrationEvent("test");
                _eventBus.Publish(test);


                _logger.LogTrace("Item Saved & event publised. event:", test);
            }
            catch (Exception ex)
            {
                _logger.LogError("Unable to save the ", ex);
            }
        }
Esempio n. 3
0
        public async Task <int> AddJobAsync(Job2Dto job2Dto)
        {
            _logger.LogInformation("Incoming Dto {0}", job2Dto);
            string currentUsername = GetCurrentUserEmail();

            var job = _mapper.Map <Job>(job2Dto.Job);

            if (job != null)
            {
                JobCreatedIntegrationEvent jobCreatedEvent = null;

                await ResilientTransaction.New(_dbContext).ExecuteAsync(async() =>
                {
                    job.TransfereeId  = SaveTransferee(job2Dto.Transferee);
                    job.AccountEntity = _dbContext.AccountEntity.FirstOrDefault(a => a.Id == job.AccountEntityId);

                    var dateTimeAdded = DateTime.UtcNow;
                    job.DateCreated   = dateTimeAdded;
                    job.DateModified  = dateTimeAdded;
                    job.CreatedBy     = GetCurrentUserEmail();
                    job.ModifiedBy    = GetCurrentUserEmail();

                    if (job2Dto.Job.IsSurveyAndBid)
                    {
                        job.JobStatus = JobStatusIdentifier.SURVEY_BID;
                    }

                    _dbContext.Job.Attach(job);
                    _dbContext.Entry(job).State = EntityState.Added;

                    await _dbContext.SaveChangesAsync();

                    //update the fks in the job table
                    var kvp                  = await SaveAddresses(job2Dto.JobInfo);
                    job.OriginAddressId      = kvp.FirstOrDefault(s => s.Key == AddressType.ORIGIN).Value;
                    job.DestinationAddressId = kvp.FirstOrDefault(s => s.Key == AddressType.DESTINATION).Value;

                    await _dbContext.SaveChangesAsync();

                    jobCreatedEvent            = job.FromJob <JobCreatedIntegrationEvent>();
                    jobCreatedEvent.Transferee = job2Dto.ToTransfereeIntegrationEvent <TransfereeCreatedIntegrationEvent>();
                    jobCreatedEvent.UserId     = GetJobsMoveConsultantEmail(job.Id);

                    await _eventLogService.SaveEventAsync(jobCreatedEvent);
                });

                // Publish the integration event through the event bus
                _eventBus.Publish(jobCreatedEvent);
                await _eventLogService.MarkEventAsPublishedAsync(jobCreatedEvent.Id);

                _logger.LogInformation("Job added {0}", job.Id);
            }

            return(job.Id);
        }