Пример #1
0
        public async Task AddAccountTosync(String accountId, String locationId, EntityHeader addedBy = null)
        {
            var appUser = await _appUserRepo.FindByIdAsync(accountId);

            var location = await _locationRepo.GetLocationAsync(locationId);

            var locationAccount = new LocationAccount(location.Organization.Id, locationId, accountId)
            {
                AccountName = appUser.Name
            };

            await _locationAccountRepo.AddAccountToLocationAsync(locationAccount);
        }
Пример #2
0
        public async Task CreateNewOrganizationAsync(CreateOrganizationViewModel organizationViewModel, EntityHeader user)
        {
            ValidationCheck(organizationViewModel, Core.Validation.Actions.Create);

            //HACK: Very, small chance, but it does exist...two entries could be added at exact same time and check would fail...need to make progress, can live with rish for now.
            if (await _organizationRepo.QueryNamespaceInUseAsync(organizationViewModel.Namespace))
            {
                throw new ValidationException(Resources.UserManagementResources.Organization_CantCreate, false,
                                              UserManagementResources.Organization_NamespaceInUse.Replace(Tokens.NAMESPACE, organizationViewModel.Namespace));
            }

            var organization = new Organization();

            organization.SetId();
            organization.SetCreationUpdatedFields(user);
            organizationViewModel.MapToOrganization(organization);
            organization.Status           = UserManagementResources.Organization_Status_Active;
            organization.TechnicalContact = user;
            organization.AdminContact     = user;
            organization.BillingContact   = user;

            var location = new OrganizationLocation();

            location.SetId();
            organizationViewModel.MapToOrganizationLocation(location);
            location.SetCreationUpdatedFields(user);
            location.AdminContact     = user;
            location.TechnicalContact = user;
            location.Organization     = organization.ToEntityHeader();

            organization.PrimaryLocation = location.ToEntityHeader();

            if (organization.Locations == null)
            {
                organization.Locations = new List <EntityHeader>();
            }
            organization.Locations.Add(location.ToEntityHeader());

            var currentUser = await _appUserRepo.FindByIdAsync(user.Id);

            var locationUser = new LocationAccount(organization.Id, location.Id, user.Id)
            {
                Email            = currentUser.Email,
                OrganizationName = organization.Name,
                AccountName      = currentUser.Name,
                ProfileImageUrl  = currentUser.ProfileImageUrl.ImageUrl,
                LocationName     = location.Name
            };

            locationUser.SetCreationUpdatedFields(user);

            await _organizationRepo.AddOrganizationAsync(organization);

            await AddAccountToOrgAsync(currentUser.ToEntityHeader(), organization.ToEntityHeader(), currentUser.ToEntityHeader());

            await _locationRepo.AddLocationAsync(location);

            await _locationAccountRepo.AddAccountToLocationAsync(locationUser);

            if (EntityHeader.IsNullOrEmpty(currentUser.CurrentOrganization))
            {
                currentUser.CurrentOrganization = organization.ToEntityHeader();
            }
            if (currentUser.Organizations == null)
            {
                currentUser.Organizations = new List <EntityHeader>();
            }

            currentUser.Organizations.Add(organization.ToEntityHeader());

            await _appUserRepo.UpdateAsync(currentUser);
        }