示例#1
0
        public IActionResult CreateColumn(CreateColumnModel model)
        {
            var board = _boards.GetEntity(model.BoardId);

            if (board == null)
            {
                return(RedirectToAction("Boards"));
            }
            if (ModelState.IsValid)
            {
                var column = new Column
                {
                    Name  = model.ColumnName.Trim(),
                    Board = board
                };
                _columns.AddEntity(column);
                _columns.Save();
            }
            else
            {
                ModelState.AddModelError("Name", "Missing name!");
            }
            return(RedirectToAction("Board", new { id = board.Id }));
        }
示例#2
0
        public async Task <(bool IsDone, string Message)> CreateColumnAsync(Guid userId, CreateColumnModel model)
        {
            try
            {
                var board = await _context.Boards.FindAsync(model.BoardId);

                if (board == null)
                {
                    return(IsDone : false, Message : "There is no such board");
                }

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

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

                var lastColumn  = _context.Columns.Where(x => x.BoardId == model.BoardId).OrderBy(x => x.Position).LastOrDefault();
                var newPosition = lastColumn == null ? 0 : lastColumn.Position + 1;
                var column      = new Column
                {
                    BoardId  = model.BoardId,
                    Title    = model.Title,
                    Position = newPosition
                };

                await _context.Columns.AddAsync(column);

                await _context.SaveChangesAsync();

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

            return(IsDone : false, Message : "Something went wrong, try again later");
        }
示例#3
0
        public async Task <IActionResult> CreateColumn([FromBody] CreateColumnModel model)
        {
            var(IsDone, Message) = await _boardService.CreateColumnAsync(this.UserId(), model);

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