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 }));
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)); }
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(), });
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 })); }
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); }
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); } }
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"); }
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); } }
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); }
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)); }
public ActionResult PostConversation(MessageRole sender, MessageRole recipient) { return(View(new ConversationPostModel { SenderRole = sender, RecipientRole = recipient })); }