public async Task <AMessage_MessageList> GetMessagesAsync(MCommunication_MessageMailbox mailbox, MCommunication_MessageStatus status, int recordCount) { using var log = BeginFunction(nameof(MessageAdminService), nameof(GetMessagesAsync), mailbox, status, recordCount); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var messages = new List <AMessage_Message>(); var mMessages = await CommunicationMicroService.GetMessagesAsync(mailbox, status, recordCount); foreach (var mMessage in mMessages.Messages) { var allowAcknowledge = AllowAcknowledge(mMessage); var message = Create.AMessage_Message(mMessage, allowAcknowledge); messages.Add(message); } var result = new AMessage_MessageList() { Messages = messages }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <MCommunication_MessageList> GetMessagesAsync(MCommunication_MessageMailbox mailbox, MCommunication_MessageStatus status, int recordCount, long?participantId) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(GetMessagesAsync), participantId, mailbox, status, recordCount); try { //AssertIsEndUser(userId); //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var query = (IQueryable <Message>)ctx.Messages; if (participantId != null) { query = query.Where(r => r.ParticipantId == participantId); } switch (mailbox) { case MCommunication_MessageMailbox.ToUser: query = query.Where(r => r.SendReceiveCode == SendReceiveCodes.ToUser); break; case MCommunication_MessageMailbox.FromUser: query = query.Where(r => r.SendReceiveCode == SendReceiveCodes.FromUser); break; case MCommunication_MessageMailbox.MetaAll: // No action required. break; default: throw new ArgumentException($"Unknown mailbox {mailbox}."); } switch (status) { case MCommunication_MessageStatus.Acknowledged: query = query.Where(r => r.AcknowledgementDateTimeUtc != null); break; case MCommunication_MessageStatus.Unacknowledged: query = query.Where(r => r.AcknowledgementDateTimeUtc == null); break; case MCommunication_MessageStatus.MetaAll: // No action required. break; default: throw new ArgumentException($"Unknown status {status}."); } query = query.Take(recordCount); var messages = new List <MCommunication_Message>(); foreach (var dbMessage in await query.ToListAsync().ConfigureAwait(false)) { var canAcknowledge = CanAcknowledge(dbMessage); var message = Create.MCommunication_Message(ctx, dbMessage, canAcknowledge, false, null); messages.Add(message); } var result = new MCommunication_MessageList() { Messages = messages }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public string CreatePagingStateFilter(MCommunication_MessageMailbox mailbox, MCommunication_MessageStatus status, int recordCount) { return($"{mailbox}|{status}|{recordCount}"); }