Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public CommentMessageStrategy(BasicCommentDTO data, string username)
 {
     commentMessage = new CommentMessage(username)
     {
         Data = data
     };
 }
Ejemplo n.º 3
0
        private async void OnNewComment()
        {
            if (ActiveUser.IsActive == true && !String.IsNullOrWhiteSpace(NewComment))
            {
                CreateCommentDTO createCommentDTO = new CreateCommentDTO()
                {
                    Text = NewComment, CardId = cardId
                };
                BasicCommentDTO basicCommentDTO = await CommentService.CreateComment(ActiveUser.Instance.LoggedUser.Token, createCommentDTO);

                if (basicCommentDTO != null)
                {
                    var comment = new ReadComment(basicCommentDTO);
                    Comments.Add(comment);
                    NewComment = "";
                }
                else
                {
                    ShowMessageBox(null, "Error creating list.");
                }
            }
            else
            {
                ShowMessageBox(null, "Error getting user.");
            }
        }
Ejemplo n.º 4
0
 public ReadComment(BasicCommentDTO dto)
 {
     if (dto != null)
     {
         CommentId = dto.CommentId;
         Text      = dto.Text;
         TimeStamp = dto.TimeStamp;
         //CardId = dto.CardId;
         //ListId = dto.ListId;
         Username = dto.Username;
     }
 }
Ejemplo n.º 5
0
        private void CreateCommentAction(object obj)
        {
            BasicCommentDTO comment = (BasicCommentDTO)obj;

            if (comment != null && comment.CardListId == CardList.ListId)
            {
                ReadCard card = CardList.Cards.FirstOrDefault(c => c.CardId == comment.CardId);

                if (card != null)
                {
                    card.Comments.Add(new ReadComment(comment));
                }
            }
        }
Ejemplo n.º 6
0
        public static MQMessage GetMessage(string stringMessage)
        {
            var jsonMessage = GetJObjectFromString(stringMessage);
            if (jsonMessage == null)
                return null;

            var messageType = GetJTokenByKey("MessageType", jsonMessage);
            if (messageType == null)
                return null;

            var messageEntity = GetJTokenByKey("MessageEntity", jsonMessage);
            if (messageEntity == null)
                return null;

            var messageUsername = GetJTokenByKey("Username", jsonMessage);

            var data = GetJTokenByKey("Data", jsonMessage);
            if (data == null)
                return null;

            var stringData = data.ToString();

            var type = (MessageType)messageType.Value<int>();
            var entity = (MessageEntity)messageEntity.Value<int>();
            var username = (string)messageUsername.Value<string>();

            if (type == MessageType.Delete)
            {
                int parsedData = JsonConvert.DeserializeObject<int>(stringData);
                return new DeleteMessage() { MessageType = MessageType.Delete, MessageEntity = entity, Data = parsedData };
            }
            else if (type == MessageType.BoardNotification)
            {
                int parsedData = JsonConvert.DeserializeObject<int>(stringData);
                return new BoardNotificationMessage() { MessageType = MessageType.BoardNotification, MessageEntity = entity, Data = parsedData };
            }
            else if (entity == MessageEntity.Board)
            {
                BasicBoardDTO parsedData = JsonConvert.DeserializeObject<BasicBoardDTO>(stringData);
                return new BoardMesage() { MessageType = type, MessageEntity = entity, Data = parsedData };
            }
            else if (entity == MessageEntity.Card)
            {
                BasicCardDTO parsedData = JsonConvert.DeserializeObject<BasicCardDTO>(stringData);
                return new CardMessage() { MessageType = type, MessageEntity = entity, Data = parsedData };
            }
            else if (entity == MessageEntity.CardList)
            {
                BasicCardListDTO parsedData = JsonConvert.DeserializeObject<BasicCardListDTO>(stringData);
                return new CardListMessage() { MessageType = type, MessageEntity = entity, Data = parsedData, Username = username };
            }
            else if (entity == MessageEntity.Comment)
            {
                BasicCommentDTO parsedData = JsonConvert.DeserializeObject<BasicCommentDTO>(stringData);
                return new CommentMessage() { MessageType = type, MessageEntity = entity, Data = parsedData };
            }
            else if (entity == MessageEntity.Notification)
            {
                ReadNotificationDTO parsedData = JsonConvert.DeserializeObject<ReadNotificationDTO>(stringData);
                return new NotificationMessage() { MessageType = type, MessageEntity = entity, Data = parsedData };
            }
            else
            {
                return null;
            }


        }