コード例 #1
0
        public async Task <IActionResult> PutSprint([FromRoute] int productId, [FromRoute] int sprintId, [FromBody] SprintBacklog sprint)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (sprint.ProductId != productId || sprint.Id != sprintId)
            {
                return(BadRequest());
            }

            var userId  = int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
            var product = await productService.GetProductById(productId);

            var sprintToUpdate = await sprintService.GetBacklogById(sprintId);

            if (product == null)
            {
                return(NotFound(new { message = "Product not found." }));
            }

            if (sprintToUpdate == null)
            {
                return(NotFound(new { message = "Sprint not found." }));
            }

            if (product.Owner.Id != userId)
            {
                return(Forbid());
            }
            await sprintService.UpdateSprint(sprint);

            return(NoContent());
        }