public async Task <BoardReturnDto> AddPinToBoardAsync(AddPinToBoardDto model) { var userId = long.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); var pinInDb = await _pinService.GetByIdAsync(model.PinId); if (pinInDb == null) { throw new ObjectNotFoundException("Pin not found."); } var boardInDb = await _boardService.GetByIdAsync(model.BoardId); if (boardInDb == null) { throw new ObjectNotFoundException("Board not found."); } if (boardInDb.CreatedBy != userId) { throw new UnauthorizedAccessException("You have no permissions to edit this board."); } var relation = new BoardPin { CreatedBy = userId, Pin = pinInDb, Board = boardInDb }; await _boardPinService.InsertAsync(relation); return(boardInDb.ToBoardReturnDto(true)); }
public async Task <long> AddPinAsync(AddPinDto model) { var userId = long.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); var usr = await(await _personService.GetAllAsync(d => d.Id == userId)).FirstOrDefaultAsync(); var boardInDb = await _boardService.GetByIdAsync(model.BoardId); if (boardInDb == null) { throw new ObjectNotFoundException("Board not found."); } if (boardInDb.CreatedBy != userId) { throw new UnauthorizedAccessException("You have no permissions to edit this board."); } var pin = await _pinService.InsertAsync(model.ToPin(usr)); var relation = new BoardPin { CreatedBy = usr.Id, Pin = pin, Board = boardInDb }; await _boardPinService.InsertAsync(relation); return(pin.Id); }
public static LastPinActionDto ToLastPinActionDto(this BoardPin boardPin) { return(new LastPinActionDto { Date = boardPin.Created, UserName = boardPin.Board.Person.UserName, BoardName = boardPin.Board.Name, BoardId = boardPin.Board.Id, UserId = boardPin.Board.Person.Id }); }
public BoardPin SavePin([FromBody] BoardPin boardPinData) { try { var userId = HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.Name) .Select(c => c.Value).SingleOrDefault(); boardPinData.UserId = userId; return(_pinRepo.SavePin(boardPinData)); } catch (Exception e) { System.Console.WriteLine(e.Message); return(null); } }
public BoardPin SavePin(BoardPin boardPinData) { Guid g; g = Guid.NewGuid(); string id = g.ToString(); BoardPin boardPin = new BoardPin() { Id = id, BoardId = boardPinData.BoardId, PinId = boardPinData.PinId, UserId = boardPinData.UserId }; var success = _db.Execute(@" INSERT INTO boardpins( id, boardId, pinId, userId ) VALUES(@Id, @BoardId, @PinId, @UserId)", boardPin); if (success < 1) { throw new Exception("Invalid BoardPin"); } else { return(new BoardPin() { Id = boardPin.Id, BoardId = boardPin.BoardId, PinId = boardPin.Id, UserId = boardPin.UserId }); } }