private async Task <ASquare_Payment> GetPaymentDetails(MSquare_Payment mPayment) { var mPaymentTransactions = await SquareMicroService.GetPaymentTransactionSummariesAsync(mPayment.SquarePaymentId, null, null); var mPaymentEvents = await SquareMicroService.GetPaymentEventLogSummariesAsync(mPayment.SquarePaymentId, null, null); var mRefundTransactions = await SquareMicroService.GetRefundTransactionSummariesAsync(null, mPayment.SquarePaymentId, null, null); var mRefundEvents = await SquareMicroService.GetRefundEventLogSummariesAsync(null, mPayment.SquarePaymentId, null, null); var mUser = TryParseUserId.FromSquareCustomerReference(mPayment.SquareCustomerReference, out string userId) ? await UserMicroService.GetUserAsync(userId).ConfigureAwait(false) : null; var funderReference = CreateFunderReference.FromSquarePaymentId(mPayment.SquarePaymentId); var funderId = await FundingMicroService.LookupFunderAsync(funderReference); var result = new ASquare_Payment() { MPayment = mPayment, MPaymentTransactions = mPaymentTransactions, MPaymentEvents = mPaymentEvents, MRefundTransactions = mRefundTransactions, MRefundEvents = mRefundEvents, MUser = mUser, FunderId = funderId }; return(result); }
public async Task <ANotification_Notification> GetNotificationAsync(long notificationId) { using var log = BeginFunction(nameof(NotificationAdminService), nameof(GetNotificationAsync), notificationId); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var mNotification = await CommunicationMicroService.GetNotificationAsync(notificationId).ConfigureAwait(false); var mUser = mNotification.ParticipantReference != null && TryParseUserId.FromParticipantReference(mNotification.ParticipantReference, out string userId) ? await UserMicroService.GetUserAsync(userId) : null; var result = Create.ANotification_Notification(mNotification, mUser); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <ANotification_NotificationList> GetNotificationsAsync(bool?acknowledged, int recordCount) { using var log = BeginFunction(nameof(NotificationAdminService), nameof(GetNotificationsAsync), acknowledged, recordCount); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var notifications = new List <ANotification_Notification>(); var mNotifications = await CommunicationMicroService.GetNotificationsAsync(recordCount, acknowledged).ConfigureAwait(false); foreach (var mNotification in mNotifications.Notifications) { var mUser = mNotification.ParticipantReference != null && TryParseUserId.FromParticipantReference(mNotification.ParticipantReference, out string userId) ? await UserMicroService.GetUserAsync(userId) : null; var notification = Create.ANotification_Notification(mNotification, mUser); notifications.Add(notification); } var result = new ANotification_NotificationList() { Notifications = notifications }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <AAlert_AlertList> GetAlertsAsync(bool?acknowledged, int recordCount) { using var log = BeginFunction(nameof(AlertAdminService), nameof(GetAlertsAsync), acknowledged, recordCount); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var alerts = new List <AAlert_Alert>(); var mAlerts = await CommunicationMicroService.GetAlertsAsync(recordCount, acknowledged); foreach (var mAlert in mAlerts.Alerts) { var mUser = mAlert.ParticipantReference != null && TryParseUserId.FromParticipantReference(mAlert.ParticipantReference, out string userId) ? await UserMicroService.GetUserAsync(userId) : null; var alert = Create.AAlert_Alert(mAlert, mUser); alerts.Add(alert); } var result = new AAlert_AlertList() { Alerts = alerts }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <AOrder_Order> GetOrderAsync(long orderId) { using var log = BeginFunction(nameof(OrderAdminService), nameof(GetOrderAsync), orderId); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var mOrder = await OrderMicroService.GetOrderAsync(orderId).ConfigureAwait(false); var mTransactions = await OrderMicroService.GetOrderTransactionSummariesAsync(orderId, null, null); var mEvents = await OrderMicroService.GetOrderEventLogSummariesAsync(orderId, null, null); var fulfillableReference = CreateFulfillableReference.FromOrderId(orderId); var fulfillableId = await FulfillmentMicroService.LookupFulfillableAsync(fulfillableReference); var mFulfillable = fulfillableId != null ? await FulfillmentMicroService.GetFulfillableAsync(fulfillableId.Value).ConfigureAwait(false) : null; var fundableReference = CreateFundableReference.FromOrderId(orderId); var fundableId = await FundingMicroService.LookupFundableAsync(fundableReference); var mFundable = fundableId != null ? await FundingMicroService.GetFundableAsync(fundableId.Value).ConfigureAwait(false) : null; var mUser = TryParseUserId.FromOrdererReference(mOrder.OrdererReference, out string userId) ? await UserMicroService.GetUserAsync(userId) : null; var result = Create.AOrder_Order(mOrder, mTransactions, mEvents, mFulfillable, mFundable, mUser); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task HandleFunderEventAsync(MFunding_FunderEvent eventData) { using var log = BeginFunction(nameof(FundingEventMicroService), nameof(HandleFunderEventAsync), eventData); try { using var ctx = CreateQuiltContext(); await Task.CompletedTask.ConfigureAwait(false); if (eventData.FundsAvailable != 0) { if (TryParseUserId.FromFunderReference(eventData.FunderReference, out var funderUserId)) { } } } catch (Exception ex) { log.Exception(ex); throw; } }
private async Task <long> SendMessageAsync(string sendReceiveCode, long participantId, string subject, string text, long?replyToMessageId, long?topicId) { using var ctx = QuiltContextFactory.Create(); var dbParticipant = await ctx.Participants.Where(r => r.ParticipantId == participantId).FirstAsync().ConfigureAwait(false); string formattedName; string email; if (TryParseUserId.FromParticipantReference(dbParticipant.ParticipantReference, out string userId)) { var dbAspNetUser = await ctx.AspNetUsers.Where(r => r.Id == userId).SingleAsync().ConfigureAwait(false); var dbUserProfile = await ctx.UserProfiles.Where(r => r.UserProfileAspNetUser.AspNetUserId == userId).SingleOrDefaultAsync().ConfigureAwait(false); formattedName = Create.FormattedName(dbUserProfile); email = dbAspNetUser.Email; } else { formattedName = dbParticipant.ParticipantReference; email = $"{dbParticipant.ParticipantId}@richtodd.com"; } Message dbReplyToMessage; if (replyToMessageId != null) { dbReplyToMessage = await ctx.Messages.Where(r => r.MessageId == replyToMessageId.Value).SingleAsync().ConfigureAwait(false); if (dbReplyToMessage.ParticipantId != participantId) { throw new InvalidOperationException(string.Format("Reply to message user ID mismatch (user ID = {0}, message user ID = {1}). ", participantId, dbReplyToMessage.Participant.ParticipantReference)); } if (topicId == null) { // Propagate order ID from original message. // topicId = dbReplyToMessage.TopicId; } else { if (dbReplyToMessage.TopicId != null) { if (dbReplyToMessage.TopicId != topicId) { throw new InvalidOperationException(string.Format("Reply to message topic ID mismatch (topic ID = {0}, message topic ID = {1}). ", topicId, dbReplyToMessage.TopicId)); } } } } else { dbReplyToMessage = null; } var dbMessage = new Message() { ParticipantId = participantId, ConversationId = dbReplyToMessage != null ? dbReplyToMessage.ConversationId : Guid.NewGuid(), SendReceiveCode = sendReceiveCode, Subject = subject, Text = text, Email = email, TopicId = topicId, CreateDateTimeUtc = GetUtcNow() }; _ = ctx.Messages.Add(dbMessage); IDictionary <string, string> topicFields = new Dictionary <string, string>(); if (topicId.HasValue) { foreach (var dbTopicField in await ctx.TopicFields.Where(r => r.TopicId == topicId.Value).ToListAsync()) { topicFields[dbTopicField.FieldCode] = dbTopicField.FieldValue; } } var formatter = new InboundMessageEmailFormatter(formattedName, email, subject, text, topicFields); var dbEmailRequest = new EmailRequest() { EmailRequestStatusCode = EmailRequestStatusCodes.Posted, SenderEmail = Constants.DoNotReplyEmail, // dbAspNetUser.Email SenderEmailName = Constants.DoNotReplyEmailName, // dbAspNetUser.EmailName RecipientEmail = Constants.AdminMailEmail, RecipientEmailName = Constants.AdminMailEmailName, RecipientParticipantId = null, Subject = formatter.GetSubject(), BodyText = formatter.GetText(), BodyHtml = formatter.GetHtml(), BodyTypeCode = EmailBodyTypes.Message, CreateDateTimeUtc = GetUtcNow(), EmailRequestStatusDateTimeUtc = GetUtcNow() }; _ = ctx.EmailRequests.Add(dbEmailRequest); var dbMessageEmailRequest = new MessageEmailRequest() { Message = dbMessage, EmailRequest = dbEmailRequest }; _ = ctx.MessageEmailRequests.Add(dbMessageEmailRequest); _ = await ctx.SaveChangesAsync().ConfigureAwait(false); return(dbMessage.MessageId); }
public async Task SendNotification(long participantId, string notificationTypeCode, long?topicId) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(SendNotification), participantId, notificationTypeCode, topicId); try { using var ctx = QuiltContextFactory.Create(); var dbNotification = new Notification() { ParticipantId = participantId, NotificationTypeCode = notificationTypeCode, TopicId = topicId, CreateDateTimeUtc = GetUtcNow() }; _ = ctx.Notifications.Add(dbNotification); var dbNotificationType = ctx.NotificationTypes.Find(dbNotification.NotificationTypeCode); var formatter = new NotificationEmailFormatter(dbNotificationType.Subject); var dbParticipant = ctx.Participants.Where(r => r.ParticipantId == dbNotification.ParticipantId).Single(); string email; if (TryParseUserId.FromParticipantReference(dbParticipant.ParticipantReference, out string userId)) { var dbAspNetUser = await ctx.AspNetUsers.Where(r => r.Id == userId).SingleAsync().ConfigureAwait(false); email = dbAspNetUser.Email; var dbEmailRequest = new EmailRequest() { EmailRequestStatusCode = EmailRequestStatusCodes.Posted, SenderEmail = Constants.DoNotReplyEmail, SenderEmailName = Constants.DoNotReplyEmailName, RecipientEmail = email, RecipientEmailName = email, RecipientParticipant = dbNotification.Participant, Subject = formatter.GetSubject(), BodyText = formatter.GetText(), BodyHtml = formatter.GetHtml(), BodyTypeCode = EmailBodyTypes.Notification, CreateDateTimeUtc = GetUtcNow(), EmailRequestStatusDateTimeUtc = GetUtcNow(), }; _ = ctx.EmailRequests.Add(dbEmailRequest); var dbNotificationEmailRequest = new NotificationEmailRequest() { Notification = dbNotification, EmailRequest = dbEmailRequest }; _ = ctx.NotificationEmailRequests.Add(dbNotificationEmailRequest); } _ = await ctx.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public static MCommunication_Message MCommunication_Message( QuiltContext ctx, Message dbMessage, bool canAcknowledge, bool includeEmails, IList <MCommunication_Message> conversation) { string email; if (TryParseUserId.FromParticipantReference(dbMessage.Participant.ParticipantReference, out string userId)) { var dbAspNetUser = ctx.AspNetUsers.Where(r => r.Id == userId).Single(); email = dbAspNetUser.Email; } else { userId = null; email = $"{dbMessage.Participant.ParticipantId}@richtodd.com"; } string from; string to; if (dbMessage.SendReceiveCode == SendReceiveCodes.FromUser) { from = email; to = Constants.AdminMailEmailName; } else // ToUser { from = Constants.AdminMailEmailName; to = email; } IList <MCommunication_Email> emails = includeEmails ? dbMessage.MessageEmailRequests.Select(r => MCommunication_Email(r.EmailRequest)).ToList() : null; var message = new MCommunication_Message() { MessageId = dbMessage.MessageId, UserId = userId, ConversationId = dbMessage.ConversationId, From = from, To = to, Subject = dbMessage.Subject, Text = dbMessage.Text, SendReceiveCode = dbMessage.SendReceiveCode, CreateDateTimeUtc = dbMessage.CreateDateTimeUtc, AcknowledgementDateTimeUtc = dbMessage.AcknowledgementDateTimeUtc, TopicId = dbMessage.TopicId, TopicReference = dbMessage.Topic?.TopicReference, CanAcknowledge = canAcknowledge, Fields = MCommunication_TopicFields(dbMessage.Topic), Emails = emails, Conversation = conversation }; return(message); }