public ActionResult Edit(UserroleInfo userroleInfo) { if (userroleInfo.Indx == 0) { return Insert(userroleInfo); } else { return Update(userroleInfo); } }
/// <summary> /// 设置SQL参数表 /// </summary> /// <param name="Userrole">Userrole对象</param> /// <returns>Userrole参数数组</returns> private SqlParameter[] Set_Userrole_Parameters(UserroleInfo userroleInfo) { SqlParameter[] paramArray = new SqlParameter[] {new SqlParameter("@Indx",userroleInfo.Indx), new SqlParameter("@UserID",userroleInfo.UserID), new SqlParameter("@RoleID",userroleInfo.RoleID), new SqlParameter("@CreatedBy",string.IsNullOrEmpty(userroleInfo.CreatedBy)?"":userroleInfo.CreatedBy) }; return paramArray; }
/// <summary> /// 初始化UserroleInfo /// </summary> private UserroleInfo InitUserroleInfoByDataReader(UserroleInfo userroleInfo, IDataReader reader) { userroleInfo = new UserroleInfo(reader["Indx"].ToString() != "" ? Int32.Parse(reader["Indx"].ToString()) : 0, reader["UserID"].ToString() != "" ? Int32.Parse(reader["UserID"].ToString()) : 0, reader["RoleID"].ToString() != "" ? Int32.Parse(reader["RoleID"].ToString()) : 0, reader["CreatedBy"].ToString(), reader["CreatedDate"].ToString() != "" ? DateTime.Parse(reader["CreatedDate"].ToString()) : new DateTime()); return userroleInfo; }
/// <summary> /// 更新一条Userrole记录 /// </summary> /// <param name="db">DataBase对象</param> /// <param name="tran">一个有效的DbTransaction</param> /// <param name="userrole">Userrole对象</param> /// <param name="whLoginID">要查询的仓库的前缀</param> /// <returns>执行更新对数据库影响的行数</returns> public int UpdateUserrole(Database db, DbTransaction tran, UserroleInfo userroleInfo) { int result = 0; SqlParameter[] paras = Set_Userrole_Parameters(userroleInfo); if (paras != null) { result += DBHelper.ExecuteNonQuery(db, tran, CommandType.Text, SQL_UPDATE_USERROLE, paras); } return result; }
/// <summary> /// 新增一条Userrole记录 /// </summary> /// <param name="userrole">Userrole对象</param> /// <param name="whLoginID">要查询的仓库的前缀</param> /// <returns>执行新增对数据库影响的行数</returns> public int InsertUserrole(UserroleInfo userroleInfo) { int result = 0; SqlParameter[] paras = Set_Userrole_Parameters(userroleInfo); if (paras != null) { result = DBHelper.ExecuteNonQuery(CommandType.Text, SQL_INSERT_USERROLE, paras); } return result; }
/// <summary> /// 更新一条Userrole记录 /// </summary> /// <param name="userrole">Userrole对象</param> /// <param name="whLoginID">要查询的仓库的前缀</param> /// <returns>执行更新对数据库影响的行数</returns> public int UpdateUserrole(UserroleInfo userroleInfo) { return userroleDA.UpdateUserrole(userroleInfo); }
/// <summary> /// 新增一条Userrole记录 /// </summary> /// <param name="userrole">Userrole对象</param> /// <param name="whLoginID">要查询的仓库的前缀</param> /// <returns>执行新增对数据库影响的行数</returns> public int InsertUserrole(UserroleInfo userroleInfo) { return userroleDA.InsertUserrole(userroleInfo); }
public ActionResult Insert(UserroleInfo userroleInfo) { try { userroleInfo.CreatedDate = DateTime.Now; //userroleInfo.UpdatedDate = DateTime.Now; userroleInfo.CreatedBy = CurrentUserInfo.UserCode; //userroleInfo.UpdatedBy = CurrentUserInfo.UserCode; IUserroleService userroleService = UnityHelper.UnityResolve<IUserroleService>(); var data = userroleService.InsertUserrole(userroleInfo); LogHelper.LogOperation(CurrentUserInfo.UserCode, string.Format("Insert UserroleInfo {0},{1}", LogHelper.ChangeEntityToLog(userroleInfo), data)); if (data > 0) { return Content("OK"); } else { return Content("Failed"); } } catch (BusinessException bex) { return Content(bex.Message); } catch (Exception ex) { LogHelper.LogError(ex, ""); return Content(ex.Message); } }