public JsonResult AddRole(RoleModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyRoleBLL propertyRoleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); //初始化平台角色数据实体 T_CompanyRole role = new T_CompanyRole() { RoleName = model.RoleName, RoleMemo = model.RoleMemo, CompanyId = GetSessionModel().CompanyId.Value }; //保存 propertyRoleBll.Save(role); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 添加公司,指定系统角色 /// </summary> /// <param name="company">公司实体对象</param> /// <returns></returns> public bool AddCompany(T_Company company) { //使用事务进行数据库操作 using (var tran = this.nContext.Database.BeginTransaction()) { try { //添加公司 var newCompany = base.Save(company); if (newCompany != null) { //给公司设定系统角色 ICompanyRoleBLL companyRoleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); //初始化物业系统角色数据实体 T_CompanyRole role = new T_CompanyRole() { RoleName = ConstantParam.COMPANY_SYSTEM_ROLE_NAME, RoleMemo = ConstantParam.COMPANY_SYSTEM_ROLE_MEMO, CompanyId = newCompany.Id, IsSystem = ConstantParam.USER_ROLE_MGR }; //保存 companyRoleBll.Save(role); //提交事务 tran.Commit(); } } catch { tran.Rollback(); return(false); } } return(true); }