Example #1
0
        public async Task <(bool IsDone, string Message)> UpdateBoardAsync(Guid userId, UpdateBoardModel model)
        {
            try
            {
                var board = await _context.Boards.FindAsync(model.Id);

                var access = await _securityService.GetUserAccessAsync(userId, board.ProjectId);

                if (!access[UserAction.UPDATE_BOARD])
                {
                    return(IsDone : false, Message : "Access denied");
                }

                board.Title      = model.Title;
                board.TaskPrefix = model.Prefix;
                _context.Boards.Update(board);

                var columnIds = model.Columns.Select(x => x.Id).ToList();
                var columns   = await _context.Columns.Where(x => columnIds.Contains(x.Id)).ToListAsync();

                columns.ForEach(x =>
                {
                    var column = model.Columns.First(c => c.Id == x.Id);
                    x.Position = column.Position;
                    x.Title    = column.Title;
                });

                _context.UpdateRange(columns);
                await _context.SaveChangesAsync();

                return(IsDone : true, Message : "Done");
            }
            catch (Exception e)
            {
                _logger.LogError("BoardService, UpdateBoardAsync", e);
            }

            return(IsDone : false, Message : "Something went wrong, try again later");
        }
Example #2
0
        public async Task <IActionResult> UpdateBoard([FromBody] UpdateBoardModel model)
        {
            var(IsDone, Message) = await _boardService.UpdateBoardAsync(this.UserId(), model);

            return(IsDone ? (IActionResult)Ok(Message) : BadRequest(Message));
        }