public ActionResult AddCompanyUser(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser propertyUser = new T_CompanyUser() { UserName = model.UserName, TrueName = model.TrueName, Password = PropertyUtils.GetMD5Str(model.Password), Memo = model.Memo, Tel = model.Tel, Phone = model.Phone, Email = model.Email, CompanyId = GetSessionModel().CompanyId.Value }; // 保存到数据库 companyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public JsonResult SetCompanyAdministrator(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL propertyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = new T_CompanyUser() { CompanyId = model.CompanyId, UserName = model.UserName, Email = model.Email, Password = PropertyUtils.GetMD5Str(model.Password), IsMgr = ConstantParam.USER_ROLE_MGR, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, }; //为管理员添加角色 ICompanyRoleBLL roleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); var role = roleBll.GetEntity(r => r.IsSystem == ConstantParam.USER_ROLE_MGR && r.CompanyId == model.CompanyId); if (role != null) { companyUser.CompanyUserRoles.Add(new R_CompanyUserRole() { RoleId = role.Id, }); } //创建管理员 propertyUserBll.Save(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }