public int Create(CreateJobDto createJobDto) { // //if the same task name exists for this tenant //not allowed // if (_context.Jobs.Where(x => x.Name == createJobDto.Name && x.TenantId == createJobDto.TenantId).Any()) { throw new OccumetricException("Job name already exists"); } var job = _mapper.Map <Job>(createJobDto); var taskList = new List <JobTask>(); foreach (int id in createJobDto.MasterTaskIds) { MasterTask mt = _context.MasterTasks .Find(id); // //snooks and niosh are already calculated //and stored in mastertask //no need to recalculate here // JobTask jobTask = _mapper.Map <JobTask>(mt); jobTask.Id = 0; taskList.Add(jobTask); } job.JobTasks = taskList; _context.Jobs.Add(job); _context.SaveChanges(); return(job.Id); }
public async Task <CoreJobDto> Create(CreateJobDto job) { using (var db = _contextFactory.CreateDb()) { var efJob = _mapper.Map <Job>(job); db.Jobs.Add(efJob); await db.SaveChangesAsync(); return((await GetForJobId(efJob.JobId)).CoreInfo); } }
public async Task <IActionResult> Create([FromBody] CreateJobDto dto) { await Task.Run(() => { int result = _jobService.Create(dto); }); return(Ok(new StringResult { Result = "Created" })); }
public async Task <ActionResult> Create(CreateJobViewModel jobToCreate) { var clients = await clientRepository.GetAllClients(); var sites = await siteRepository.GetAll(); var mappedJob = jobToCreate.Job; var createDto = new CreateJobDto() { ClientId = jobToCreate.SelectedClientId, JobCode = jobToCreate.Job.JobCode, JobName = jobToCreate.Job.JobName, JobStatusId = (JobStatus)jobToCreate.SelectedJobStatusId, ProjectManagerEmployeeId = jobToCreate.SelectedProjectManagerEmployeeId, SiteId = jobToCreate.SelectedSiteId, TargetHours = jobToCreate.Job.TargetHours, }; await _jobsRepository.Create(createDto); NotificationsController.AddNotification(User.SafeUserName(), $"Sucessfully created {jobToCreate.Job.FullJobCodeWithName}"); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CreateJobAsync(CreateJobDto createJobDto) { var id = await _mediator.Send(createJobDto); return(Ok(id)); }
public async Task CreateJob(CreateJobDto input) { var job = _mapper.Map <JobAdvert>(input); await _jobRepository.InsertAsync(job); }