Exemple #1
0
        public async Task <IActionResult> Post(string projectId, string userEditId, [FromBody] Edit newEdit)
        {
            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 toBeMod = await _repo.GetUserEdit(projectId, userEditId);

            if (toBeMod == null)
            {
                return(new NotFoundObjectResult(userEditId));
            }

            var result = await _userEditService.AddGoalToUserEdit(projectId, userEditId, newEdit);

            // If the replacement was successful
            if (result.Item1)
            {
                return(new OkObjectResult(result.Item2));
            }
            else
            {
                return(new NotFoundObjectResult(result.Item2));
            }
        }
        public async Task <IActionResult> UpdateUserEditGoal(
            string projectId, string userEditId, [FromBody, BindRequired] Edit newEdit)
        {
            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 toBeMod = await _userEditRepo.GetUserEdit(projectId, userEditId);

            if (toBeMod is null)
            {
                return(NotFound(userEditId));
            }

            var(isSuccess, editIndex) = await _userEditService.AddGoalToUserEdit(projectId, userEditId, newEdit);

            // If the replacement was successful
            if (isSuccess)
            {
                return(Ok(editIndex));
            }

            return(NotFound(editIndex.ToString()));
        }