public async Task <MCommunication_Notification> GetNotificationAsync(long notificationId) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(GetNotificationAsync), notificationId); try { //AssertIsEndUser(userId); //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var dbNotification = await ctx.Notifications .Include(r => r.NotificationEmailRequests) .ThenInclude(r => r.EmailRequest) .Where(r => r.NotificationId == notificationId) .FirstAsync().ConfigureAwait(false); var notification = Create.MCommunication_Notification(dbNotification, true); var result = notification; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <long> AllocateOwnerAsync(string ownerReference) { using var log = BeginFunction(nameof(ProjectMicroService), nameof(AllocateOwnerAsync), ownerReference); try { using var ctx = QuiltContextFactory.Create(); var dbOwner = await ctx.Owners.Where(r => r.OwnerReference == ownerReference).SingleOrDefaultAsync().ConfigureAwait(false); if (dbOwner == null) { dbOwner = new Owner() { OwnerReference = ownerReference, OwnerTypeCode = "A" }; _ = ctx.Owners.Add(dbOwner); _ = await ctx.SaveChangesAsync().ConfigureAwait(false); } var result = dbOwner.OwnerId; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task AcknowledgeAlertAsync(long alertId) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(AcknowledgeAlertAsync), alertId); try { //AssertIsEndUser(userId); //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var dbAlert = await ctx.Alerts.Where(r => r.AlertId == alertId).SingleAsync().ConfigureAwait(false); if (dbAlert.AcknowledgementDateTimeUtc == null) { dbAlert.AcknowledgementDateTimeUtc = GetUtcNow(); } _ = await ctx.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <IReadOnlyList <MDomain_LedgerAccountType> > GetLedgerAccountTypesAsync() { using var log = BeginFunction(nameof(DomainMicroService), nameof(GetLedgerAccountTypesAsync)); try { using var ctx = QuiltContextFactory.Create(); var entries = new List <MDomain_LedgerAccountType>(); foreach (var dbLedgerAccount in await ctx.LedgerAccounts.ToListAsync()) { var entry = new MDomain_LedgerAccountType() { LedgerAccountNumber = dbLedgerAccount.LedgerAccountNumber, Name = dbLedgerAccount.Name, DebitCreditCode = dbLedgerAccount.DebitCreditCode }; entries.Add(entry); } var result = entries; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <MDesign_BlockCollection> GetBlockCollectionAsync(int previewSize) { using var log = BeginFunction(nameof(DesignMicroService), nameof(GetBlockCollectionAsync)); try { using var ctx = QuiltContextFactory.Create(); var allTags = await ctx.Tags.Where(r => r.TagTypeCode == TagTypeCodes.Block).OrderBy(r => r.Value).Select(r => r.Value).ToArrayAsync().ConfigureAwait(false); var blockList = new List <MDesign_Block>(); var provider = new DatabaseBlockComponentProvider(QuiltContextFactory); foreach (var entry in provider.GetComponents(BlockComponent.TypeName, Constants.DefaultComponentCategory).OrderBy(r => r.Category).ThenBy(r => r.Name)) { var blockComponent = (BlockComponent)entry.Component; var data = Create.MDesign_Block(blockComponent, entry.Tags, previewSize); blockList.Add(data); } var result = new MDesign_BlockCollection() { Blocks = blockList, AllTags = allTags }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <bool> DeleteDesignAsync(Guid designId, DateTime utcNow) { using var log = BeginFunction(nameof(DesignMicroService), nameof(DeleteDesignAsync), designId, utcNow); try { using var ctx = QuiltContextFactory.Create(); var dbDesign = await ctx.Designs.Where(r => r.DesignId == designId).SingleOrDefaultAsync().ConfigureAwait(false); if (dbDesign == null) { return(false); } //var ownerUserId = ParseUserId.FromOwnerReference(dbDesign.Owner.OwnerReference); //if (!SecurityPolicy.IsAuthorized(userId, ownerUserId)) //{ // return false; //} dbDesign.DeleteDateTimeUtc = utcNow; _ = await ctx.SaveChangesAsync().ConfigureAwait(false); var result = true; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <bool> HasDeletedDesignsAsync(long ownerId) { using var log = BeginFunction(nameof(DesignMicroService), nameof(HasDeletedDesignsAsync), ownerId); try { //if (SecurityPolicy.IsBuiltInUser(userId)) //{ // throw new InvalidOperationException("Built-in user ID not supported."); //} using var ctx = QuiltContextFactory.Create(); //var ownerReference = CreateOwnerReference.FromUserId(userId); var result = await ctx.Designs.AnyAsync(r => r.OwnerId == ownerId && r.DeleteDateTimeUtc != null).ConfigureAwait(false); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <MDesign_Design> GetDesignAsync(Guid designId) { using var log = BeginFunction(nameof(DesignMicroService), nameof(GetDesignAsync), designId); try { using var ctx = QuiltContextFactory.Create(); var dbDesign = await ctx.Designs.Where(r => r.DesignId == designId).SingleOrDefaultAsync().ConfigureAwait(false); if (dbDesign == null) { return(null); } //var ownerUserId = ParseUserId.FromOwnerReference(dbDesign.Owner.OwnerReference); //if (!SecurityPolicy.IsAuthorized(userId, ownerUserId)) //{ // return null; //} var dbDesignSnapshot = dbDesign.DesignSnapshots.Where(r => r.DesignSnapshotSequence == dbDesign.CurrentDesignSnapshotSequence).Single(); var result = Create.MDesign_Design(dbDesignSnapshot); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public IEnumerable <MDomain_WebsiteValue> GetWebsiteValues() { using var log = BeginFunction(nameof(DomainMicroService), nameof(GetWebsiteValues)); try { using var ctx = QuiltContextFactory.Create(); var result = new List <MDomain_WebsiteValue>(); foreach (var dbWebsiteProperty in ctx.WebsiteProperties) { result.Add(new MDomain_WebsiteValue() { PropertyName = dbWebsiteProperty.PropertyName, PropertyValue = dbWebsiteProperty.PropertyValue }); } log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <IReadOnlyList <MProject_Project> > GetProjectsAsync(long?ownerId, int?skip, int?take) { var projects = new List <MProject_Project>(); using var ctx = QuiltContextFactory.Create(); var dbProjects = ctx.Projects.Where(r => r.DeleteDateTimeUtc == null); if (ownerId.HasValue) { dbProjects = dbProjects.Where(r => r.OwnerId == ownerId.Value); } dbProjects = dbProjects.OrderByDescending(r => r.UpdateDateTimeUtc); if (skip.HasValue) { dbProjects = dbProjects.Skip(skip.Value); } if (take.HasValue) { dbProjects = dbProjects.Take(take.Value); } var dbProjectList = await dbProjects.ToListAsync().ConfigureAwait(false); foreach (var dbProject in dbProjectList) { var dbProjectSnapshot = dbProject.ProjectSnapshots.Where(r => r.ProjectSnapshotSequence == dbProject.CurrentProjectSnapshotSequence).Single(); var project = Create.MProject_Project(dbProjectSnapshot); projects.Add(project); } return(projects); }
public async Task <bool> RenameProjectAsync(Guid projectId, string name) { using var ctx = QuiltContextFactory.Create(); var dbProject = await ctx.Projects.Where(r => r.ProjectId == projectId).SingleOrDefaultAsync().ConfigureAwait(false); if (dbProject == null) { return(false); } //var ownerUserId = ParseUserId.FromOwnerReference(dbProject.Owner.OwnerReference); //if (!SecurityPolicy.IsAuthorized(userId, ownerUserId)) //{ // return false; //} var dbProjectSnapshot = dbProject.ProjectSnapshots.Where(r => r.ProjectSnapshotSequence == dbProject.CurrentProjectSnapshotSequence).Single(); dbProject.Name = name; dbProjectSnapshot.Name = name; _ = await ctx.SaveChangesAsync().ConfigureAwait(false); return(true); }
public async Task <Guid?> UndeleteProjectAsync(long ownerId, DateTime utcNow) { //if (SecurityPolicy.IsBuiltInUser(userId)) //{ // throw new InvalidOperationException("Built-in user ID not supported."); //} using var ctx = QuiltContextFactory.Create(); var dbProject = await(from p in ctx.Projects where p.DeleteDateTimeUtc != null && p.OwnerId == ownerId orderby p.DeleteDateTimeUtc descending select p).FirstOrDefaultAsync().ConfigureAwait(false); if (dbProject != null) { dbProject.DeleteDateTimeUtc = null; _ = await ctx.SaveChangesAsync().ConfigureAwait(false); return(dbProject.ProjectId); } return(null); }
public async Task <MUser_User> GetUserAsync(string userId) { using var log = BeginFunction(nameof(UserMicroService), nameof(GetUserAsync), userId); try { //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var dbAspNetUser = await ctx.AspNetUsers.Where(r => r.Id == userId).SingleOrDefaultAsync().ConfigureAwait(false); if (dbAspNetUser == null) { log.Result(null); return(null); } var result = Create.MUser_User(dbAspNetUser); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task AcknowledgeNotificationsAsync(long?participantId) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(AcknowledgeNotificationsAsync), participantId); try { //AssertIsEndUser(userId); //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var query = ctx.Notifications.Where(r => r.AcknowledgementDateTimeUtc == null); if (participantId != null) { query = query.Where(r => r.ParticipantId == participantId.Value); } var dbNotifications = await query.ToListAsync().ConfigureAwait(false); foreach (var dbNotification in dbNotifications) { dbNotification.AcknowledgementDateTimeUtc = GetUtcNow(); } _ = await ctx.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <long> CreateAlert(Exception exception, long?participantId = null, long?topicId = null) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(CreateAlert), exception, topicId); try { var utcNow = GetUtcNow(); using var ctx = QuiltContextFactory.Create(); var dbAlert = new Alert() { AlertTypeCode = AlertTypeCodes.OperationException, CreateDateTimeUtc = utcNow, Description = "Operation Exception", Exception = exception.GetDetail(), ParticipantId = participantId, TopicId = topicId }; _ = ctx.Alerts.Add(dbAlert); var dbAlertType = ctx.AlertTypes.Find(dbAlert.AlertTypeCode); var formatter = new AlertEmailFormatter(dbAlertType.Name); var dbEmailRequest = new EmailRequest() { EmailRequestStatusCode = EmailRequestStatusCodes.Posted, SenderEmail = Constants.DoNotReplyEmail, SenderEmailName = Constants.DoNotReplyEmailName, RecipientEmail = Constants.AdminMailEmail, RecipientEmailName = Constants.AdminMailEmailName, RecipientParticipantId = null, Subject = formatter.GetSubject(), BodyText = formatter.GetText(), BodyHtml = formatter.GetHtml(), BodyTypeCode = EmailBodyTypes.Alert, CreateDateTimeUtc = utcNow, EmailRequestStatusDateTimeUtc = utcNow, }; _ = ctx.EmailRequests.Add(dbEmailRequest); var dbAlertEmailRequest = new AlertEmailRequest() { Alert = dbAlert, EmailRequest = dbEmailRequest, }; _ = ctx.AlertEmailRequests.Add(dbAlertEmailRequest); _ = await ctx.SaveChangesAsync().ConfigureAwait(false); return(dbAlert.AlertId); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <AUser_User> GetUserAsync(string userId) { using var log = BeginFunction(nameof(UserAdminService), nameof(GetUserAsync), userId); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var dbAspNetUser = await ctx.AspNetUsers .Include(r => r.AspNetUserRoles) .ThenInclude(r => r.Role) .Include(r => r.AspNetUserLogins) .Where(r => r.Id == userId) .FirstOrDefaultAsync().ConfigureAwait(false); if (dbAspNetUser == null) { log.Result(null); return(null); } var squareCustomerReference = CreateSquareCustomerReference.FromUserId(userId); var squareCustomerId = await SquareMicroService.LookupSquareCustomerIdAsync(squareCustomerReference).ConfigureAwait(false); var mSquareCustomerSummaryList = squareCustomerId != null ? await SquareMicroService.GetSquareCustomerSummariesAsync(squareCustomerId.Value, null).ConfigureAwait(false) : null; var mSquarePaymentSummaryList = squareCustomerId != null ? await SquareMicroService.GetSquarePaymentSummariesAsync(squareCustomerId, null, null).ConfigureAwait(false) : null; var ordererReference = CreateOrdererReference.FromUserId(userId); var ordererId = await OrderMicroService.LookupOrdererAsync(ordererReference).ConfigureAwait(false); var mOrderSummaryList = ordererId != null ? await OrderMicroService.GetOrderSummariesAsync(null, null, MOrder_OrderStatus.MetaAll, ordererId, null).ConfigureAwait(false) : null; var result = Create.AUser_User( dbAspNetUser, mOrderSummaryList, mSquareCustomerSummaryList?.Summaries.FirstOrDefault(), mSquarePaymentSummaryList); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public IEnumerable <MDomain_ValueData> GetDomainValues(string domain) { using var log = BeginFunction(nameof(DomainMicroService), nameof(GetDomainValues), domain); try { switch (domain) { case s_shippingVendorDomain: { var result = new List <MDomain_ValueData>(); using (var ctx = QuiltContextFactory.Create()) { foreach (var dbShippingVendor in ctx.ShippingVendors.OrderBy(r => r.Name)) { result.Add(new MDomain_ValueData() { Id = dbShippingVendor.ShippingVendorId.ToString(), Value = dbShippingVendor.Name }); } } log.Result(result); return(result); } case s_stateDomain: { var result = new List <MDomain_ValueData>(); using (var ctx = QuiltContextFactory.Create()) { foreach (var dbState in ctx.States.OrderBy(r => r.Name)) { result.Add(new MDomain_ValueData() { Id = dbState.StateCode, Value = dbState.Name }); } } log.Result(result); return(result); } } throw new InvalidOperationException(string.Format("Unknown domain value {0}", domain)); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <Guid> UpdateDesignAsync(Guid designId, MDesign_DesignSpecification designSpecification, DateTime utcNow) { using var log = BeginFunction(nameof(DesignMicroService), nameof(UpdateDesignAsync), designId, designSpecification, utcNow); try { using var ctx = QuiltContextFactory.Create(); //ctx.Database.Log = message => Trace.WriteLine(message); var dbDesign = await ctx.Designs.SingleAsync(p => p.DesignId == designId).ConfigureAwait(false); //var ownerUserId = ParseUserId.FromOwnerReference(dbDesign.Owner.OwnerReference); //if (!SecurityPolicy.IsAuthorized(userId, ownerUserId)) //{ // throw new InvalidOperationException("Design has different owner."); //} dbDesign.CurrentDesignSnapshotSequence += 1; dbDesign.UpdateDateTimeUtc = utcNow; var dbArtifact = new Artifact() { ArtifactTypeCode = ArtifactTypeCodes.Design, ArtifactValueTypeCode = ArtifactValueTypeCodes.Json, Value = designSpecification.ArtifactValue }; _ = ctx.Artifacts.Add(dbArtifact); var dbDesignSnapshot = new DesignSnapshot() { Design = dbDesign, Artifact = dbArtifact, Name = dbDesign.Name, DesignSnapshotSequence = dbDesign.CurrentDesignSnapshotSequence, CreateDateTimeUtc = utcNow, UpdateDateTimeUtc = utcNow }; _ = ctx.DesignSnapshots.Add(dbDesignSnapshot); _ = await ctx.SaveChangesAsync().ConfigureAwait(false); var result = designId; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public void HasUsers() { //var serviceProvider = (ServiceProvider)TestContext.Properties["SERVICES"]; //var quiltContextFactory = serviceProvider.GetService<IQuiltContextFactory>(); using var ctx = QuiltContextFactory.Create(); var count = ctx.AspNetUsers.Count(); TestContext.WriteLine("{0} records found.", count); Assert.AreNotEqual(count, 0); }
public async Task <bool> HasDeletedProjectsAsync(long ownerId) { //if (SecurityPolicy.IsBuiltInUser(userId)) //{ // throw new InvalidOperationException("Built-in user ID not supported."); //} using var ctx = QuiltContextFactory.Create(); var result = await ctx.Projects.AnyAsync(r => r.OwnerId == ownerId && r.DeleteDateTimeUtc != null).ConfigureAwait(false); return(result); }
public async Task <MProject_Project> GetProjectAsync(long projectSnapshotId) { using var ctx = QuiltContextFactory.Create(); var mProject = await ctx.ProjectSnapshots .Include(r => r.Artifact) .Include(r => r.DesignSnapshot) .ThenInclude(r => r.Artifact) .Include(r => r.ProjectSnapshotComponents) .Where(r => r.ProjectSnapshotId == projectSnapshotId) .Select(r => Create.MProject_Project(r)) .SingleOrDefaultAsync().ConfigureAwait(false); return(mProject); }
public async Task <MCommunication_NotificationList> GetNotificationsAsync(int recordCount, bool?acknowledged, long?participantId) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(GetNotificationsAsync), participantId, acknowledged, recordCount); try { //AssertIsEndUser(userId); //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var query = (IQueryable <Notification>)ctx.Notifications; if (participantId != null) { query = query.Where(r => r.ParticipantId == participantId.Value); } if (acknowledged != null) { query = acknowledged.Value ? query.Where(r => r.AcknowledgementDateTimeUtc != null) : query.Where(r => r.AcknowledgementDateTimeUtc == null); } query = query.Take(recordCount); var notifications = new List <MCommunication_Notification>(); foreach (var dbNotification in await query.ToListAsync().ConfigureAwait(false)) { var notification = Create.MCommunication_Notification(dbNotification, false); notifications.Add(notification); } var result = new MCommunication_NotificationList() { Notifications = notifications }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task UpdateShippingAddressAsync(string userId, MUser_UpdateShippingAddress shippingAddress) { using var log = BeginFunction(nameof(UserMicroService), nameof(UpdateShippingAddressAsync), userId, shippingAddress); try { //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var dbUserProfile = ctx.GetUserProfile(userId); var dbUserAddress = dbUserProfile.UserAddresses.Where(r => r.AddressTypeCode == AddressTypeCodes.Shipping).SingleOrDefault(); if (shippingAddress != null) { if (dbUserAddress == null) { dbUserAddress = new UserAddress() { UserProfile = dbUserProfile, AddressTypeCodeNavigation = ctx.AddressType(AddressTypeCodes.Shipping) }; _ = ctx.UserAddresses.Add(dbUserAddress); } dbUserAddress.AddressLine1 = shippingAddress.AddressLine1; dbUserAddress.AddressLine2 = shippingAddress.AddressLine2; dbUserAddress.City = shippingAddress.City; dbUserAddress.StateCode = shippingAddress.StateCode; dbUserAddress.PostalCode = shippingAddress.PostalCode; dbUserAddress.CountryCode = shippingAddress.CountryCode; } else { if (dbUserAddress != null) { _ = ctx.UserAddresses.Remove(dbUserAddress); } } _ = await ctx.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <MUser_UserSummaryList> GetUserSummariesAsync(string userName, string role, int?recordCount) { using var log = BeginFunction(nameof(UserMicroService), nameof(GetUserSummariesAsync), userName, role, recordCount); try { using var ctx = QuiltContextFactory.Create(); IQueryable <AspNetUser> query = ctx.AspNetUsers; if (!string.IsNullOrEmpty(userName)) { query = query.Where(r => r.NormalizedUserName.Contains(userName)); } if (!string.IsNullOrEmpty(role)) { query = query.Where(r => r.AspNetUserRoles.Any(r => r.Role.NormalizedName == role)); } if (recordCount != null) { query = query.Take(recordCount.Value); } var dbUsers = await query.ToListAsync().ConfigureAwait(false); var aSummaries = new List <MUser_UserSummary>(); foreach (var dbUser in dbUsers) { var MUser = Create.MUser_UserSummary(dbUser); aSummaries.Add(MUser); } var result = new MUser_UserSummaryList() { Summaries = aSummaries }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
private static void CreateNewDatabase(IConfiguration configuration) { var options = new DatabaseOptions(); configuration.GetSection(ConfigurationSectionNames.Application).Bind(options); var databaseName = string.Format("Quilt-{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now); options.LocalDatabaseName = databaseName; var fileName = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\SQL\\{options.LocalDatabaseName}.mdf"; options.LocalConnectionString = $"Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog={options.LocalDatabaseName};AttachDbFilename={fileName};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; var quiltContextFactory = QuiltContextFactory.Create(configuration, options); ModelSetup.CreateDatabase(quiltContextFactory); }
public async Task <IReadOnlyList <MDesign_Design> > GetDesignsAsync(long?ownerId, int?skip, int?take) { using var log = BeginFunction(nameof(DesignMicroService), nameof(GetDesignsAsync), ownerId, skip, take); try { using var ctx = QuiltContextFactory.Create(); var dbDesigns = ctx.Designs.Where(r => r.DeleteDateTimeUtc == null); if (ownerId.HasValue) { dbDesigns = dbDesigns.Where(r => r.OwnerId == ownerId.Value); } dbDesigns = dbDesigns.OrderByDescending(r => r.UpdateDateTimeUtc); if (skip.HasValue) { dbDesigns = dbDesigns.Skip(skip.Value); } if (take.HasValue) { dbDesigns = dbDesigns.Take(take.Value); } var dbDesignList = await dbDesigns.ToListAsync().ConfigureAwait(false); var designs = new List <MDesign_Design>(); foreach (var dbDesign in dbDesignList) { var dbDesignSnapshot = dbDesign.DesignSnapshots.Where(r => r.DesignSnapshotSequence == dbDesign.CurrentDesignSnapshotSequence).Single(); var design = Create.MDesign_Design(dbDesignSnapshot); designs.Add(design); } var result = designs; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <Guid?> UndeleteDesignAsync(long ownerId) { using var log = BeginFunction(nameof(DesignMicroService), nameof(UndeleteDesignAsync), ownerId); try { //if (SecurityPolicy.IsBuiltInUser(userId)) //{ // throw new InvalidOperationException("Built-in user ID not supported."); //} using var ctx = QuiltContextFactory.Create(); //var ownerReference = CreateOwnerReference.FromUserId(userId); var dbDesign = await(from p in ctx.Designs where p.DeleteDateTimeUtc != null && p.OwnerId == ownerId orderby p.DeleteDateTimeUtc descending select p).FirstOrDefaultAsync().ConfigureAwait(false); Guid?deletedDesignId; if (dbDesign != null) { dbDesign.DeleteDateTimeUtc = null; _ = await ctx.SaveChangesAsync().ConfigureAwait(false); deletedDesignId = dbDesign.DesignId; } else { deletedDesignId = null; } var result = deletedDesignId; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task AcknowledgeAlertsAsync() { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(AcknowledgeAlertsAsync)); try { var utcNow = GetUtcNow(); using var ctx = QuiltContextFactory.Create(); await ctx.Alerts.Where(r => r.AcknowledgementDateTimeUtc == null).ForEachAsync(r => r.AcknowledgementDateTimeUtc = utcNow).ConfigureAwait(false); _ = await ctx.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <MCommunication_Message> GetMessageAsync(long messageId, bool acknowledge, long?participantId) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(GetMessageAsync), participantId, messageId, acknowledge); try { //AssertIsEndUser(userId); //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var query = ctx.Messages.Where(r => r.MessageId == messageId); if (participantId != null) { query = query.Where(r => r.ParticipantId == participantId.Value); } var dbMessage = await query.SingleAsync().ConfigureAwait(false); if (acknowledge && dbMessage.SendReceiveCode == SendReceiveCodes.ToUser && dbMessage.AcknowledgementDateTimeUtc == null) { dbMessage.AcknowledgementDateTimeUtc = GetUtcNow(); _ = await ctx.SaveChangesAsync().ConfigureAwait(false); } var conversation = new List <MCommunication_Message>(); foreach (var dbRelatedMessage in await ctx.Messages.Where(r => r.ConversationId == dbMessage.ConversationId).OrderBy(r => r.CreateDateTimeUtc).ToListAsync().ConfigureAwait(false)) { conversation.Add(Create.MCommunication_Message(ctx, dbRelatedMessage, CanAcknowledge(dbRelatedMessage), false, null)); } var result = Create.MCommunication_Message(ctx, dbMessage, CanAcknowledge(dbMessage), true, conversation); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <MCommunication_AlertList> GetAlertsAsync(int recordCount, bool?acknowledged) { using var log = BeginFunction(nameof(CommunicationMicroService), nameof(GetAlertsAsync), acknowledged, recordCount); try { //AssertIsEndUser(userId); //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); using var ctx = QuiltContextFactory.Create(); var query = (IQueryable <Alert>)ctx.Alerts; if (acknowledged != null) { query = acknowledged.Value ? query.Where(r => r.AcknowledgementDateTimeUtc != null) : query.Where(r => r.AcknowledgementDateTimeUtc == null); } query = query.Take(recordCount); var alerts = new List <MCommunication_Alert>(); foreach (var dbAlert in await query.ToListAsync().ConfigureAwait(false)) { var alert = Create.MCommunication_Alert(dbAlert); alerts.Add(alert); } var result = new MCommunication_AlertList() { Alerts = alerts }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }