public IActionResult Update(int id, [FromBody] UserStoryUpdateModel model)
        {
            var userStoryModel = _mapper.Map <UserStoryModel>(model);

            userStoryModel.Id = id;

            try
            {
                _userStoryService.Update(userStoryModel);
                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Exemplo n.º 2
0
        public async Task UpdateAsync(UserStoryUpdateModel updateModel)
        {
            var toUpdate = this.userStoryRepo.All()
                           .Where(x => x.Id == updateModel.Id)
                           .Include(x => x.Tests)
                           .Include(x => x.Tasks)
                           .FirstOrDefault();

            toUpdate.ModifiedOn         = DateTime.UtcNow;
            toUpdate.Title              = updateModel.Title;
            toUpdate.StoryPoints        = updateModel.StoryPoints;
            toUpdate.AcceptanceCriteria = updateModel.AcceptanceCriteria;
            toUpdate.BacklogPriorityId  = updateModel.BacklogPriorityid;
            toUpdate.Description        = updateModel.Description;

            // If sprint is changed
            if (toUpdate.SprintId != updateModel.SprintId && updateModel.SprintId != null)
            {
                int sprintId = updateModel.SprintId ?? default;
                var columnId = (await this.boardService.GetAllColumnsAsync(toUpdate.ProjectId, sprintId)).FirstOrDefault().Id;

                if (toUpdate.SprintId != null)
                {
                    await RemoveFromBurndownData(toUpdate.SprintId, toUpdate.KanbanBoardColumnId);
                }

                await UpdateBurndownTsks(updateModel.SprintId, columnId, true);

                toUpdate.SprintId            = sprintId;
                toUpdate.KanbanBoardColumnId = columnId;

                foreach (var test in toUpdate.Tests)
                {
                    test.KanbanBoardColumnId = columnId;
                }

                foreach (var task in toUpdate.Tasks)
                {
                    task.KanbanBoardColumnId = columnId;
                }
            }
            // If sprint is set to null then userStory should be removed from table
            else if (updateModel.SprintId == null)
            {
                // Remove from sprint and board.
                toUpdate.SprintId            = updateModel.SprintId;
                toUpdate.KanbanBoardColumnId = null;

                foreach (var test in toUpdate.Tests)
                {
                    test.KanbanBoardColumnId = null;
                }

                foreach (var task in toUpdate.Tasks)
                {
                    task.KanbanBoardColumnId = null;
                }
            }

            // Add comments if there are any
            if (updateModel.Comment != null)
            {
                var comment = new UserStoryComment
                {
                    UserId      = updateModel.Comment.AddedById,
                    Description = updateModel.Comment.SanitizedDescription,
                    AddedOn     = DateTime.UtcNow
                };

                toUpdate.Comments.Add(comment);
            }

            // Add mockups
            foreach (var mockup in updateModel.MockupPaths)
            {
                toUpdate.Mockups.Add(new Mockup()
                {
                    AddedOn     = DateTime.UtcNow,
                    MockUpPath  = mockup,
                    UserStoryId = toUpdate.Id,
                });
            }

            this.userStoryRepo.Update(toUpdate);
            await this.userStoryRepo.SaveChangesAsync();
        }