public async STT.Task <IEnumerable <SAVM.Result> > CreateAndExecuteAsync(SAVM.TaskForm taskForm, CancellationToken ct) { // create the TaskEntity var task = await CreateAsync(taskForm, ct); // execute the TaskEntity. Authorization is null, because there can't be any subtasks on a CreateAndExecute. var resultList = await ExecuteAsync(task.Id, ct); return(resultList); }
public async STT.Task <SAVM.Task> CreateAsync(SAVM.TaskForm taskForm, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var vmListCount = taskForm.VmList != null ? taskForm.VmList.Count : 0; if (vmListCount > 0) { if (taskForm.VmMask != "") { throw new InvalidOperationException("A Task cannot have BOTH a VmMask and a VmList!"); } // convert the list of vm guids into a comma separated string and save it in VmMask var vmIdString = ""; foreach (var vmId in taskForm.VmList) { vmIdString = vmIdString + vmId + ","; } taskForm.VmMask = vmIdString.Remove(vmIdString.Count() - 1); } if (taskForm.ActionParameters.Keys.Any(key => key == "Moid")) { taskForm.ActionParameters["Moid"] = "{moid}"; } if (taskForm.ActionParameters.Keys.Any(key => key == "VmName")) { taskForm.ActionParameters["VmName"] = "{VmName}"; } var taskEntity = _mapper.Map <TaskEntity>(taskForm); taskEntity.DateCreated = DateTime.UtcNow; taskEntity.CreatedBy = _user.GetId(); taskEntity.UserId = _user.GetId(); taskEntity.Iterations = taskForm.Iterations > 0 ? taskForm.Iterations : 1; taskEntity.CurrentIteration = 0; _context.Tasks.Add(taskEntity); await _context.SaveChangesAsync(ct); var task = await GetAsync(taskEntity.Id, ct); return(task); }
public async STT.Task <SAVM.Task> UpdateAsync(Guid id, SAVM.TaskForm taskForm, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var taskToUpdate = await _context.Tasks.SingleOrDefaultAsync(v => v.Id == id, ct); if (taskToUpdate == null) { throw new EntityNotFoundException <SAVM.Task>(); } var vmListCount = taskForm.VmList != null ? taskForm.VmList.Count : 0; if (vmListCount > 0) { if (taskForm.VmMask != "") { throw new InvalidOperationException("A Task cannot have BOTH a VmMask and a VmList!"); } // convert the list of vm guids into a comma separated string and save it in VmMask var vmIdString = ""; foreach (var vmId in taskForm.VmList) { vmIdString = vmIdString + vmId + ","; } taskForm.VmMask = vmIdString.Remove(vmIdString.Count() - 1); } _mapper.Map(taskForm, taskToUpdate); taskToUpdate.DateModified = DateTime.UtcNow; taskToUpdate.ModifiedBy = _user.GetId(); await _context.SaveChangesAsync(ct); var updatedTask = _mapper.Map <SAVM.Task>(taskToUpdate); updatedTask.VmList = null; return(updatedTask); }
public async STT.Task <IActionResult> Update([FromRoute] Guid id, [FromBody] SAVM.TaskForm taskForm, CancellationToken ct) { var updatedTask = await _TaskService.UpdateAsync(id, taskForm, ct); return(Ok(updatedTask)); }
public async STT.Task <IActionResult> CreateAndExecute([FromBody] SAVM.TaskForm taskForm, CancellationToken ct) { var resultList = await _TaskService.CreateAndExecuteAsync(taskForm, ct); return(Ok(resultList)); }
public async STT.Task <IActionResult> Create([FromBody] SAVM.TaskForm taskForm, CancellationToken ct) { var createdTask = await _TaskService.CreateAsync(taskForm, ct); return(CreatedAtAction(nameof(this.Get), new { id = createdTask.Id }, createdTask)); }