public async Task <IActionResult> UpdateUserEditStep(string projectId, string userEditId, [FromBody, BindRequired] UserEditStepWrapper stepEdit) { if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry)) { return(Forbid()); } // Check to see if user is changing the correct user edit if (await _permissionService.IsViolationEdit(HttpContext, userEditId, projectId)) { return(BadRequest("You cannot edit another user's UserEdit.")); } // Ensure project exists. var proj = await _projRepo.GetProject(projectId); if (proj is null) { return(NotFound(projectId)); } // Ensure userEdit exists. var document = await _userEditRepo.GetUserEdit(projectId, userEditId); if (document is null) { return(NotFound(projectId)); } // Ensure indices exist. if (stepEdit.GoalIndex < 0 || stepEdit.GoalIndex >= document.Edits.Count) { return(BadRequest("Goal index out of range.")); } var maxStepIndex = document.Edits[stepEdit.GoalIndex].StepData.Count; var stepIndex = stepEdit.StepIndex ?? maxStepIndex; if (stepIndex < 0 || stepIndex > maxStepIndex) { return(BadRequest("Step index out of range.")); } // Add new step to or update step in goal. if (stepIndex == maxStepIndex) { await _userEditService.AddStepToGoal( projectId, userEditId, stepEdit.GoalIndex, stepEdit.StepString); } else { await _userEditService.UpdateStepInGoal( projectId, userEditId, stepEdit.GoalIndex, stepEdit.StepString, stepIndex); } return(Ok(stepIndex)); }
public async Task <IActionResult> Put(string projectId, string userEditId, [FromBody] UserEditObjectWrapper userEdit) { if (!_permissionService.HasProjectPermission(Permission.WordEntry, HttpContext)) { return(new ForbidResult()); } // Check to see if user is changing the correct user edit if (_permissionService.IsViolationEdit(HttpContext, userEditId, projectId)) { return(new BadRequestObjectResult("You can not edit another users UserEdit")); } // Ensure project exists var proj = _projectService.GetProject(projectId); if (proj == null) { return(new NotFoundObjectResult(projectId)); } // Ensure userEdit exists var document = await _repo.GetUserEdit(projectId, userEditId); if (document == null) { return(new NotFoundResult()); } // Ensure index exists if (userEdit.GoalIndex >= document.Edits.Count) { return(new BadRequestObjectResult("Goal index out of range")); } await _userEditService.AddStepToGoal(projectId, userEditId, userEdit.GoalIndex, userEdit.NewEdit); return(new OkObjectResult(document.Edits[userEdit.GoalIndex].StepData.Count - 1)); }