public async Task <Office365UserModel> CreateOffice365DatabaseUserAsync(Office365UserModel model)
        {
            var user = _userService.GetUser(model.UserPrincipalName);

            if (user == null)
            {
                throw new ArgumentException($"No database user with User Principal Name: {model.UserPrincipalName}");
            }

            var customer = _dbContext.Office365Customers.FirstOrDefault(c => c.CompanyId == user.CompanyId);

            if (customer == null)
            {
                throw new ArgumentException($"No Office 365 Database Customer with Company Id: {user.CompanyId}");
            }

            var createdUser = _dbContext.Office365Users.Add(new Office365User
            {
                Customer          = customer,
                CloudPlusUserId   = user.Id,
                Office365UserId   = model.Office365UserId,
                UserPrincipalName = model.UserPrincipalName,
            });

            await _dbContext.SaveChangesAsync();

            model.Id = createdUser.Id;

            return(model);
        }
        private async Task SendTransitionUserAndLicensesCommand(
            ExecuteContext <ITransitionDispatchCreatingUsersArguments> context, Office365UserModel office365User,
            UserModel user, RoleModel userRole, Office365TransitionProductItemModel item, bool keepLicences)
        {
            var arguments = context.Arguments;

            var isNewLicenses = !(item.Admin || item.RemoveLicenses);

            var userAndLicenseEndpoint = Office365ServiceConstants.QueueOffice365TransitionUserAndLicenseUri;
            var sendEndpoint           = await context.GetSendEndpoint(userAndLicenseEndpoint);

            await sendEndpoint.Send <IOffice365TransitionUserAndLicensesCommand>(new
            {
                arguments.CompanyId,
                arguments.Office365CustomerId,
                CloudPlusUserExist = user != null,
                office365User.UserPrincipalName,
                office365User.Office365UserId,
                office365User.FirstName,
                office365User.LastName,
                office365User.DisplayName,
                KeepLicences = keepLicences,
                UserRoles    = new List <string> {
                    "Company Administrator"
                },
                Roles = new List <int> {
                    userRole.Id
                },
                item.Password,
                item.RecommendedProductItem.CloudPlusProductIdentifier,
                IsNewLicenses = isNewLicenses,
                item.Admin,
            });
        }
        private async Task SendDeletePartnerPlatformUserCommand(
            ExecuteContext <ITransitionDispatchCreatingUsersArguments> context, Office365UserModel office365User)
        {
            var arguments = context.Arguments;

            var deleteUserEndpoint = await context.GetSendEndpoint(Office365ServiceConstants.QueueOffice365UserAssignLicenseUri);

            await deleteUserEndpoint.Send <IOffice365TransitionDeletePartnerPlatformUserCommand>(new
            {
                arguments.Office365CustomerId,
                office365User.Office365UserId
            });
        }
Esempio n. 4
0
        private async void SendUserChangeLicense(ConsumeContext <IOffice365UserMultiEditCommand> context, Office365UserModel office365User)
        {
            var messages = context.Message;

            var assignLicenseEndpoint = await context.GetSendEndpoint(Office365ServiceConstants.Office365UserChangeLicenseUri);

            await assignLicenseEndpoint.Send <IOffice365UserChangeLicenseCommand>(new
            {
                messages.CompanyId,
                office365User.UserPrincipalName,
                RemoveCloudPlusProductIdentifier = office365User.Licenses.FirstOrDefault()?.Office365Offer.CloudPlusProductIdentifier,
                AssignCloudPlusProductIdentifier = messages.CloudPlusProductIdentifier,
                messages.UserRoles
            });
        }