public ActionResult AddUser(PropertyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = new T_PropertyUser() { UserName = model.UserName, TrueName = model.TrueName, Password = PropertyUtils.GetMD5Str(model.Password), Memo = model.Memo, Tel = model.Tel, Phone = model.Phone, Email = model.Email, PropertyPlaceId = GetSessionModel().PropertyPlaceId.Value }; // 保存到数据库 propertyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 设置管理员提交 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonModel SetAdmin(PropertyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = new T_PropertyUser() { PropertyPlaceId = model.PlaceId, UserName = model.UserName, Email = model.Email, Password = PropertyUtils.GetMD5Str(model.Password), IsMgr = ConstantParam.USER_ROLE_MGR, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, }; //为管理员添加角色 IPropertyRoleBLL roleBll = BLLFactory <IPropertyRoleBLL> .GetBLL("PropertyRoleBLL"); var role = roleBll.GetEntity(r => r.IsSystem == ConstantParam.USER_ROLE_MGR && r.PropertyPlaceId == model.PlaceId); if (role != null) { propertyUser.PropertyUserRoles.Add(new R_PropertyUserRole() { RoleId = role.Id, }); } //创建管理员 propertyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(jm); }