private void CreateSchedule(RecruitmentSystemContext dbContext, IOptions <EmailSettings> emailSettings)
        {
            var startDate = DateHelper.GetDayOfWeekDate(DateTime.Today.AddDays(7), DayOfWeek.Monday);
            var endDate   = startDate.AddDays(6);
            var jobs      = dbContext.Jobs
                            .Where(j => j.IsActive && j.StartDate.Date <= endDate.Date && j.EndDate.Date >= startDate.Date)
                            .Include(j => j.JobSkills).Include(j => j.LabourerJobs).Include(j => j.Company)
                            .OrderByDescending(j => j.Company.Rating).ToList();

            if (jobs != null && jobs.Count > 0)
            {
                foreach (var job in jobs)
                {
                    AutoSchedule.MatchLabourersByDates(job, dbContext, startDate, endDate, emailSettings);
                }
            }
        }
        private static void CreateJob(string title, string description, string address, string city, Weekdays weekdays, RecruitmentSystemContext context, Company company)
        {
            Random r         = new Random();
            var    startDate = new DateTime(2019, r.Next(1, 12), 1);
            var    job       = new Job
            {
                Title       = title,
                Description = description,
                Address     = address,
                City        = city,
                Province    = "BC",
                Country     = "Canada",
                Company     = company,
                CreateDate  = startDate,
                UpdateDate  = startDate,
                StartDate   = startDate,
                EndDate     = new DateTime(2020, r.Next(6, 12), 1),
                Weekdays    = weekdays,
                IsActive    = true
            };

            context.Jobs.Add(job);

            //add skills
            var skills = context.Skills.ToList();
            var from   = r.Next(0, 14);
            var to     = r.Next(from, 14);
            var count  = 1;

            for (var i = from; i <= to; i++)
            {
                if (count == 6)
                {
                    break;
                }
                var jobSkill = new JobSkill
                {
                    Job   = job,
                    Skill = skills[i],
                    NumberOfLabourersNeeded = r.Next(1, 10)
                };
                context.JobSkills.Add(jobSkill);
                count++;
            }
            context.SaveChanges();

            //create past schedules
            AutoSchedule.MatchLabourersByDates(job, context, job.StartDate, DateTime.Now, null);

            //rate
            var labourerJobs = context.LabourerJobs.Where(lj => lj.JobId == job.Id).Include(l => l.Labourer).ToList();

            foreach (var labourerJob in labourerJobs)
            {
                labourerJob.QualityRating = r.Next(3, 5);
                labourerJob.SafetyRating  = r.Next(3, 5);
                labourerJob.JobRating     = r.Next(3, 5);
                context.Update(labourerJob);
            }
            context.SaveChanges();

            //calc labourer avg ratings
            foreach (var labourer in context.Labourers.ToList())
            {
                var avgQualityRating = context.LabourerJobs.Where(lj => lj.LabourerId == labourer.Id && lj.QualityRating.HasValue).Select(lj => lj.QualityRating.Value).ToList().DefaultIfEmpty().Average();
                var avgSafetyRating  = context.LabourerJobs.Where(lj => lj.LabourerId == labourer.Id && lj.SafetyRating.HasValue).Select(lj => lj.SafetyRating.Value).ToList().DefaultIfEmpty().Average();
                labourer.QualityRating = (float)avgQualityRating;
                labourer.SafetyRating  = (float)avgSafetyRating;
                context.Update(labourer);
            }

            //calc job avg rating
            var avgRating = context.LabourerJobs.Where(lj => lj.JobId == job.Id && lj.QualityRating.HasValue).Select(lj => lj.JobRating.Value).ToList().DefaultIfEmpty().Average();

            job.Rating = (float)avgRating;
            context.Update(job);
            context.SaveChanges();

            //TODO: incident reports

            new AutoSchedule(null).MatchLabourersForTheNearestTwoWeeks(job, context, null);
        }