Пример #1
0
        public async Task <Tenant> Handle(CreateTenantCommand message, CancellationToken cancellationToken)
        {
            var tenant = await Tenant.Factory.CreateNewEntry(_repository, message.Name, message.Description);

            await _repository.Add(tenant);

            return(tenant);
        }
        public async Task <Tenant> Handle(CreateTenantCommand message, CancellationToken cancellationToken)
        {
            var tenant = await Tenant.Factory.CreateNewEntry(_repository, message.Name, message.DisplayName, message.Description);

            tenant.CreatedAt = DateTime.Now;
            tenant.CreatedBy = _identityService.GetUserIdentity();
            await _repository.Add(tenant);

            return(tenant);
        }
Пример #3
0
        public Task <CommandResult> Handle(SeedUserCommand command)
        {
            var user = userRepo.Get(command.Email);

            if (user != null)
            {
                return(CommandResult.Success().AsTask());
            }

            var tenant = tenantRepo.Add(new Tenant()
            {
                TenantId = "admin", TenantName = "Admin"
            });

            user = new User()
            {
                Credentials = new Credentials()
                {
                    Email         = command.Email,
                    EmailVerified = DateTime.Now,
                    Password      = hasher.HashPassword(command.Password)
                },
                Profile = new UserProfile()
                {
                    FirstName = "Fin User",
                    LastName  = "Extreme",
                    Address   = new Address()
                },
                Tenants = new List <UserTenant>()
                {
                    new UserTenant()
                    {
                        TenantId       = tenant.TenantId,
                        Federated      = DateTime.Now,
                        FederationCode = "autogenerated",
                        Permissions    = new Dictionary <string, HashSet <string> >()
                        {
                            {
                                appSettings.ApplicationName,
                                new HashSet <string>()
                                {
                                    Permission.AddUsers.ToString(), Permission.DeleteUser.ToString(), Permission.EditUsers.ToString(), Permission.ViewUsers.ToString()
                                }
                            }
                        }
                    }
                },
                Registered      = true,
                ValidationCodes = new List <ValidationCode>()
            };
            userRepo.Add(user);

            return(CommandResult.Success().AsTask());
        }
Пример #4
0
        public async Task <IActionResult> ExecuteAsync(SaveTenant parameter, CancellationToken cancellationToken = default)
        {
            if (parameter.IsDefaultConnection)
            {
                parameter.ConnectionString = host.TenantInfo().ConnectionString;
            }
            else
            {
                if (this.TestConnection(host.TenantInfo(), parameter.ConnectionString) == false)
                {
                    return(new StatusCodeResult(417));//Expectation failed
                }
            }

            var tenant = saveTenantToTenantMapper.Map(parameter);

            tenant = await tenantRepository.Add(tenant, out RepositoryError error, cancellationToken).ConfigureAwait(false);

            if (error == RepositoryError.AlreadyExists)
            {
                return(new ConflictResult());
            }
            if (error != RepositoryError.None)
            {
                return(new StatusCodeResult(500));
            }
            var tenantViewModel = tenantToTenantMapper.Map(tenant);

            if (parameter.IsDefaultConnection == true)
            {
                await bus.Publish <TenantCreated>(new
                {
                    Id           = tenant.Id,
                    CreationTime = tenant.Created.UtcDateTime
                });
            }
            else
            {
                await bus.ScheduleMessage <TenantCreatedNotDefault>(
                    new Uri("loopback://localhost/tenant-created-notdefault"),
                    DateTime.UtcNow.AddSeconds(30),
                    (TenantCreatedNotDefault)(new
                {
                    Id = tenant.Id,
                    CreationTime = tenant.Created.UtcDateTime
                }));
            }

            return(new CreatedAtRouteResult(
                       TenantControllerRoute.GetTenant,
                       new { tenantId = tenantViewModel.Id },
                       tenantViewModel));
        }
Пример #5
0
        /// <summary>
        /// Adds new tenant to the database
        /// </summary>
        /// <param name="tenant">Tenant information to be added. Instance of <see cref="TenantDomain"/></param>
        /// <returns>TenantId of the newly created tenant</returns>
        public int AddTenant(TenantDomain tenant)
        {
            ValidateTenantModel(tenant);
            tenant.Identifier = Guid.NewGuid();
            // Check if identifier exists
            var tenantWithProvidedIdentifier = _tenantRepository.GetByIdentifier(tenant.Identifier);

            if (tenantWithProvidedIdentifier != null)
            {
                throw new NsiArgumentException(MembershipMessages.TenantIdentifierAlreadyExists, Common.Enumerations.SeverityEnum.Warning);
            }

            return(_tenantRepository.Add(tenant));
        }
Пример #6
0
        public async Task <IActionResult> SignUp(Dal.Tenant tenant)
        {
            var state   = Guid.NewGuid().ToString();
            var request = String.Format(_adOptions.SignUpRequestUri,
                                        Uri.EscapeDataString(_adOptions.ClientId),
                                        Uri.EscapeDataString(_adOptions.GraphApiUri),
                                        Uri.EscapeDataString($"{this.Request.Scheme}://{this.Request.Host}/Account/ProcessSignUpCode"),
                                        state,
                                        tenant.AdminConsented ? "admin_consent": "consent");

            tenant.StateMarker = state;

            await _tenantRepository.Add(tenant);

            return(new RedirectResult(request));
        }
Пример #7
0
        public IActionResult Add([FromBody] TenantDto tenant)
        {
            if (tenant == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TenantDto tenantAdded = _tenantRepository.Add(tenant);

            return(Ok(tenantAdded));
        }
Пример #8
0
        public Task <CommandResult> Handle(AddTenantCommand command)
        {
            var existinTenant = tenantRepo.Get(command.Id);

            if (existinTenant != null)
            {
                return(CommandResult.Fail(UserManagementError.TenantCodeAlreadyExists()).AsTask());
            }

            var tenant = tenantRepo.Add(new Entities.Tenant()
            {
                TenantId   = command.Id,
                TenantName = command.Name
            });

            return(CommandResult <string> .Success(tenant.TenantId.ToString()).AsTask());
        }
        /// <summary>
        /// Creates a new <see cref="Tenant"/>, stores it in
        /// its <see cref="ITenantRepository"/> instance, and
        /// publishes a <see cref="TenantProvisioned"/> event,
        /// along with requisite domain events for the creation
        /// of a <see cref="User"/> and <see cref="Role"/>
        /// for default administration of the new tenant.
        /// Refer to remarks for details.
        /// </summary>
        /// <param name="tenantName">
        /// The <see cref="Tenant.Name"/> of the new tenant.
        /// </param>
        /// <param name="tenantDescription">
        /// The <see cref="Tenant.Description"/> of the new tenant.
        /// </param>
        /// <param name="administorName">
        /// The <see cref="Person.Name"/> of the
        /// default administrator for the new tenant.
        /// </param>
        /// <param name="emailAddress">
        /// The <see cref="Person.EmailAddress"/> of the
        /// default administrator for the new tenant.
        /// </param>
        /// <param name="postalAddress">
        /// The <see cref="ContactInformation.PostalAddress"/>
        /// of the default administrator for the new tenant.
        /// </param>
        /// <param name="primaryTelephone">
        /// The <see cref="ContactInformation.PrimaryTelephone"/>
        /// of the default administrator for the new tenant.
        /// </param>
        /// <param name="secondaryTelephone">
        /// The <see cref="ContactInformation.SecondaryTelephone"/>
        /// of the default administrator for the new tenant.
        /// </param>
        /// <returns>
        /// The newly registered <see cref="Tenant"/>,
        /// which has already been added to the internal
        /// <see cref="ITenantRepository"/> instance.
        /// </returns>
        /// <remarks>
        /// <para>
        /// The events published, in order, are:
        /// </para>
        /// <list type="bullet">
        /// <item><description><see cref="UserRegistered"/></description></item>
        /// <item><description><see cref="RoleProvisioned"/></description></item>
        /// <item><description><see cref="UserAssignedToRole"/></description></item>
        /// <item><description><see cref="TenantAdministratorRegistered"/></description></item>
        /// <item><description><see cref="TenantProvisioned"/></description></item>
        /// </list>
        /// </remarks>
        public Tenant ProvisionTenant(
            string tenantName,
            string tenantDescription,
            FullName administorName,
            EmailAddress emailAddress,
            PostalAddress postalAddress,
            Telephone primaryTelephone,
            Telephone secondaryTelephone)
        {
            try
            {
                // must be active to register admin
                Tenant tenant = new Tenant(_tenantRepository.GetNextIdentity(), tenantName, tenantDescription, true);

                // Since this is a new entity, add it to
                // the collection-oriented repository.
                // Subsequent changes to the entity
                // are implicitly persisted.
                _tenantRepository.Add(tenant);

                // Creates user and role entities and stores them
                // in their respective repositories, and publishes
                // domain events UserRegistered, RoleProvisioned,
                // UserAssignedToRole, and TenantAdministratorRegistered.
                RegisterAdministratorFor(
                    tenant,
                    administorName,
                    emailAddress,
                    postalAddress,
                    primaryTelephone,
                    secondaryTelephone);

                DomainEventPublisher
                .Instance
                .Publish(new TenantProvisioned(
                             tenant.TenantId));

                return(tenant);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                          string.Concat("Cannot provision tenant because: ", e.Message), e);
            }
        }
Пример #10
0
        public async Task <IActionResult> CreateTenant([FromBody] TenantResource tenantResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var tenant = await repository.FindTenant(tenantResource);

            if (tenant != null)
            {
                ModelState.AddModelError("Message", "Tenant creation error. Sorry, this tenant already exists!");
                return(BadRequest(ModelState));
            }
            tenant = mapper.Map <TenantResource, Tenant>(tenantResource);
            repository.Add(tenant);
            await unitOfWork.CompleteAsync();

            return(Ok(tenant));
        }
        public async Task <(Tenant, ExceptionKey?)> Add(Tenant tenant, CancellationToken cancelationToken = default(CancellationToken))
        {
            tenant.Name = tenant.DisplayName.Slugify();

            if (await tenantRepository.GetTenantByName(tenant.Name, cancelationToken) != null)
            {
                return(null, ExceptionKey.ERROR_IN_USE);
            }

            tenant.Host = String.Format("{0}.{1}", tenant.Name, configuration["ClientDomain"]);


            tenantRepository.Add(tenant, cancelationToken);

            if (await tenantRepository.Commit(cancelationToken) > 0)
            {
                return(tenant, null);
            }
            else
            {
                return(null, ExceptionKey.ERROR_CREATE);
            }
        }
        public Task Handle(TenantProvisionedIntegrationEvent message)
        {
            Console.WriteLine("Handling TenantProvisionedIntegrationEvent.");
            Tenant tenant = new Tenant(
                message.Id,
                message.Name,
                message.Description
                );

            try
            {
                _tenantRepository.Add(tenant);
                _tenantRepository.SaveChanges();
                Console.WriteLine("TenantProvisionedIntegrationEvent handled.");
                return(Task.CompletedTask);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.InnerException.Message);
                throw e;
            }
        }
Пример #13
0
        public IHttpActionResult PostAddUser(UserDTO userDTO)
        {
            List <Module>  modules  = new List <Module>();
            List <Service> services = new List <Service>();



            foreach (string modulename in userDTO.subscriptiondetail.Modules)
            {
                modules.Add(new Module {
                    ModuleName = modulename,
                });
            }

            foreach (string servicename in userDTO.subscriptiondetail.Services)
            {
                services.Add(new Service
                {
                    ServiceName = servicename
                });
            }


            User user = new User();

            user.Name      = userDTO.basicdetail.Name;
            user.Currency  = userDTO.basicdetail.Currency;
            user.UserRole  = userDTO.basicdetail.UserRole;
            user.WebUrl    = userDTO.basicdetail.WebUrl;
            user.ShortName = userDTO.basicdetail.ShortName;

            user.UserAddress = new List <Address>();
            user.UserAddress = ConvertToAddress(userDTO.basicdetail.address);

            user.Contact = new List <ContactDetail>();
            user.Contact = Convert_ToContactDetail(userDTO.basicdetail.contact);



            user.UserSubscriptionsDetails = new List <Subscription>();
            user.UserSubscriptionsDetails.Add(new Subscription {
                NoNamedUser  = userDTO.subscriptiondetail.NoOfNamedUser,
                Type         = userDTO.subscriptiondetail.Type,
                UserModules  = modules,
                UserServices = services
            });

            user.UserMasterDetails          = new Master();
            user.UserMasterDetails.Modules  = new List <Module>();
            user.UserMasterDetails.Servies  = new List <Service>();
            user.UserMasterDetails.Partners = new List <Partner>();
            user.UserMasterDetails.Partners.Add(new Partner {
                PartnerName = "Aurinpro"
            });

            user.UserMasterDetails.Modules = modules;
            user.UserMasterDetails.Servies = services;



            user.LoginDetails          = new LoginDetail();
            user.LoginDetails.Username = userDTO.logindetail.Username;
            user.LoginDetails.Password = userDTO.logindetail.Password;
            user.LoginDetails.Captcha  = userDTO.logindetail.Captcha;


            return(Ok(_tenantRepo.Add(user)));
        }
Пример #14
0
 public Task AddTenant(ref Tenant tenant)
 {
     return(_tenantRepository.Add(ref tenant));
 }
        public IHttpActionResult PostRegisterUser(UserDTO userDTO)
        {
            User user = new User();

            user.Name      = userDTO.UserDetails.Name;
            user.Role      = "customer";
            user.ShortName = userDTO.UserDetails.ShortName;
            user.Currency  = userDTO.UserDetails.Currency;
            user.WebUrl    = userDTO.UserDetails.WebUrl;

            user.AddressDetail = new List <Address>();

            foreach (var addressDetail in userDTO.UserDetails.AddressDetails)
            {
                user.AddressDetail.Add(new Address
                {
                    Street  = addressDetail.Street,
                    City    = addressDetail.City,
                    State   = addressDetail.State,
                    Country = addressDetail.Country,
                    ZipCode = addressDetail.ZipCode,
                });
            }


            user.ContactDetail = new List <ContactDetail>();

            foreach (var contactDetail in userDTO.UserDetails.ContactDetails)
            {
                user.ContactDetail.Add(new ContactDetail
                {
                    FirstName   = contactDetail.FirstName,
                    LastName    = contactDetail.LastName,
                    PhoneNumber = contactDetail.Mobile,
                    Email       = contactDetail.Email
                });
            }


            user.UserLoginDetails = new LoginDetail
            {
                Username = userDTO.LoginDetails.Username,
                Password = userDTO.LoginDetails.Password,
                Captcha  = userDTO.LoginDetails.Captcha
            };

            Master userMaster = new Master();

            userMaster.ModuleMaster  = new List <Module>();
            userMaster.ServiceMaster = new List <Service>();
            userMaster.PartnerMaster = new List <Partner>();

            foreach (var item in userDTO.SubscriptionDetails.Modules)
            {
                userMaster.ModuleMaster.Add(new Module {
                    Name = item
                });
            }

            foreach (var item in userDTO.SubscriptionDetails.Services)
            {
                userMaster.ServiceMaster.Add(new Service {
                    Name = item
                });
            }

            userMaster.PartnerMaster.Add(new Partner
            {
                Name = "AurionPro"
            });

            user.UserMasterDetails       = userMaster;
            user.UserSubscriptionDetails = new List <Subscription>();

            user.UserSubscriptionDetails.Add(new Subscription {
                Type           = userDTO.SubscriptionDetails.Type,
                NoOfNamedUsers = userDTO.SubscriptionDetails.NoOfNamedUsers,
                UserModules    = userMaster.ModuleMaster,
                UserServices   = userMaster.ServiceMaster
            });

            return(Ok(_tenantRepository.Add(user)));
        }