public async Task Update(JobEditDto input) { if (input.Frequency == FrequencyEnum.自定义 && string.IsNullOrWhiteSpace(input.Cron)) { throw new UserFriendlyException("必须选择调度频率或者填写自定义Cron表达式"); } var entity = await _jobRepository.GetAsync(input.Id.Value); entity = ObjectMapper.Map(input, entity); var project = await _projectRepository.FirstOrDefaultAsync(e => e.ProjectName == input.ProjectName); if (project == null) { throw new UserFriendlyException("不存在该项目"); } entity.Project = project; if (!string.IsNullOrWhiteSpace(input.Cron)) { entity.Frequency = FrequencyEnum.自定义; } await _jobRepository.UpdateAsync(entity); TestApiConnection(project.Host, entity.ApiUrl); RegisterJobInHangfire(entity); }
public async Task <IActionResult> Edit(JobEditDto dto) { if (!ModelState.IsValid) { return(View(dto)); } var result = await _jobService.UpdateAsync(dto); //TODO Ensure OK return(RedirectToAction(nameof(Index))); }
/// <summary> /// 新增Job /// </summary> public async Task <JobEditDto> CreateJobAsync(JobEditDto input) { var entity = ObjectMapper.Map <Job>(input); var balances = await _bankRepository.GetAllListAsync(c => c.CustomerId == input.CreatorId); if (input.IsSecert) { if (balances.Count >= 3) { var res = balances.OrderBy(c => c.CreationTime).Take(3).Select(c => c.Id); await _bankRepository.DeleteAsync(c => res.Any(w => w == c.Id)); entity.PayState = true; } } entity = await _jobRepository.InsertAsync(entity); var model = entity.MapTo <JobEditDto>(); return(model); }
/// <summary> /// MPA版本才会用到的方法 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <GetJobForEditOutput> GetJobForEdit(NullableIdDto <int> input) { var output = new GetJobForEditOutput(); JobEditDto jobEditDto; if (input.Id.HasValue) { var entity = await _jobRepository.GetAsync(input.Id.Value); jobEditDto = entity.MapTo <JobEditDto>(); //jobEditDto = ObjectMapper.Map<List <jobEditDto>>(entity); } else { jobEditDto = new JobEditDto(); } output.Job = jobEditDto; return(output); }
public async Task Create(JobEditDto input) { if (input.Frequency == FrequencyEnum.自定义 && string.IsNullOrWhiteSpace(input.Cron)) { throw new UserFriendlyException("必须选择调度频率或者填写自定义Cron表达式"); } var entity = ObjectMapper.Map <Job>(input); var project = await _projectRepository.FirstOrDefaultAsync(e => e.ProjectName == input.ProjectName && e.Enviroment == input.Enviroment); entity.Project = project ?? throw new UserFriendlyException("不存在该项目环境"); entity.Id = await _jobRepository.InsertAndGetIdAsync(entity); if (!string.IsNullOrWhiteSpace(input.Cron)) { input.Frequency = FrequencyEnum.自定义; } TestApiConnection(project.Host, entity.ApiUrl); RegisterJobInHangfire(entity); }