public async Task <bool> UpdateJob(Jobs.Model.Job job)
        {
            if (job == null)
            {
                throw new ArgumentNullException();
            }

            using (IJobQueueDataContext context = _contextFactory())
            {
                Job entity = await context.Job.SingleOrDefaultAsync(x => x.JobId == job.JobId);

                if (entity == null)
                {
                    throw new ArgumentException($"Job id {job.JobId} does not exist");
                }

                bool statusChanged = entity.Status != (short)job.Status;

                JobConverter.Convert(job, entity);
                entity.DateTimeUpdatedUtc = _dateTimeProvider.GetNowUtc();
                context.Entry(entity).Property("RowVersion").OriginalValue = job.RowVersion == null ? null : Convert.FromBase64String(job.RowVersion);
                context.Entry(entity).State = EntityState.Modified;

                if (job.Status == JobStatusType.Ready)
                {
                    context.JobSubmission.Add(new JobSubmission()
                    {
                        DateTimeUtc = _dateTimeProvider.GetNowUtc(),
                        JobId       = job.JobId
                    });
                }

                try
                {
                    await context.SaveChangesAsync();

                    if (statusChanged)
                    {
                        await SendEmailNotification(job);
                    }

                    return(true);
                }
                catch (DbUpdateConcurrencyException exception)
                {
                    throw new Exception(
                              "Save failed. Job details have been changed. Reload the job object and try save again");
                }
            }
        }
        public async Task <bool> UpdateCrossLoadingStatus(long jobId, JobStatusType status)
        {
            if (jobId == 0)
            {
                throw new ArgumentException("Job id can not be 0");
            }

            using (IJobQueueDataContext context = _contextFactory())
            {
                var entity = await context.Job.SingleOrDefaultAsync(x => x.JobId == jobId);

                if (entity == null)
                {
                    throw new ArgumentException($"Job id {jobId} does not exist");
                }

                entity.CrossLoadingStatus   = (short)status;
                entity.DateTimeUpdatedUtc   = _dateTimeProvider.GetNowUtc();
                context.Entry(entity).State = EntityState.Modified;

                await context.SaveChangesAsync();

                return(true);
            }
        }
        public async Task <bool> UpdateJobStatus(long jobId, JobStatusType status)
        {
            if (jobId == 0)
            {
                throw new ArgumentException("Job id can not be 0");
            }

            using (IJobQueueDataContext context = _contextFactory())
            {
                var entity = await context.Job.SingleOrDefaultAsync(x => x.JobId == jobId);

                if (entity == null)
                {
                    throw new ArgumentException($"Job id {jobId} does not exist");
                }

                var statusChanged = entity.Status != (short)status;

                entity.Status               = (short)status;
                entity.DateTimeUpdatedUtc   = _dateTimeProvider.GetNowUtc();
                context.Entry(entity).State = EntityState.Modified;

                if (status == JobStatusType.Ready)
                {
                    context.JobSubmission.Add(new JobSubmission()
                    {
                        DateTimeUtc = _dateTimeProvider.GetNowUtc(),
                        JobId       = jobId
                    });
                }

                await context.SaveChangesAsync();

                if (statusChanged)
                {
                    await SendEmailNotification(jobId);
                }

                return(true);
            }
        }