public ActionResult CreateExtUser(FormCollection _POST)
        {
            try
            {
                model.CreateExtUser.Organization = _POST["organization"];
                model.CreateExtUser.UserName     = _POST["username"];
                model.CreateExtUser.Description  = _POST["description"];
                model.CreateExtUser.DisplayName  = _POST["displayname"];
                model.CreateExtUser.DomainName   = _POST["domainname"];

                model.CreateExtUser.Password       = CommonCAS.GeneratePassword();
                model.CreateExtUser.ExpirationDate = _POST["datetime"];

                CommonCAS.Log(string.Format("has run User/CreateExtUser() to create ext user {0}_ext_{1}", model.CreateExtUser.Organization, model.CreateExtUser.UserName));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateExtUser(model.CreateExtUser).Invoke();
                }

                CommonCAS.Stats("User/CreateExtUser");

                return(View("CreateExtUserSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View("CreateExtUser", model));
            }
        }
        public ActionResult CreateServiceUser(FormCollection _POST)
        {
            try
            {
                model.ServiceUser.Organization = _POST["organization"];
                model.ServiceUser.Service      = _POST["service"];
                model.ServiceUser.Description  = _POST["description"];
                model.ServiceUser.Password     = CommonCAS.GeneratePassword();
                model.ServiceUser.Management   = _POST["management"] == "on" ? true : false;

                CommonCAS.Log(string.Format("has run User/CreateServiceUser() to create service user {0}_svc_{1}", model.ServiceUser.Organization, model.ServiceUser.Service));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateServiceUser(model.ServiceUser);
                    var result = ps.Invoke();
                }

                CommonCAS.Stats("User/CreateServiceUser");

                return(View("CreateServiceUserSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View("CreateServiceUser", model));
            }
        }
        public ActionResult CreateMailbox(FormCollection _POST)
        {
            try
            {
                var NewPassword = CommonCAS.GeneratePassword();

                CustomMailbox newMailbox = new CustomMailbox()
                {
                    UserName     = _POST["username"].Trim(),
                    DomainName   = _POST["domainname"],
                    DisplayName  = _POST["displayname"].TrimEnd(),
                    Organization = _POST["organization"],
                    Password     = CommonCAS.GeneratePassword(),
                    Type         = _POST["type"],
                };

                if (_POST["emailaddresses"] != null)
                {
                    newMailbox.EmailAddresses = _POST["emailaddresses"].Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>();
                }
                else
                {
                    newMailbox.EmailAddresses = new List <string>();
                }

                model.Mailbox = newMailbox;

                CommonCAS.Log(string.Format("has run Mail/CreateMailbox() to create {0} for {1}.", newMailbox.DisplayName, model.Mailbox.Organization));

                using (MyPowerShell ps = new MyPowerShell())
                {
                    ps.CreateMailbox(newMailbox);
                    var result = ps.Invoke();
                }

                model.OKMessage.Add("Successfully created mailbox " + newMailbox.DisplayName + "for" + newMailbox.Organization);

                CommonCAS.Stats("Mail/CreateMailbox");

                return(View("CreateMailboxSuccess", model));
            }
            catch (Exception exc)
            {
                CommonCAS.Log("Exception: " + exc.Message);
                model.ActionFailed = true;
                model.Message      = exc.Message;
                return(View(model));
            }
        }