public async Task <ExecutionResult> Execute(ExecuteContext <IDeletePartnerPlatformUserArguments> context)
        {
            var arguments = context.Arguments;

            var office365User = await _office365DbUserService.GetOffice365DatabaseUserWithLicensesAndOfferAsync(arguments.UserPrincipalName);

            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerWithIncludesAsync(arguments.CompanyId);

            if (office365User == null)
            {
                throw new ArgumentException($"No Office 365 User with User Principal Name: {arguments.UserPrincipalName}");
            }

            if (office365Customer == null)
            {
                throw new ArgumentException($"No Office 365 Customer with Comapny Id: {arguments.CompanyId}");
            }

            await _office365UserService.DeleteOffice365UserAsync(office365User.Office365UserId, office365Customer.Office365CustomerId);

            return(context.CompletedWithVariables(new DeletePartnerPlatformUserLog
            {
                Office365UserId = office365User.Office365UserId,
                Office365CustomerId = office365Customer.Office365CustomerId
            }, new
            {
                office365User.Licenses.FirstOrDefault()?.Office365Offer.CloudPlusProductIdentifier
            }));
        }
        public async Task Consume(ConsumeContext <IOffice365ResendTxtRecordsCommand> context)
        {
            var message           = context.Message;
            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerWithIncludesAsync(message.CompanyId);

            if (office365Customer == null)
            {
                throw new NullReferenceException(nameof(office365Customer));
            }
            // [Kljuco 12/12/2017]: IDK if this is the best way. It feels funny. If someone has better solution PLEASE implement it.
            message.Office365CustomerId = office365Customer.Office365CustomerId;

            await _office365ResendTxtRecordsWorkflowBuilder.Execute(context);
        }
예제 #3
0
        public async Task <ExecutionResult> Execute(ExecuteContext <IPartnerPlatformCustomerSubscriptionArguments> context)
        {
            var arguments = context.Arguments;

            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerWithIncludesAsync(arguments.CompanyId);

            var subscription = office365Customer.Office365Subscriptions
                               .FirstOrDefault(s => s.Office365Offer.CloudPlusProductIdentifier == arguments.CloudPlusProductIdentifier);

            if (subscription == null || string.IsNullOrWhiteSpace(subscription.Office365SubscriptionId))
            {
                // Create or Activate suspended subscription
                var offer = await _office356DbOfferService.GetOffice365OfferAsync(arguments.CloudPlusProductIdentifier);

                var partnerPortalSubscription = await _office365SubscriptionService
                                                .GetPartnerPlatformSubscriptionByOfferAsync(office365Customer.Office365CustomerId, offer.Office365Id);

                if (partnerPortalSubscription == null)
                {
                    subscription = await _office365SubscriptionService.CreatePartnerPlatformSubscriptionAsync(
                        office365Customer.Office365CustomerId, offer.Office365Id);
                }
                else
                {
                    subscription = await _office365SubscriptionService.ActivateSuspendedPartnerPlatformSubscriptionAsync(
                        office365Customer.Office365CustomerId, partnerPortalSubscription.Office365SubscriptionId);
                }
            }
            else
            {
                // Update subscription
                await _office365SubscriptionService.IncreasePartnerPlatformSubscriptionQuantityAsync(
                    office365Customer.Office365CustomerId, subscription.Office365SubscriptionId);
            }

            return(context.CompletedWithVariables(new PartnerPlatformCustomerSubscriptionLog
            {
                Office365CustomerId = office365Customer.Office365CustomerId,
                Office365SubscriptionId = subscription.Office365SubscriptionId,
                Quantity = subscription.Quantity
            }, new
            {
                subscription.Office365SubscriptionId,
                subscription.Office365OrderId,
                subscription.Office365FriendlyName,
                subscription.Quantity,
                office365Customer.Office365CustomerId
            }));
        }
예제 #4
0
        public async Task <ExecutionResult> Execute(ExecuteContext <ICreatePartnerPlatformUserArguments> context)
        {
            var arguments = context.Arguments;

            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerWithIncludesAsync(arguments.CompanyId);

            if (office365Customer == null)
            {
                throw new ArgumentException($"No Office 365 Customer in database with Comapny Id: {arguments.CompanyId}");
            }

            string office365UserId = null;

            var existingOffice365UserId = await _office365UserService.GetOffice365UserIdAsync(arguments.UserPrincipalName,
                                                                                              office365Customer.Office365CustomerId);

            if (existingOffice365UserId == null)
            {
                office365UserId = await _office365ApiService.CreateOffice365UserAsync(new Office365ApiUserModel
                {
                    Office365CustomerId = office365Customer.Office365CustomerId,
                    UserPrincipalName   = arguments.UserPrincipalName,
                    DisplayName         = arguments.DisplayName,
                    FirstName           = arguments.FirstName,
                    LastName            = arguments.LastName,
                    UsageLocation       = arguments.UsageLocation,
                    City          = arguments.City,
                    Country       = arguments.Country,
                    PhoneNumber   = arguments.PhoneNumber,
                    PostalCode    = arguments.PostalCode,
                    State         = arguments.State,
                    StreetAddress = arguments.StreetAddress,
                    Password      = arguments.Password
                });
            }
            return(context.CompletedWithVariables(new CreatePartnerPlatformUserLog
            {
                Office365CustomerId = office365Customer.Office365CustomerId,
                UserPrincipalName = arguments.UserPrincipalName
            }, new
            {
                office365Customer.Office365CustomerId,
                Office365UserId = office365UserId ?? existingOffice365UserId
            }));
        }
예제 #5
0
        public async Task <IHttpActionResult> VerifyCustomerDomain(string domainName)
        {
            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerWithIncludesAsync(User.CompanyId());

            if (office365Customer == null)
            {
                throw new NullReferenceException(nameof(office365Customer));
            }

            var verifyDomainUri = Office365ServiceConstants.QueueOffice365DomainVerification;

            await _messageBroker.GetSendEndpoint(verifyDomainUri)
            .Send <IOffice365VerifyDomainCommand>(new
            {
                DomainName = domainName,
                office365Customer.Office365CustomerId
            });

            return(Ok());
        }
        public async Task <ExecutionResult> Execute(ExecuteContext <IRestorePartnerPlatformUserArguments> context)
        {
            var arguments = context.Arguments;

            var office365User = await _office365DbUserService.GetOffice365DatabaseUserAsync(arguments.UserPrincipalName);

            if (office365User == null)
            {
                throw new Exception($"No Office365 user with upn {arguments.UserPrincipalName}");
            }
            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerWithIncludesAsync(arguments.CompanyId);

            await _office365UserService.RestoreOffice365UserAsync(office365User.Office365UserId, office365Customer.Office365CustomerId);

            return(context.Completed(new RestorePartnerPlatformUserLog
            {
                Office365UserId = office365User.Office365UserId,
                Office365CustomerId = office365Customer.Office365CustomerId
            }));
        }
        public async Task <ExecutionResult> Execute(ExecuteContext <IDecreasePartnerPlatformCustomerSubscriptionArguments> context)
        {
            var arguments = context.Arguments;

            var office365Customer = await _office365DbCustomerService.GetOffice365CustomerWithIncludesAsync(arguments.CompanyId);

            var subscription = office365Customer.Office365Subscriptions
                               .FirstOrDefault(s => s.Office365Offer.CloudPlusProductIdentifier == arguments.CloudPlusProductIdentifier);

            if (subscription == null)
            {
                throw new ArgumentException($"Could not find subscription for product identifier: {arguments.CloudPlusProductIdentifier}");
            }

            if (subscription.Quantity == 1)
            {
                await _office365SubscriptionService.SuspendPartnerPlatformSubscriptionAsync(office365Customer.Office365CustomerId,
                                                                                            subscription.Office365SubscriptionId);
            }
            else
            {
                await _office365SubscriptionService.DecreasePartnerPlatformSubscriptionQuantityAsync(
                    office365Customer.Office365CustomerId, subscription.Office365SubscriptionId);
            }

            return(context.CompletedWithVariables(new DecreasePartnerPlatformCustomerSubscriptionLog
            {
                Office365CustomerId = office365Customer.Office365CustomerId,
                Office365SubscriptionId = subscription.Office365SubscriptionId,
                Quantity = subscription.Quantity
            }, new
            {
                office365Customer.Office365CustomerId,
                subscription.Office365SubscriptionId
            }));
        }
        public async Task Consume(ConsumeContext <IOffice365TransitionReportCommand> context)
        {
            var message = context.Message;

            var transitionStarted    = _workflowService.IsOffice365TransitionStarted(message.CompanyId);
            var transitionInProgress = _workflowService.IsOffice365TransitionInProgress(message.CompanyId);

            if (!transitionStarted || transitionInProgress)
            {
#pragma warning disable 4014
                context.Redeliver(TimeSpan.FromSeconds(30));
#pragma warning restore 4014
                return;
            }

            var report       = new Office365TransitionReportModel();
            var deletedUsers = new List <string>();
            var adminUsers   = new List <string>();
            var licenseUsers = new List <string>();

            foreach (var item in message.ProductItems)
            {
                if (item.Delete)
                {
                    transitionInProgress =
                        _workflowService.IsOffice365TransitionDeletePartnerPlatformUserInProgress(
                            item.UserPrincipalName);

                    if (transitionInProgress)
                    {
#pragma warning disable 4014
                        context.Redeliver(TimeSpan.FromSeconds(30));
#pragma warning restore 4014
                        return;
                    }

                    deletedUsers.Add(item.UserPrincipalName);
                }
                else if (item.KeepLicenses)
                {
                    report.KeepLicensesUsers.Add(item.UserPrincipalName);
                }
                else
                {
                    transitionInProgress =
                        _workflowService.IsOffice365TransitionUserAndLicensesInProgress(item.UserPrincipalName);

                    if (transitionInProgress)
                    {
#pragma warning disable 4014
                        context.Redeliver(TimeSpan.FromSeconds(30));
#pragma warning restore 4014
                        return;
                    }

                    if (item.Admin)
                    {
                        adminUsers.Add(item.UserPrincipalName);
                    }
                    else
                    {
                        licenseUsers.Add(item.UserPrincipalName);
                    }
                }
            }

            foreach (var user in deletedUsers)
            {
                var status = _workflowService.Office365TransitionDeletePartnerPlatformUserStatus(user);

                if (status == WorkflowActivityStatus.ActivityCompleted)
                {
                    report.DeletedUsersSucceed.Add(user);
                }
                else
                {
                    report.DeletedUsersFailed.Add(user);
                }
            }

            foreach (var user in adminUsers)
            {
                var status = _workflowService.Office365TransitionUserAndLicensesStatus(user);

                if (status == WorkflowActivityStatus.ActivityCompleted)
                {
                    report.AdminUsersSucceed.Add(user);
                }
                else
                {
                    report.AdminUsersFailed.Add(user);
                }
            }

            foreach (var user in licenseUsers)
            {
                var status = _workflowService.Office365TransitionUserAndLicensesStatus(user);

                if (status == WorkflowActivityStatus.ActivityCompleted)
                {
                    report.LicenseUsersSucceed.Add(user);
                }
                else
                {
                    report.LicenseUsersFailed.Add(user);
                }
            }

            var office365Customer =
                await _office365DbCustomerService.GetOffice365CustomerWithIncludesAsync(message.CompanyId);

            report.Domains = office365Customer.Domains.Select(d => d.Name).ToList();
            var productItems = _productItemService.GetProductItems().ToList();

            foreach (var subscription in office365Customer.Office365Subscriptions)
            {
                var productItem = productItems.FirstOrDefault(i =>
                                                              i.Identifier == subscription.Office365Offer.CloudPlusProductIdentifier);

                report.Subscriptions.Add(new Office365TransitionSubscriptionReportModel
                {
                    Name     = productItem?.Name,
                    Quantity = subscription.Quantity
                });
            }

            var recipients = new List <string> {
                _office365ServiceSettings.CloudPlusEngineeringEmail
            };

            await context.Send <ISendEmailCommand>(NotificationServiceConstants.SendEmailNotificationUri, new
            {
                message.CompanyId,
                To                = _office365ServiceSettings.CloudPlusSupportEmail,
                Recipients        = recipients,
                EmailTemplateType = EmailTemplateType.Office365TransitionReport,
                Report            = report
            });
        }