public ActionResult Add()
 {
     ViewBag.User = MatrixUser;
     ViewBag.NextName = UNameBuilder.GetNextUserName(MatrixUser);
     ViewBag.UserState = EnumHelper.ToSelectList<UserState>(
         it => it == UserState.Active,
         it => Resource.ResourceManager.GetString(it.ToString()),
         it => it.ToString());
     ViewBag.Species = EnumHelper.ToMultiSelectList<LotterySpecies>(
         it => true,
         it => Resource.ResourceManager.GetString(it.ToString()),
         it => it.ToString());
     if (MatrixUser.Role == Role.Agent)
         ViewBag.CommGroup = CommManager.GetVNVoteCommGroup().Select(it => new SelectListItem
         {
             Text = it.GroupName,
             Value = it.GroupId.ToString()
         });
     var model = new RegisterModel
     {
         MinShareRate = 0,
         MinGivenCredit = 0,
         MaxShareRate = MatrixUser.UserInfo.ShareRate * 100,
         MaxGivenCredit = MatrixUser.UserInfo.AvailableGivenCredit
     };
     return View(model);
 }
 public ActionResult Add(RegisterModel model)
 {
     JsonResultModel result = new JsonResultModel();
     if (!(result.IsSuccess = ModelState.IsValid))
     {
         result.Message = ModelState.ToErrorString();
         return Json(result);
     }
     if (!EncryptHelper.Equal(model.YourPassword, CurrentUser.UserInfo.Password))
     {
         result.IsSuccess = false;
         result.Message = Resource.PasswordError;
         return Json(result);
     }
     try
     {
         AddUser(model);
         result.Message = Resource.Success;
         result.Model = model;
     }
     catch (Exception ex)
     {
         result.IsSuccess = false;
         result.Message = ex.Message;
         //TODO:筛选各种异常,并记录异常信息
     }
     return Json(result);
 }
 private void AddUser(RegisterModel model)
 {
     var user = model.ToUser();
     user.ParentId = MatrixUser.UserId;
     switch (MatrixUser.Role)
     {
         case Role.Company: UserManager.AddSuper(user, model.Species); break;
         case Role.Super: UserManager.AddMaster(user, model.Species); break;
         case Role.Master: UserManager.AddAgent(user, model.Species); break;
         case Role.Agent: UserManager.AddMember(user, model.Species, model.CommGroup); break;
         default: throw new NoPermissionException("Add User", string.Format("User:{0},Role:{1}", CurrentUser.UserName, CurrentUser.Role));
     }
     ActionLogger.Log(CurrentUser, user, LogResources.AddUser, LogResources.GetAddUser(user.UserName));
 }