Esempio n. 1
0
        public ActionResult UserCreate(string firstName, string lastName, string userName, string email, int?staffID)
        {
            UserVM model = new UserVM
            {
                FirstName = firstName,
                LastName  = lastName,
                UserName  = userName,
                Email     = email
            };

            if (staffID.HasValue)
            {
                model.StaffMember = new Domain.OfficeStaff.OfficeStaff()
                {
                    ID = staffID
                };
            }

            try
            {
                RegisterModel registerUser = new RegisterModel
                {
                    UserName = model.UserName,
                    Password = Domain.Admin.User.GenerateRandomPassword()
                };

                App.Account.AccountController accountController = new App.Account.AccountController
                {
                    ControllerContext = ControllerContext
                };
                accountController.Register(registerUser);

                int aspNetUserId = accountController.GetUserID(model.UserName);

                if ((aspNetUserId) != 0)
                {
                    model.AspNetUserID = aspNetUserId;
                    repository.SaveUser(model);

                    // TODO: Email Temporary Password to User


                    // Load Permissions and Options for the Registered User
                    repository.InsertPermissionsList(model.ID);
                    repository.InsertOptionsList(model.ID);

                    // send this along with the temp password so we can display it onscreen
                    return(Manage(0, registerUser.Password));
                }

                return(new Dymeng.Framework.Web.Mvc.Controllers.TransferResult("Manage"));
            }
            catch (Exception e)
            {
                Dymeng.Framework.Exceptions.Handle(e, Global.GetWebInfo());
                return(Content("ERR: " + e.Message));
            }
        }
Esempio n. 2
0
        public ActionResult Delete(int id)
        {
            UserVM user = new UserVM();

            user = repository.GetUser(id);

            App.Account.AccountController accountController = new App.Account.AccountController
            {
                ControllerContext = this.ControllerContext
            };
            accountController.Delete(user.UserName);

            repository.DeleteUser(id);


            return(RedirectToAction("Users"));
        }