๐ Documentation: IrbyImaging.DomainClasses/Permissions.cs
๐ Table of Contents
- ๐ Overview & Purpose
- ๐ Key Functional Areas
- ๐ Dependencies & Technologies
- ๐ฆ Data Model:
PermissionsEntity - ๐ ๏ธ Helper Methods & Utilities
- โ ๏ธ Error Handling & Return Types
- ๐ API Endpoints Overview
- ๐ค Third-party Integrations
- ๐ป Sample Code Blocks & Usage Examples
- ๐ UML Class Diagram
- ๐งญ Conclusion
๐ Overview & Purpose
The Permissions class in IrbyImaging.DomainClasses represents a single Permission in the system.
This entity is used to:
- Define granular access rights within the application (e.g., โViewReportsโ, โEditOrdersโ).
- Associate many-to-many relationships with Roles.
- Track audit fields (Created/Modified timestamps & user info) and soft-deletion status.
By mapping to the database via Entity Framework attributes, this class becomes the backbone of the applicationโs authorization layer.
๐ Key Functional Areas
- Entity Definition: Defines the schema and properties of a permission.
- Database Mapping: Uses EF Data Annotations to map to
irby.Permissions. - Navigation: Holds a collection of
Roleentities for many-to-many role assignments. - Audit & Soft Delete: Contains fields like
IsDeleted,AddedBy,AddedDate, etc., for tracking changes.
๐ Dependencies & Technologies
- .NET: C#/.NET Framework
- Entity Framework:
System.ComponentModel.DataAnnotationsSystem.ComponentModel.DataAnnotations.Schema
- LINQ: For querying collections (
System.Linq) - Collections:
ICollection<T>for navigation properties
๐ฆ Data Model: Permissions Entity
4.1 Entity-to-Table Mapping
[Table("Permissions", Schema = "irby")]
public class Permissions
{
// ...
}
- Table Name:
Permissions - Schema:
irby
4.2 Property Reference Table
| Property | Type | Attributes | Description |
|---|---|---|---|
| PermissionId | Guid |
[Key] |
Primary key (unique identifier). |
| PermissionName | string |
[Display(Name = "Permission")] |
Humanโreadable name (e.g. โViewReportsโ). |
| PermissionDescription | string |
[Display(Name = "Permission Description")] |
Free text description of what this permission allows. |
| Roles | ICollection<Role> |
[NotMapped] |
Navigation to associated Role entities. |
| IsDeleted | bool |
Soft-delete flag (true = logically deleted). | |
| AddedBy | string |
Username or ID of creator. | |
| AddedDate | DateTime |
Timestamp when the record was created. | |
| ModifiedBy | string |
Username or ID of last modifier. | |
| ModifiedDate | DateTime |
Timestamp of the last update. |
๐ ๏ธ Helper Methods & Utilities
Note:
Permissions.csis a pure entity class.
All logic (repositories, services, validation) resides elsewhere.No additional helper methods or utilities are defined here aside from the constructor:
public Permissions()
{
Roles = new HashSet<Role>();
}
- Purpose: Ensures
Rolesis never null when first instantiated.
โ ๏ธ Error Handling & Return Types
As a domain class, Permissions does not implement methods that return values or exceptions. Error handling is managed by:
- Entity Framework on database operations (e.g.
DbUpdateException). - Validation in higher-level layers (e.g. DataAnnotations, FluentValidation).
๐ API Endpoints Overview
โ ๏ธ This file does not define any API endpoints.
It is consumed by your Data Access / Service layers, which in turn power your controllers or GraphQL endpoints.
๐ค Third-party Integrations
- Entity Framework (Data Annotations) for ORM mapping.
- System.ComponentModel (Display attributes) for UI/metadata hints.
๐ป Sample Code Blocks & Usage Examples
1. Creating a New Permission
using IrbyImaging.DomainClasses;
// Instantiate
var newPermission = new Permissions
{
PermissionId = Guid.NewGuid(),
PermissionName = "ManageUsers",
PermissionDescription = "Allows management of user accounts",
IsDeleted = false,
AddedBy = "adminUser",
AddedDate = DateTime.UtcNow,
ModifiedBy = "adminUser",
ModifiedDate = DateTime.UtcNow
};
// Assign to a Role (navigation property)
var adminRole = dbContext.Roles
.FirstOrDefault(r => r.RoleName == "Administrator");
newPermission.Roles.Add(adminRole);
// Persist
dbContext.Permissions.Add(newPermission);
dbContext.SaveChanges();
2. Querying Active Permissions
var activePermissions = dbContext.Permissions
.Where(p => !p.IsDeleted)
.Select(p => new
{
p.PermissionName,
p.PermissionDescription
})
.ToList();
๐ UML Class Diagram
classDiagram
class Permissions {
<<Entity>>
+Guid PermissionId
+string PermissionName
+string PermissionDescription
+bool IsDeleted
+string AddedBy
+DateTime AddedDate
+string ModifiedBy
+DateTime ModifiedDate
-ICollection<Role> Roles
}
class Role {
<<Entity>>
+Guid RoleId
+string RoleName
+ICollection<Permissions> Permissions
}
Permissions "1" -- "0..*" Role : Roles
Role "1" -- "0..*" Permissions : Permissions
Legend
โข+Public member
โข-Private/Protected member
โข<<Entity>>Represents a databaseโmapped class
๐งญ Conclusion
The Permissions domain class is the cornerstone of your authorization module. By defining permissions in a normalized table and linking them to roles, you achieve a flexible and extensible security model.
- Scales to hundreds of permissions/roles
- Supports audit trails & soft deletes
- Integrates seamlessly with Entity Framework
Use this class as the starting point for building out your security infrastructureโbe it in MVC controllers, Web APIs, or GraphQL services.
Happy coding! ๐