// GET: Ldap/UserSync
        public ActionResult Index(Guid id)
        {

            LdapUserConfig uc = new LdapUserConfig(id.ToString(), new Lcps.UI.Models.LcpsUiContext());

            return View(uc);
        }
        public ActionResult SyncGroups(Guid id)
        {
            string result = "ok";

            try
            {
                LdapUserConfig uc = new LdapUserConfig(id.ToString(), new Lcps.UI.Models.LcpsUiContext());
                uc.SyncGroupMemberships(true);
            }
            catch(Exception ex)
            {
                ExceptionCollector ec = new ExceptionCollector(ex);
                result = ec.ToUL();
            }

            return Content(result);
        }
        public ActionResult CreateAccount(string memberId)
        {
            string result = "ok";

            try
            {
                LdapUserConfig uc = new LdapUserConfig(memberId, new Lcps.UI.Models.LcpsUiContext());
                uc.SyncUser(false);
            }
            catch(Exception ex)
            {
                ExceptionCollector ec = new ExceptionCollector(ex);
                result = ec.ToUL();
            }

            return Content(result);
        }
        public ActionResult AssignRights(string currentName, string memberId)
        {
            string result = "ok";
            try
            {
                LdapUserConfig cfg = new LdapUserConfig(memberId, new Lcps.UI.Models.LcpsUiContext());
                DirectoryEntry de = (DirectoryEntry)cfg.LdapUser.GetUnderlyingObject();

                LdapUserConfig.GrantFullAccessToFolder(currentName, de, cfg.Member.UserName, cfg.LdapConfig.DomainPrincipalName);


            }
            catch(Exception ex)
            {
                ExceptionCollector ec = new ExceptionCollector(ex);
                result = ec.ToUL();
            }

            return Content(result);
        }
        public ActionResult SyncLdapAccount(Guid id)
        {
            string result = "ok";

            LdapUserConfig cfg = new LdapUserConfig(id.ToString(), _dbContext);
            
            try
            {
                cfg.SyncUser(false);
            }
            catch (Exception ex)
            {
                ExceptionCollector ec = new ExceptionCollector(ex);
                result = ec.ToUL();
            }

            return Content(result);
        }
 public ActionResult LdapConfig(string id)
 {
     LdapUserConfig u = new LdapUserConfig(id, new LcpsRepositoryContext());
     return View(u);
 }