예제 #1
0
 public void SendMessageFromUserToUser(long sender, MessageRole senderRole, long recipient,
                                       MessageRole recipientRole,
                                       string messageText)
 => WithConnection(conn => conn.Execute(
                       $"INSERT INTO [{nameof(Message)}s] ([{nameof(Message.SenderId)}],[{nameof(Message.RecipientId)}],[{nameof(Message.SenderRole)}],[{nameof(Message.RecipientRole)}],[{nameof(Message.MessageText)}]) " +
                       $"VALUES(@{nameof(sender)}, @{nameof(recipient)}, @{nameof(senderRole)}, @{nameof(recipientRole)}, @{nameof(messageText)})",
                       new { sender, recipient, senderRole, recipientRole, messageText }));
예제 #2
0
        public Task SendEmailAsync(MessageRole messageRole, string messageDisplay, string email, string subject, string body)
        {
            var(username, password) = GetRoleCredentials(messageRole);

            Task.Run(() => _emailSender.SendAsync(username, password, messageDisplay, email, subject, body)).Forget();

            return(Task.CompletedTask);
        }
        private static string GetLabel(bool fromUser, MessageRole messageSenderRole)
        {
            if (fromUser)
            {
                return(Resources.Global.Messages_FromYou);
            }

            return(MessageRoleTranslationHelper.From(messageSenderRole));
        }
예제 #4
0
 private (string userName, string password) GetRoleCredentials(MessageRole role)
 {
     return(role switch
     {
         MessageRole.Admin => (_appSettings.Value.Company.AdminEmail, _appSettings.Value.Company.AdminPassword),
         MessageRole.Notification => (_appSettings.Value.Company.NotificationEmail, _appSettings.Value.Company.NotificationPassword),
         MessageRole.Info => (_appSettings.Value.Company.InfoEmail, _appSettings.Value.Company.InfoPassword),
         _ => throw new InvalidOperationException(),
     });
예제 #5
0
        public void SendMessageFromAdmin(long recipient, string messageText)
        {
            const MessageRole senderRole    = MessageRole.Administrator;
            const MessageRole recipientRole = MessageRole.User;

            WithConnection(conn => conn.Execute(
                               $"INSERT INTO [{nameof(Message)}s] ([{nameof(Message.RecipientId)}],[{nameof(Message.SenderRole)}],[{nameof(Message.RecipientRole)}],[{nameof(Message.MessageText)}]) " +
                               $"VALUES(@{nameof(recipient)}, @{nameof(senderRole)}, @{nameof(recipientRole)}, @{nameof(messageText)})",
                               new { recipient, senderRole, recipientRole, messageText }));
        }
예제 #6
0
        public void SendNewMessageNotification(SantaUser recipient, MessageRole @from, string messageText)
        {
            var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

            var subject = string.Format(Resources.Global.Email_NewMessage_Subject, MessageRoleTranslationHelper.From(from));
            var body    = string.Format(Resources.Global.Email_NewMessage_Body, recipient.DisplayName, MessageRoleTranslationHelper.From(from),
                                        messageText, urlHelper.Action("Index", "Messages", new { }, HttpContext.Current.Request.Url.Scheme));

            SendEmail(recipient.Email, subject, body);
        }
예제 #7
0
        public void SendMessageFromUserToUser(long sender, MessageRole senderRole, long recipient, MessageRole recipientRole,
                                              string messageText)
        {
            // Save to db
            _messageRepository.SendMessageFromUserToUser(sender, senderRole, recipient, recipientRole, messageText);

            // send email
            if (_sendEmail)
            {
                _emailService.SendNewMessageNotification(_userRepository.GetUserWithoutProtectedData(recipient),
                                                         senderRole, messageText);
            }
        }
예제 #8
0
        private long GetRecipient(MessageRole modelRecipientRole, long userId)
        {
            switch (modelRecipientRole)
            {
            case MessageRole.GiftRecipient:
                return(_userRepository.GetAssignedPartnerIdForUser(userId) ??
                       throw new InvalidOperationException(
                           $"User ({userId}) that has not been in assignment tried to send a message to recipient"));

            case MessageRole.GiftSender:
                return(_userRepository.GetUserAssignedTo(userId) ?? throw new InvalidOperationException(
                           $"User ({userId}) that has not been in assignment tried to send a message to recipient"));
            }
            throw new ArgumentOutOfRangeException(nameof(modelRecipientRole), $"User ({userId}) requested recipient for role {modelRecipientRole.ToString()} which should not have happened");
        }
예제 #9
0
        public static string To(MessageRole role)
        {
            switch (role)
            {
            case MessageRole.GiftSender:
                return(Resources.Global.Messages_ToGiver);

            case MessageRole.GiftRecipient:
                return(Resources.Global.Messages_ToAssigned);

            case MessageRole.Administrator:
                return(Resources.Global.Messages_ToAdmin);

            default:
                throw new ArgumentOutOfRangeException(nameof(role), role, null);
            }
        }
예제 #10
0
        public async Task SendEmailAsync <TModel>(MessageRole messageRole, MessageType messageType, string messageDisplay, string email, string subject, TModel model)
        {
            string body = await _razorViewRenderer.RenderViewToStringAsync($"~/Views/Shared/Templates/Email/{messageType}.cshtml", model);

            await SendEmailAsync(messageRole, messageDisplay, email, subject, body);
        }
예제 #11
0
        public Task SendEmailAsync <TModel>(MessageRole messageRole, MessageType messageType, string messageDisplay, string email, TModel model)
        {
            string subject = messageType.GetEnumText();

            return(SendEmailAsync(messageRole, messageType, messageDisplay, email, subject, model));
        }
예제 #12
0
 public ActionResult PostConversation(MessageRole sender, MessageRole recipient)
 {
     return(View(new ConversationPostModel {
         SenderRole = sender, RecipientRole = recipient
     }));
 }