public async Task <IActionResult> Create_schedule(string time, string timem, List <string> list_Idtestcase, int id_url) { Test_schedule test_Schedule = new Test_schedule(); test_Schedule.CreatedDate = DateTime.Now; string scheduleId = Guid.NewGuid().ToString("N"); test_Schedule.id_schedule = scheduleId; var id_user = _userManager.GetUserId(User); test_Schedule.id_user = id_user; test_Schedule.job_repeat_time = time + ":" + timem; test_Schedule.status = "running"; _context.Test_schedule.Add(test_Schedule); await _context.SaveChangesAsync(); foreach (var id in list_Idtestcase) { Testcase_scheduled testcase_Scheduled = new Testcase_scheduled(); testcase_Scheduled.id_schedule = scheduleId; testcase_Scheduled.id_url = id_url; testcase_Scheduled.id_testcase = id; _context.Testcase_scheduled.Add(testcase_Scheduled); } _context.SaveChanges(); IJobDetail job = JobBuilder.Create <RunTestcaseJob>() .UsingJobData("scheduleid", scheduleId) .WithIdentity(scheduleId, id_user) .StoreDurably() .RequestRecovery() .Build(); await _scheduler.AddJob(job, true); ITrigger trigger = TriggerBuilder.Create() .ForJob(job) //.UsingJobData("triggerparam", "Simple trigger 1 Parameter") .WithIdentity(scheduleId + "trigger", id_user) .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(int.Parse(time), int.Parse(timem))) // .StartNow() // .WithSimpleSchedule(z => z.WithIntervalInSeconds(600).RepeatForever()) .Build(); await _scheduler.ScheduleJob(trigger); StatusMessage = "Create schedule successfully"; return(RedirectToAction("Index")); }
public async Task <IActionResult> AddMoreTestCases(int id_url, string scheduleId, List <string> list_Idtestcase) { var user = await _userManager.GetUserAsync(User); foreach (var id in list_Idtestcase) { Testcase_scheduled testcase_Scheduled = new Testcase_scheduled(); testcase_Scheduled.id_schedule = scheduleId; testcase_Scheduled.id_url = id_url; testcase_Scheduled.id_testcase = id; _context.Testcase_scheduled.Add(testcase_Scheduled); } _context.SaveChanges(); ViewData["id_url"] = id_url; ViewData["scheduleId"] = scheduleId; return(RedirectToAction(nameof(DetailSchedule), new { scheduleId = scheduleId })); }