예제 #1
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         //save
         PermissionService service = new PermissionService();
         if (this.Model == null)//新建
         {
             User model = new User();
             model.Code     = this.txtCode.Text.Trim();
             model.Name     = this.txtName.Text.Trim();
             model.Password = this.txtPassword.Text.Trim();
             model.IsAdmin  = this.ckbIsAdmin.Checked;
             model.Actived  = this.ckbActived.Checked;
             model.Remark   = this.txtRemark.Text.Trim();
             service.CreateUser(model, PermissionService.GetCurrentUser().Name);
         }
         else//修改
         {
             this.Model.Code     = this.txtCode.Text.Trim();
             this.Model.Name     = this.txtName.Text.Trim();
             this.Model.Password = this.txtPassword.Text.Trim();
             this.Model.IsAdmin  = this.ckbIsAdmin.Checked;
             this.Model.Actived  = this.ckbActived.Checked;
             this.Model.Remark   = this.txtRemark.Text.Trim();
             service.ModifyUser(this.Model, PermissionService.GetCurrentUser().Name);
         }
         //close diaglog
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         ErrorHandler.OnError(ex);
     }
 }
        public ActionResult Create(CreateAdminUserModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var service = new PermissionService(DataContext);
                    service.CreateUser(new AdminUser
                    {
                        UserName = model.UserName,
                        Email    = model.Email,
                        Password = model.Password,
                        RoleId   = model.RoleId
                    });
                    ShowSuccess(MessageResource.CreateSuccess);

                    return(RedirectToIndex());
                }
                catch (Exception ex)
                {
                    LogError(ex.ToString());
                    ShowError(MessageResource.CreateFailed);
                }
            }

            return(View(model));
        }
예제 #3
0
        public ActionResult Create(CreateAdminUserModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var service = new PermissionService(DataContext);
                    service.CreateUser(new AdminUser
                    {
                        UserName = model.UserName,
                        Email = model.Email,
                        Password = model.Password,
                        RoleId = model.RoleId
                    });
                    ShowSuccess(MessageResource.CreateSuccess);

                    return RedirectToIndex();
                }
                catch (Exception ex)
                {
                    LogError(ex.ToString());
                    ShowError(MessageResource.CreateFailed);
                }
            }

            return View(model);
        }
예제 #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //Verify
                if (string.IsNullOrEmpty(this.txtCode.Text.Trim()))
                {
                    throw new ApplicationException("编码不能为空");
                }
                if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
                {
                    throw new ApplicationException("名称不能为空");
                }

                //Save
                PermissionService service = new PermissionService();
                if (this._Model == null) //新建
                {
                    User newModel = new User();
                    newModel.Code     = this.txtCode.Text.Trim();
                    newModel.Name     = this.txtName.Text.Trim();
                    newModel.Remark   = this.txtRemark.Text.Trim();
                    newModel.Actived  = true;
                    newModel.Password = this.txtPassword.Text;
                    service.CreateUser(newModel, PermissionService.GetCurrentUser().Name);
                }
                else//修改
                {
                    this._Model.Name     = this.txtName.Text.Trim();
                    this._Model.Remark   = this.txtRemark.Text.Trim();
                    this._Model.Password = this.txtPassword.Text;
                    service.ModifyUser(this._Model, PermissionService.GetCurrentUser().Name);
                }

                //Close dialog
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                ErrorHandler.OnError(ex);
            }
        }