๐Ÿ“š Documentation: IrbyImaging.DomainClasses/Permissions.cs


๐Ÿ“– Table of Contents

  1. ๐Ÿ“ Overview & Purpose
  2. ๐Ÿš€ Key Functional Areas
  3. ๐Ÿ”— Dependencies & Technologies
  4. ๐Ÿ“ฆ Data Model: Permissions Entity
  5. ๐Ÿ› ๏ธ Helper Methods & Utilities
  6. โš ๏ธ Error Handling & Return Types
  7. ๐ŸŒ API Endpoints Overview
  8. ๐Ÿค Third-party Integrations
  9. ๐Ÿ’ป Sample Code Blocks & Usage Examples
  10. ๐Ÿ“Š UML Class Diagram
  11. ๐Ÿงญ 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 Role entities 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.DataAnnotations
    • System.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.cs is 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 Roles is 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! ๐ŸŽ‰