コード例 #1
0
        public bool DeleteCard(int id)
        {
            bool success = false;

            using (UnitOfWork uw = new UnitOfWork())
            {
                Card card = uw.CardRepository.GetById(id);

                if (card != null)
                {
                    Board board = card.List.Board;
                    uw.CardRepository.Delete(id);
                    success = uw.Save();

                    if (success)
                    {
                        RabbitMQService.PublishToExchange(board.ExchangeName,
                                                          new MessageContext(new CardMessageStrategy(id)));

                        BoardNotificationService.ChangeBoardNotifications(board.BoardId);
                    }
                }
            }
            return(success);
        }
コード例 #2
0
        public BasicCommentDTO InsertComment(string username, CreateCommentDTO dto)
        {
            Comment         comment    = CreateCommentDTO.FromDTO(dto);
            BasicCommentDTO commentDTO = null;

            using (UnitOfWork uw = new UnitOfWork())
            {
                Card card = uw.CardRepository.GetById(dto.CardId);
                User user = uw.UserRepository.GetUserByUsername(username);
                if (card != null && user != null)
                {
                    comment.Card = card;
                    comment.User = user;
                    uw.CommentRepository.Insert(comment);

                    if (uw.Save())
                    {
                        NotificationService notif = new NotificationService();
                        notif.CreateChangeNotification(new CreateNotificationDTO()
                        {
                            CardId           = dto.CardId,
                            UserId           = user.UserId,
                            NotificationType = NotificationType.Change
                        });

                        commentDTO = new BasicCommentDTO(comment);
                        RabbitMQService.PublishToExchange(card.List.Board.ExchangeName,
                                                          new MessageContext(new CommentMessageStrategy(commentDTO, username)));

                        BoardNotificationService.ChangeBoardNotifications(card.List.Board.BoardId);
                    }
                }
            }
            return(commentDTO);
        }
コード例 #3
0
        public BasicCardDTO InsertCard(string username, CreateCardDTO dto)
        {
            //if (!PermissionHelper.HasPermissionOnList(dto.ListId, userId))
            //{
            //    return 0;
            //}

            BasicCardDTO cardDto = null;

            using (UnitOfWork uw = new UnitOfWork())
            {
                CardList list = uw.CardListRepository.GetById(dto.ListId);
                User     user = uw.UserRepository.GetUserByUsername(username);

                Card card = CreateCardDTO.FromDTO(dto);

                if (user != null && list != null)
                {
                    card.User = user;
                    card.List = list;
                    uw.CardRepository.Insert(card);
                    if (uw.Save())
                    {
                        cardDto = new BasicCardDTO(card);
                        RabbitMQService.PublishToExchange(list.Board.ExchangeName,
                                                          new MessageContext(new CardMessageStrategy(cardDto, MessageType.Create, username)));

                        BoardNotificationService.ChangeBoardNotifications(list.Board.BoardId);
                    }
                }
            }
            return(cardDto);
        }
コード例 #4
0
        public bool UpdateCardList(int cardlistId, UpdateCardListDTO cardListDTO, string username)
        {
            bool ret = false;

            using (UnitOfWork unit = new UnitOfWork())
            {
                CardList cardList = unit.CardListRepository.GetById(cardlistId);

                if (cardList != null)
                {
                    cardList.Name  = cardListDTO.Name;
                    cardList.Color = cardListDTO.Color;

                    unit.CardListRepository.Update(cardList);

                    ret = unit.Save();

                    if (ret)
                    {
                        BasicCardListDTO dto = new BasicCardListDTO(cardList);
                        RabbitMQService.PublishToExchange(cardList.Board.ExchangeName,
                                                          new MessageContext(new CardListMessageStrategy(dto, MessageType.Update, username)));

                        BoardNotificationService.ChangeBoardNotifications(cardList.Board.BoardId);
                    }
                }
            }

            return(ret);
        }
コード例 #5
0
        public BasicCardListDTO InsertCardList(CreateCardListDTO cardListDto, string username)
        {
            //if (!PermissionHelper.HasPermissionOnBoard(cardListDto.BoardId, userId))
            //{
            //    return 0;
            //}

            BasicCardListDTO dto  = null;
            CardList         list = cardListDto.FromDTO();

            using (UnitOfWork unit = new UnitOfWork())
            {
                Board board = unit.BoardRepository.GetById(cardListDto.BoardId);

                if (board != null)
                {
                    list.Board = board;

                    unit.CardListRepository.Insert(list);
                    if (unit.Save())
                    {
                        dto = new BasicCardListDTO(list);
                        RabbitMQService.PublishToExchange(board.ExchangeName,
                                                          new MessageContext(new CardListMessageStrategy(dto, MessageType.Create, username)));

                        BoardNotificationService.ChangeBoardNotifications(board.BoardId);
                    }
                }
            }

            return(dto);
        }
コード例 #6
0
        public bool DeleteCardList(int id, string username)
        {
            bool ret = false;

            using (UnitOfWork unit = new UnitOfWork())
            {
                CardList cardlist = unit.CardListRepository.GetById(id);

                if (cardlist != null)
                {
                    Board  board        = cardlist.Board;
                    string exchangeName = board.ExchangeName;
                    int    boardId      = board.BoardId;

                    unit.CardListRepository.Delete(id);
                    ret = unit.Save();

                    if (ret)
                    {
                        RabbitMQService.PublishToExchange(exchangeName,
                                                          new MessageContext(new CardListMessageStrategy(id, username)));

                        BoardNotificationService.ChangeBoardNotifications(boardId);
                    }
                }
            }

            return(ret);
        }
コード例 #7
0
        public bool UpdateCard(int cardId, string username, UpdateCardDTO dto)
        {
            bool succ = false;

            using (UnitOfWork uw = new UnitOfWork())
            {
                Card card = uw.CardRepository.GetById(cardId);
                User user = uw.UserRepository.GetUserByUsername(username);
                if (card != null && user != null)
                {
                    card.Name        = dto.Name;
                    card.Description = dto.Description;
                    card.DueDate     = dto.DueDate;
                    uw.CardRepository.Update(card);

                    NotificationService notif = new NotificationService();
                    notif.CreateChangeNotification(new CreateNotificationDTO()
                    {
                        CardId           = card.CardId,
                        UserId           = user.UserId,
                        NotificationType = NotificationType.Change
                    });

                    succ = uw.Save();

                    if (succ)
                    {
                        BasicCardDTO cardDto = new BasicCardDTO(card);
                        RabbitMQService.PublishToExchange(card.List.Board.ExchangeName,
                                                          new MessageContext(new CardMessageStrategy(cardDto, MessageType.Update, username)));

                        BoardNotificationService.ChangeBoardNotifications(card.List.Board.BoardId);
                    }
                }
            }
            return(succ);
        }
コード例 #8
0
        public bool MoveCardToList(int cardId, int listId, string username)
        {
            bool succ = false;

            using (UnitOfWork uw = new UnitOfWork())
            {
                Card card = uw.CardRepository.GetById(cardId);
                if (card != null && card.List.ListId != listId)
                {
                    CardList list = uw.CardListRepository.GetById(listId);
                    User     user = uw.UserRepository.GetUserByUsername(username);
                    if (list != null && user != null)
                    {
                        list.Cards.Add(card);
                        uw.CardListRepository.Update(list);

                        if (uw.Save())
                        {
                            NotificationService notif = new NotificationService();
                            succ = notif.CreateMoveNotification(new CreateNotificationDTO()
                            {
                                CardId           = cardId,
                                UserId           = user.UserId,
                                NotificationType = NotificationType.Move
                            });

                            BasicCardDTO cardDto = new BasicCardDTO(card);
                            RabbitMQService.PublishToExchange(card.List.Board.ExchangeName,
                                                              new MessageContext(new CardMessageStrategy(cardDto, MessageType.Move, username)));

                            BoardNotificationService.ChangeBoardNotifications(card.List.Board.BoardId);
                        }
                    }
                }
            }
            return(succ);
        }
コード例 #9
0
        public bool UpdateBoard(int boardId, UpdateBoardDTO boardDTO, string username)
        {
            bool ret = false;

            using (UnitOfWork unit = new UnitOfWork())
            {
                Board board = unit.BoardRepository.GetById(boardId);

                if (board != null)
                {
                    board.Name = boardDTO.Name;

                    unit.BoardRepository.Update(board);
                    ret = unit.Save();
                    if (ret)
                    {
                        BoardNotificationService.ChangeBoardNotifications(board.BoardId);

                        BasicBoardDTO dto = new BasicBoardDTO(board);

                        RabbitMQService.PublishToExchange(board.ExchangeName,
                                                          new MessageContext(new BoardMessageStrategy(dto, MessageType.Update, username)));

                        List <User> users = unit.PermissionRepository.GetAllUsersWithPermissionOnBoard(board.BoardId);

                        foreach (var u in users)
                        {
                            RabbitMQService.PublishToExchange(u.ExchangeName,
                                                              new MessageContext(new BoardMessageStrategy(dto, MessageType.UserUpdate, username)));
                        }
                    }
                }
            }

            return(ret);
        }