Example #1
0
        public async Task <IActionResult> Create(CreateConversationDto input)
        {
            var token  = GetToken();
            var userId = LoginHelper.GetClaim(token, "UserId");

            if (input.SenderId != Guid.Parse(userId))
            {
                return(Unauthorized());
            }

            var result = await _conversationAppService.Create(input);

            return(Ok(result));
        }
Example #2
0
        public async Task <Message> Create(CreateMessageDto input)
        {
            if (input.ConversationId == Guid.Empty)
            {
                var conversation = await _conversationAppService.Create(new CreateConversationDto
                                                                        { ReceiverId = input.ReceiverId, SenderId = input.SenderId });

                var message = new Message
                {
                    SenderId       = input.SenderId,
                    ReceiverId     = input.ReceiverId,
                    Content        = input.Content,
                    ConversationId = conversation.Id
                };
                await _messageRepository.AddAsync(message);

                return(message);
            }
            var model = new Message
            {
                SenderId       = input.SenderId,
                ReceiverId     = input.ReceiverId,
                Content        = input.Content,
                ConversationId = input.ConversationId
            };
            await _messageRepository.AddAsync(model);

            var receiver = await _userRepository.GetByIdAsync(input.ReceiverId);

            var sender = await _userRepository.GetByIdAsync(input.SenderId);

            var emailBody = sender.Username + " isimli kullanıcı size mesaj gönderdi";
            await _emailSender.SendEmail(receiver.EmailAddress, "Yeni mesajınız var", emailBody);

            return(model);
        }