protected async Task SendRejectEmailAsync(Guid productId, WorkflowProductService.ProductActivityChangedArgs args, String comment) { var product = await ProductRepository.Get() .Where(p => p.Id == productId) .Include(p => p.Project) .ThenInclude(pr => pr.Type) .Include(p => p.Project) .ThenInclude(pr => pr.Organization) .Include(p => p.Project) .ThenInclude(pr => pr.Owner) .Include(p => p.Store) .Include(p => p.ProductDefinition) .FirstOrDefaultAsync(); if (product != null) { var messageParms = new Dictionary <string, object>() { { "projectName", product.Project.Name }, { "productName", product.ProductDefinition.Name }, { "previousState", args.PreviousState }, { "newState", args.CurrentState }, { "comment", comment } }; var sentEmailToOwner = false; var orgAdmins = UserRolesRepository.Get() .Include(ur => ur.User) .Include(ur => ur.Role) .Where(ur => ur.OrganizationId == product.Project.Organization.Id && ur.Role.RoleName == RoleName.OrganizationAdmin) .ToList(); foreach (UserRole orgAdmin in orgAdmins) { if (orgAdmin.UserId == product.Project.OwnerId) { sentEmailToOwner = true; } await SendRejectEmailToUserAsync(orgAdmin.User, messageParms); } if (!sentEmailToOwner) { await SendRejectEmailToUserAsync(product.Project.Owner, messageParms); } } }
public void SendRejectEmail() { BuildTestData(); var sendEmailService = _fixture.GetService <SendEmailService>(); var args = new WorkflowProductService.ProductActivityChangedArgs { PreviousState = "Verify And Publish", CurrentState = "Synchronize Data" }; var comment = "This was rejected because this is a test"; sendEmailService.SendRejectEmail(product1.Id, args, comment); var emails = ReadTestData <AppDbContext, Email>(); Assert.Equal(2, emails.Count); Assert.Equal("{\"Message\":\"<p>The organization administrator has returned Test Project1 to state Synchronize Data from state Verify And Publish with the following comment:<br><br>This was rejected because this is a test</p>\"}", emails[0].ContentModelJson); Assert.Equal("Scriptoria: Test Project1 TestProd1 Returned", emails[0].Subject); Assert.Equal("*****@*****.**", emails[0].To); Assert.Equal("*****@*****.**", emails[1].To); }
public void SendRejectEmail(Guid productId, WorkflowProductService.ProductActivityChangedArgs args, String comment) { SendRejectEmailAsync(productId, args, comment).Wait(); }