static void BuildRMLocations(List<Position> full)
        {
            TrimApplication.Initialize();

            try
            {
                using (Database db = new Database())
                {
                    //5503
                    Location locUseProfileof = new Location(db, 19509);
                    Location LocHighLevel = new Location(db, 5503);
                    db.Id = "03";
                    db.Connect();
                    FieldDefinition fd = new FieldDefinition(db, 501);
                    //
                    //Classification cla = new Classification(db);
                    
                    foreach (Position p in full)
                    {
                        //if (p.RMUri == 0)
                        //{
                            Location posloc = new Location(db, LocationType.Position);
                            //{
                            posloc.Surname = p.Title + " - " + p.Position_Number.ToString();
                            posloc.SetNotes("Entered by auto process: Source ID: " + p.Position_Number.ToString(), NotesUpdateType.AppendWithNewLine);
                            posloc.AddRelationship(LocHighLevel, LocRelationshipType.MemberOf, false);
                            //bu3loc.SetFieldValue(fd, new UserFieldValue("Business Unit 3"));
                            posloc.IsWithin = true;
                            //posloc.UseProfileOf = locUseProfileof;
                            posloc.Save();
                            p.RMUri = posloc.Uri;
                            Console.WriteLine("Created " + p.Title + " - " + p.Position_Number.ToString());
                            //
                            foreach (User u in p.user.Where(x => x.RMUri == 0))
                            {
                                //if (u.RMUri == 0)
                                //{
                                    try
                                    {
                                        Location userloc = new Location(db, LocationType.Person);
                                        //{
                                        userloc.Surname = u.Surname;
                                        userloc.GivenNames = u.FirstName;
                                        userloc.EmailAddress = u.Email;
                                        userloc.CanLogin = true;
                                        userloc.LogsInAs = u.FirstName[0].ToString() + u.Surname[0].ToString() + u.Employee_Number.ToString();
                                        userloc.AdditionalLogin = u.Email;
                                        string dlogon = lstDomain.Where(x=>x.email==u.Email).First().DomainLogon;
                                        if(dlogon.Length>1)
                                        {
                                        userloc.LogsInAs = "MSC\\"+dlogon;
                                        }
                                        else
                                        {
                                            userloc.LogsInAs = "MSC\\";
                                        }
                                        //userloc.UserType = UserTypes.Contributor;

                                        userloc.SetNotes("Entered by auto process: Source ID: " + u.Employee_Number, NotesUpdateType.AppendWithNewLine);
                                        userloc.AddRelationship(posloc, LocRelationshipType.MemberOf, false);
                                        //bu3loc.SetFieldValue(fd, new UserFieldValue("Business Unit 3"));
                                        userloc.IsWithin = true;
                                        userloc.UseProfileOf = locUseProfileof;
                                        userloc.Save();
                                        u.RMUri = userloc.Uri;
                                        BuildRMpersonalFolders(userloc);
                                        Console.WriteLine("Created " + u.Surname);
                                        //}
                                    }
                                    catch (Exception exp)
                                    {
                                        Console.WriteLine("Error creating person location: " + exp.Message.ToString());
                                    }
                                //}
                                //else
                                //{
                                //    Location userloc = new Location(db, u.RMUri);
                                //    userloc.AddRelationship(posloc, LocRelationshipType.MemberOf, false);
                                //    userloc.Save();
                                //}
                            }
                        //}
                        //else
                        //{
                        //    Location posloc = new Location(db, p.RMUri);
                        //    //posloc.AddRelationship(bu2loc, LocRelationshipType.MemberOf, false);
                        //    posloc.Save();
                        //}
                    }




                    //
                    //Build SCC org
                    //Location lOrg = new Location(db, LocationType.Organization);
                    //lOrg.Surname = "Sunshine Coast Council";
                    //lOrg.IsWithin = true;
                    //lOrg.SetFieldValue(fd, new UserFieldValue("Organisation"));
                    //lOrg.UseProfileOf = locUseProfileof;
                    //lOrg.Save();
                    //Console.WriteLine("Created " + lOrg.Surname);
                    //
                    //foreach (BU1 bu1 in full)
                    //{
                    //    Location bu1loc = new Location(db, LocationType.Organization);
                    //    //{
                    //        bu1loc.Surname = bu1.Name;
                    //        bu1loc.SetNotes("Entered by auto process: Source ID: " + bu1.ID.ToString(), NotesUpdateType.AppendWithNewLine);
                    //        bu1loc.SetFieldValue(fd, new UserFieldValue("Branch"));
                    //        bu1loc.AddRelationship(lOrg, LocRelationshipType.MemberOf, false);
                    //        bu1loc.IsWithin = true;
                    //        bu1loc.UseProfileOf = locUseProfileof;
                    //        bu1loc.Save();
                    //        bu1.RMUri = bu1loc.Uri;
                    //        Console.WriteLine("Created " + bu1.Name);

                    //        foreach (BU2 bu2 in bu1.bu2)
                    //        {
                    //            Location bu2loc = new Location(db, LocationType.Organization);
                    //            //{
                    //                bu2loc.Surname = bu2.Name;
                    //                bu2loc.SetNotes("Entered by auto process: Source ID: " + bu2.ID.ToString(), NotesUpdateType.AppendWithNewLine);
                    //                bu2loc.AddRelationship(bu1loc, LocRelationshipType.MemberOf, false);
                    //                bu2loc.SetFieldValue(fd, new UserFieldValue("Department"));
                    //                bu2loc.IsWithin = true;
                    //                bu2loc.UseProfileOf = locUseProfileof;
                    //                bu2loc.Save();
                    //                bu2.RMUri = bu2loc.Uri;
                    //                Console.WriteLine("Created " + bu2.Name);
                    //                //}
                    //            //
                    //                foreach (Position p in bu2.position)
                    //                {
                    //                    if (p.RMUri == 0)
                    //                    {
                    //                        Location posloc = new Location(db, LocationType.Position);
                    //                        //{
                    //                        posloc.Surname = p.Title + " - " + p.Position_Number.ToString();
                    //                        posloc.SetNotes("Entered by auto process: Source ID: " + p.Position_Number.ToString(), NotesUpdateType.AppendWithNewLine);
                    //                        posloc.AddRelationship(bu2loc, LocRelationshipType.MemberOf, false);
                    //                        //bu3loc.SetFieldValue(fd, new UserFieldValue("Business Unit 3"));
                    //                        posloc.IsWithin = true;
                    //                        posloc.UseProfileOf = locUseProfileof;
                    //                        posloc.Save();
                    //                        p.RMUri = posloc.Uri;
                    //                        Console.WriteLine("Created " + p.Title + " - " + p.Position_Number.ToString());
                    //                        //
                    //                        foreach (User u in p.user.Where(x => x.RMUri == 0))
                    //                        {
                    //                            if (u.RMUri == 0)
                    //                            {
                    //                                try
                    //                                {
                    //                                    Location userloc = new Location(db, LocationType.Person);
                    //                                    //{
                    //                                    userloc.Surname = u.Surname;
                    //                                    userloc.GivenNames = u.FirstName;
                    //                                    userloc.EmailAddress = u.Email;
                    //                                    userloc.CanLogin = true;
                    //                                    userloc.LogsInAs = u.FirstName[0].ToString() + u.Surname[0].ToString() + u.Employee_Number.ToString();
                    //                                    userloc.AdditionalLogin = u.FirstName + "." + u.Surname + "@sunshinecoast.qld.gov.au";
                    //                                    userloc.UserType = UserTypes.Contributor;
                    //                                    userloc.SetNotes("Entered by auto process: Source ID: " + u.Employee_Number, NotesUpdateType.AppendWithNewLine);
                    //                                    userloc.AddRelationship(posloc, LocRelationshipType.MemberOf, false);
                    //                                    //bu3loc.SetFieldValue(fd, new UserFieldValue("Business Unit 3"));
                    //                                    userloc.IsWithin = true;
                    //                                    userloc.Save();
                    //                                    u.RMUri = userloc.Uri;
                    //                                    BuildRMpersonalFolders(userloc);
                    //                                    Console.WriteLine("Created " + u.Surname);
                    //                                    //}
                    //                                }
                    //                                catch (Exception exp)
                    //                                {
                    //                                    Console.WriteLine("Error creating person location: " + exp.Message.ToString());
                    //                                }
                    //                            }
                    //                            else
                    //                            {
                    //                                Location userloc = new Location(db, u.RMUri);
                    //                                userloc.AddRelationship(posloc, LocRelationshipType.MemberOf, false);
                    //                                userloc.Save();
                    //                            }
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        Location posloc = new Location(db, p.RMUri);
                    //                        posloc.AddRelationship(bu2loc, LocRelationshipType.MemberOf, false);
                    //                        posloc.Save();
                    //                    }
                    //                }
                    //            //
                    //                foreach (BU3 bu3 in bu2.bu3)
                    //                {
                    //                    Location bu3loc = new Location(db, LocationType.Organization);
                    //                    //{
                    //                        bu3loc.Surname = bu3.Name;
                    //                        bu3loc.SetNotes("Entered by auto process: Source ID: " + bu3.ID.ToString(), NotesUpdateType.AppendWithNewLine);
                    //                        bu3loc.AddRelationship(bu2loc, LocRelationshipType.MemberOf, false);
                    //                        bu3loc.SetFieldValue(fd, new UserFieldValue("Team"));
                    //                        bu3loc.IsWithin = true;
                    //                        bu3loc.UseProfileOf = locUseProfileof;
                    //                        bu3loc.Save();
                    //                        bu3.RMUri = bu3loc.Uri;
                    //                        Console.WriteLine("Created " + bu3.Name);
                    //                        //
                    //                        foreach (Position p in bu3.position)
                    //                        {
                    //                            if (p.RMUri == 0)
                    //                            {
                    //                                Location posloc = new Location(db, LocationType.Position);
                    //                                //{
                    //                                posloc.Surname = p.Title + " - " + p.Position_Number.ToString();
                    //                                posloc.SetNotes("Entered by auto process: Source ID: " + p.Position_Number.ToString(), NotesUpdateType.AppendWithNewLine);
                    //                                posloc.AddRelationship(bu3loc, LocRelationshipType.MemberOf, false);
                    //                                //bu3loc.SetFieldValue(fd, new UserFieldValue("Business Unit 3"));
                    //                                posloc.IsWithin = true;
                    //                                posloc.UseProfileOf = locUseProfileof;
                    //                                posloc.Save();
                    //                                p.RMUri = posloc.Uri;
                    //                                Console.WriteLine("Created " + p.Title + " - " + p.Position_Number.ToString());
                    //                                //
                    //                                foreach (User u in p.user.Where(x => x.RMUri == 0))
                    //                                {
                    //                                    if (u.RMUri == 0)
                    //                                    {
                    //                                        try
                    //                                        {
                    //                                            Location userloc = new Location(db, LocationType.Person);
                    //                                            //{
                    //                                            userloc.Surname = u.Surname;
                    //                                            userloc.GivenNames = u.FirstName;
                    //                                            userloc.EmailAddress = u.Email;
                    //                                            //
                    //                                            userloc.CanLogin = true;
                    //                                            userloc.LogsInAs = u.FirstName[0].ToString() + u.Surname[0].ToString() + u.Employee_Number.ToString();
                    //                                            userloc.AdditionalLogin = u.FirstName + "." + u.Surname + "@sunshinecoast.qld.gov.au";
                    //                                            userloc.UserType = UserTypes.Contributor;

                    //                                            userloc.SetNotes("Entered by auto process: Source ID: " + u.Employee_Number, NotesUpdateType.AppendWithNewLine);
                    //                                            userloc.AddRelationship(posloc, LocRelationshipType.MemberOf, false);
                    //                                            //bu3loc.SetFieldValue(fd, new UserFieldValue("Business Unit 3"));
                    //                                            userloc.IsWithin = true;
                    //                                            userloc.Save();
                    //                                            u.RMUri = userloc.Uri;
                    //                                            BuildRMpersonalFolders(userloc);
                    //                                            Console.WriteLine("Created " + u.Surname);
                    //                                            //}
                    //                                        }
                    //                                        catch (Exception exp)
                    //                                        {
                    //                                            Console.WriteLine("Error creating person location: " + exp.Message.ToString());
                    //                                        }
                    //                                    }
                    //                                    else
                    //                                    {
                    //                                        Location userloc = new Location(db, u.RMUri);
                    //                                        userloc.AddRelationship(posloc, LocRelationshipType.MemberOf, false);
                    //                                        userloc.Save();
                    //                                    }
                    //                                }
                    //                            }
                    //                            else 
                    //                            {
                    //                                Location posloc = new Location(db, p.RMUri);
                    //                                posloc.AddRelationship(bu3loc, LocRelationshipType.MemberOf, false);
                    //                                posloc.Save();
                    //                            }
                    //                            //}
                    //                        }
                    //                        //
                    //                        foreach (BU4 bu4 in bu3.bu4)
                    //                        {
                    //                            Location bu4loc = new Location(db, LocationType.Organization);
                    //                            //{
                    //                                bu4loc.Surname = bu4.Name;
                    //                                bu4loc.SetNotes("Entered by auto process: Source ID: " + bu4.ID.ToString(), NotesUpdateType.AppendWithNewLine);
                    //                                bu4loc.AddRelationship(bu3loc, LocRelationshipType.MemberOf, false);
                    //                                bu4loc.SetFieldValue(fd, new UserFieldValue("Unit"));
                    //                                bu4loc.IsWithin = true;
                    //                                bu4loc.UseProfileOf = locUseProfileof;
                    //                                bu4loc.Save();
                    //                                bu4.RMUri = bu4loc.Uri;
                    //                                Console.WriteLine("Created " + bu4.Name);
                    //                                //
                    //                                foreach (Position p in bu4.position)
                    //                                {
                    //                                    if (p.RMUri == 0)
                    //                                    {
                    //                                        Location posloc = new Location(db, LocationType.Position);
                    //                                        posloc.Surname = p.Title + " - " + p.Position_Number.ToString();
                    //                                        posloc.SetNotes("Entered by auto process: Source ID: " + p.Position_Number.ToString(), NotesUpdateType.AppendWithNewLine);
                    //                                        posloc.AddRelationship(bu4loc, LocRelationshipType.MemberOf, false);
                    //                                        //bu3loc.SetFieldValue(fd, new UserFieldValue("Business Unit 3"));
                    //                                        posloc.IsWithin = true;
                    //                                        posloc.UseProfileOf = locUseProfileof;
                    //                                        posloc.Save();
                    //                                        p.RMUri = posloc.Uri;
                    //                                        Console.WriteLine("Created " + p.Title + " - " + p.Position_Number.ToString());
                    //                                        foreach (User u in p.user)
                    //                                        {
                    //                                            if (u.RMUri == 0)
                    //                                            {
                    //                                                try
                    //                                                {
                    //                                                    Location userloc = new Location(db, LocationType.Person);
                    //                                                    userloc.Surname = u.Surname;
                    //                                                    userloc.GivenNames = u.FirstName;
                    //                                                    userloc.EmailAddress = u.Email;
                    //                                                    userloc.CanLogin = true;
                    //                                                    userloc.LogsInAs = u.FirstName[0].ToString() + u.Surname[0].ToString() + u.Employee_Number.ToString();
                    //                                                    userloc.AdditionalLogin = u.FirstName + "." + u.Surname + "@sunshinecoast.qld.gov.au";
                    //                                                    userloc.UserType = UserTypes.Contributor;
                    //                                                    userloc.SetNotes("Entered by auto process: Source ID: " + u.Employee_Number, NotesUpdateType.AppendWithNewLine);
                    //                                                    userloc.AddRelationship(posloc, LocRelationshipType.MemberOf, false);
                    //                                                    userloc.IsWithin = true;
                    //                                                    userloc.Save();
                    //                                                    u.RMUri = userloc.Uri;
                    //                                                    BuildRMpersonalFolders(userloc);
                    //                                                    Console.WriteLine("Created " + userloc.Surname);
                    //                                                }
                    //                                                catch (Exception exp)
                    //                                                {
                    //                                                    Console.WriteLine("Error creating person location: " + exp.Message.ToString());
                    //                                                }
                    //                                            }
                    //                                            else
                    //                                            {
                    //                                                Location userloc = new Location(db, u.RMUri);
                    //                                                userloc.AddRelationship(posloc, LocRelationshipType.MemberOf, false);
                    //                                                userloc.Save();
                    //                                            }
                    //                                        }
                    //                                    }
                    //                                    else
                    //                                    {
                    //                                        Location posloc = new Location(db, p.RMUri);
                    //                                        posloc.AddRelationship(bu4loc, LocRelationshipType.MemberOf, false);
                    //                                        posloc.Save();
                    //                                    }
                    //                                }
                    //                        }
                    //                }
                    //        }
                    //}
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error: " + exp.Message.ToString());
                Loggitt(exp.Message.ToString(), "Error creating location");
            }
        }