Beispiel #1
0
        public static UserRole AddUserRole(UserRole userRole)
        {
            string sql =
                "INSERT UserRoles (Name)" +
                "VALUES (@Name)";

            sql += " ; SELECT @@IDENTITY";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@Name", userRole.Name)
                };

                int newId = DBHelper.GetScalar(sql, para);
                return GetUserRoleById(newId);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
Beispiel #2
0
        public static UserRole GetUserRoleById(int id)
        {
            string sql = "SELECT * FROM UserRoles WHERE Id = @Id";

            try
            {
                SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@Id", id));
                if (reader.Read())
                {
                    UserRole userRole = new UserRole();

                    userRole.Id = (int)reader["Id"];
                    userRole.Name = (string)reader["Name"];

                    reader.Close();

                    return userRole;
                }
                else
                {
                    reader.Close();
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
Beispiel #3
0
 public static void DeleteUserRole(UserRole userRole)
 {
     DeleteUserRoleById( userRole.Id );
 }
Beispiel #4
0
        private static IList<UserRole> GetUserRolesBySql( string sql, params SqlParameter[] values )
        {
            List<UserRole> list = new List<UserRole>();

            try
            {
                DataTable table = DBHelper.GetDataSet( sql, values );

                foreach (DataRow row in table.Rows)
                {
                    UserRole userRole = new UserRole();

                    userRole.Id = (int)row["Id"];
                    userRole.Name = (string)row["Name"];

                    list.Add(userRole);
                }

                return list;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
Beispiel #5
0
        public static void ModifyUserRole(UserRole userRole)
        {
            string sql =
                "UPDATE UserRoles " +
                "SET " +
                    "Name = @Name " +
                "WHERE Id = @Id";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@Id", userRole.Id),
                    new SqlParameter("@Name", userRole.Name)
                };

                DBHelper.ExecuteCommand(sql, para);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
Beispiel #6
0
 public static void ModifyUserRole(UserRole userRole)
 {
     UserRoleService.ModifyUserRole(userRole);
 }
Beispiel #7
0
 public static void DeleteUserRole(UserRole userRole)
 {
     UserRoleService.DeleteUserRole(userRole);
 }
Beispiel #8
0
 public static UserRole AddUserRole(UserRole userRole)
 {
     return UserRoleService.AddUserRole(userRole);
 }