示例#1
0
        public ActionResult AddUser(UserViewModel model)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(model.LoginName)
                    || String.IsNullOrWhiteSpace(model.Password)
                    || String.IsNullOrWhiteSpace(model.PasswordConfirm)
                    || String.IsNullOrWhiteSpace(model.Name)
                    || String.IsNullOrWhiteSpace(model.City))
                {
                    throw new Exception("打 * 的为必填字段,请正确填写完毕再提交。");
                }

                if(!model.Password.Equals(model.PasswordConfirm))
                {
                    throw new Exception("两次输入的密码不一致,请重新输入。");
                }

                var bizUser = model.ToUserModel();
                UserBusiness ub = new UserBusiness();
                ub.AddUser(bizUser);

                ModelState.AddModelError("", "新用户添加成功。");
                return View("New", new UserViewModel());
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("",ex.Message);
                return View("New", new UserViewModel());
            }
        }
示例#2
0
 public ActionResult MyInfo()
 {
     try
     {
         var myInfo = new UserViewModel(SessionManager.User);
         return View("MyInfo", myInfo);
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         return View("MyInfo", new UserViewModel());
     }
 }