Esempio n. 1
0
        //Ako ne uspe dodavanje board-a vratice se null
        public ShortBoardDTO InsertBoard(CreateBoardDTO boardDTO, string username)
        {
            Board board = boardDTO.FromDTO();

            board.ExchangeName = Guid.NewGuid().ToString();
            ShortBoardDTO dto = null;

            using (UnitOfWork unit = new UnitOfWork())
            {
                User creator = unit.UserRepository.GetUserByUsername(username);

                if (board != null && creator != null)
                {
                    Permission permision = new Permission()
                    {
                        IsAdmin = true,
                        Board   = board,
                        User    = creator
                    };

                    BoardNotification boardNotif = new BoardNotification()
                    {
                        Board = board,
                        User  = creator
                    };

                    unit.PermissionRepository.Insert(permision);
                    unit.BoardNotificationRepository.Insert(boardNotif);

                    if (unit.Save())
                    {
                        dto = new ShortBoardDTO(board, true);
                        RabbitMQService.DeclareExchange(board.ExchangeName);
                    }
                }
            }

            return(dto);
        }