public void EnsureOrganisationName()
            {
                Organisation org = new Organisation
                    {
                        Id = "new-org",
                        ParentOrganisationId = "12345"
                    };

                this.Manager.SaveOrganisation(org, "Administrator");
            }
            public void EnsureNonBlankMetadataKey()
            {
                Organisation org = new Organisation
                {
                    Id = "new-org",
                    Name = "Test",
                    ParentOrganisationId = "12345",
                    ExtendedProperties = new ExtendedProperties { { string.Empty, "Test" } }
                };

                this.Manager.SaveOrganisation(org, "Administrator");
            }
        /// <summary>
        /// Saves the organisation.
        /// </summary>
        /// <param name="organisation">The organisation to save.</param>
        /// <returns>The saved organisation.</returns>
        protected override Organisation DoSaveOrganisation(Organisation organisation)
        {
            MongoCollection<BsonDocument> collection = this.database.GetCollection(iApplyDb.Organisation._COLLECTION_NAME);
            BsonDocument newDocument = BsonConverter.ConvertToBsonViaJson(organisation);

            if (!organisation.IsNew)
            {
                BsonDocument existingDocument = collection.FindOneById(new BsonObjectId(new ObjectId(organisation.Id)));
                if (newDocument.EquivalentTo(existingDocument))
                {
                    return organisation;
                }

                collection.CopyDocumentToHistory(organisation.Id, iApplyDb.OrganisationHistory._COLLECTION_NAME, iApplyDb.OrganisationHistory.ORGANISATION_ID);
            }

            collection.Save(newDocument);
            return BsonConverter.ConvertToObjectViaJson<Organisation>(newDocument);
        }
            public void EnsureParentOrganisation()
            {
                Organisation org = new Organisation
                    {
                        Id = "new-org",
                        Name = "Test"
                    };

                this.Manager.SaveOrganisation(org, "Administrator");
            }
            public void SetRestrictedPropertiesOnBaseOrg()
            {
                Organisation org = new Organisation
                    {
                        Id = "foundation",
                        Enabled = false,
                        Name = "Test",
                        ParentOrganisationId = "grandchild-1"
                    };

                Organisation savedOrg = this.Manager.SaveOrganisation(org, "Administrator");

                Assert.IsTrue(savedOrg.BaseOrganisation);
                Assert.IsTrue(savedOrg.Enabled);
                Assert.IsNull(savedOrg.ParentOrganisationId);
            }
 public void UnentitledOrganisation()
 {
     Organisation org = new Organisation { Id = "child-1", Name = "Foo", BaseOrganisation = false, ParentOrganisationId = "foundation" };
     this.Manager.SaveOrganisation(org, "user-1");
 }
 public void SetBaseOrganisationOnNew()
 {
     Organisation org = new Organisation { BaseOrganisation = true, Name = "Test", ParentOrganisationId = "foundation" };
     Organisation savedOrg = this.Manager.SaveOrganisation(org, "Administrator");
     Assert.IsFalse(savedOrg.BaseOrganisation);
 }
 public void SetBaseOrganisationOnExisting()
 {
     Organisation org = new Organisation { Id = "child-1", Name = "Foo", BaseOrganisation = true, ParentOrganisationId = "foundation" };
     Organisation savedOrg = this.Manager.SaveOrganisation(org, "Administrator");
     Assert.IsFalse(savedOrg.BaseOrganisation);
 }
 /// <summary>
 /// Saves the organisation.
 /// </summary>
 /// <param name="organisation">The organisation to save.</param>
 /// <returns>The saved organisation.</returns>
 protected abstract Organisation DoSaveOrganisation(Organisation organisation);
 /// <summary>
 /// Saves the organisation.
 /// </summary>
 /// <param name="organisation">The organisation to save.</param>
 /// <returns>The saved organisation.</returns>
 public Organisation SaveOrganisation(Organisation organisation)
 {
     return this.DoSaveOrganisation(organisation);
 }
        /// <summary>
        /// Ensures there is at least one organisation in the database,
        /// and caches the organisation id to the install variables.
        /// </summary>
        private void InitOrganisation()
        {
            MongoCursor<BsonDocument> orgDocs = this.Database.GetCollection(iApplyDb.Organisation._COLLECTION_NAME).FindAll();
            OrganisationList orgs = BsonConverter.ConvertToObjectViaJson<OrganisationList>(orgDocs);

            switch (orgs.Count)
            {
                case 0:
                    string orgName = !string.IsNullOrEmpty(this.installConfiguration.OrgName) ? this.installConfiguration.OrgName : this.ReadInput("No organisation found. Please enter new organisation name");
                    this.installLogger.Log(Messages.DB_CreateOrg);
                    Organisation tempOrg = new Organisation { Name = orgName, BaseOrganisation = true, Enabled = true };
                    tempOrg.CreateHandle();
                    BsonDocument document = BsonConverter.ConvertToBsonViaJson(tempOrg);
                    this.Database.GetCollection(iApplyDb.Organisation._COLLECTION_NAME).Save(document);
                    this.installLogger.LogSuccess(Messages.MAIN_StepComplete);
                    this.installVariables.BaseOrganisation = BsonConverter.ConvertToObjectViaJson<Organisation>(document);

                    SystemSettings systemSettings = new SystemSettings
                    {
                        SystemName = orgName,
                        EnableFormApprovals = false,
                        ServiceEndpointFilter = new UrlFilter
                        {
                            Enabled = true,
                            Whitelist = new List<string>()
                        }
                    };

                    BsonDocument settingsDoc = BsonConverter.ConvertToBsonViaJson(systemSettings);
                    this.Database.GetCollection(iApplyDb.SystemSettings._COLLECTION_NAME).Save(settingsDoc);

                    break;

                case 1:
                    this.installVariables.BaseOrganisation = orgs.First();
                    break;

                default:
                    Organisation org = orgs.FirstOrDefault(o => o.BaseOrganisation);
                    if (org == null)
                    {
                        throw new InvalidOperationException(Messages.DB_MultipleOrganisations);
                    }

                    this.installVariables.BaseOrganisation = org;
                    break;
            }
        }