Skip to main content

Overview

The Customer Management module provides complete CRUD functionality for managing customer information. The system stores detailed customer profiles including personal information, contact details, and addresses.

Customer Model

The Customer model (Models/Customer.cs:3-13) defines a comprehensive customer profile:
public class Customer
{
    public int Id { get; set; }
    public string Document { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Address { get; set; }
    public DateTime Birthday { get; set; }
    public string PhoneNumber { get; set; }
    public string Email { get; set; }
}

Properties

PropertyTypeDescriptionExample
IdintUnique identifier1
DocumentstringGovernment-issued ID number”12345678”
FirstNamestringCustomer’s first name”John”
LastNamestringCustomer’s last name”Smith”
AddressstringPhysical address”123 Main St”
BirthdayDateTimeDate of birth1990-05-15
PhoneNumberstringContact phone number”+1-555-0123”
EmailstringEmail address[email protected]
The Customer model captures all essential information needed for customer relationship management, loyalty programs, and communication.

CRUD Operations

Viewing All Customers

The Index page (Pages/Customers/Index.cshtml.cs:22-28) displays all customer records:
public IList<Customer> Customers { get; set; } = default!;

public async Task OnGetAsync()
{
    if (_context.Customers != null)
    {
        Customers = await _context.Customers.ToListAsync();
    }
}
The page loads all customers asynchronously and exposes them through the Customers property for display in the view.

Customer Information Fields

Personal Information

Document

Government-issued identification number for unique customer identification

Name

Full name split into FirstName and LastName for proper addressing

Birthday

Date of birth for age verification and birthday promotions

Address

Physical address for delivery and communication purposes

Contact Information

Email

Primary email address for digital communication

Phone Number

Contact phone number for urgent communication

Authorization

All customer management operations require authentication:
[Authorize]
public class IndexModel : PageModel
{
    // Implementation
}
Customer data contains personally identifiable information (PII). Only authenticated users can access customer management features.

Database Context

Customers are managed through the SupermarketContext (Data/SupermarketContext.cs:15):
public DbSet<Customer> Customers { get; set; }

Page Structure

The customer management module consists of four Razor Pages:
PageRoutePurpose
Index/Pages/Customers/Index.cshtmlDisplay all customers
Create/Pages/Customers/Create.cshtmlAdd new customer
Edit/Pages/Customers/Edit.cshtmlUpdate customer details
Delete/Pages/Customers/Delete.cshtmlRemove customer record

Validation Best Practices

Consider adding validation attributes to ensure data quality:
public class Customer
{
    public int Id { get; set; }
    
    [Required]
    [StringLength(20)]
    public string Document { get; set; }
    
    [Required]
    [StringLength(50)]
    public string FirstName { get; set; }
    
    [Required]
    [StringLength(50)]
    public string LastName { get; set; }
    
    [Required]
    [StringLength(200)]
    public string Address { get; set; }
    
    [Required]
    [DataType(DataType.Date)]
    public DateTime Birthday { get; set; }
    
    [Required]
    [Phone]
    [StringLength(20)]
    public string PhoneNumber { get; set; }
    
    [Required]
    [EmailAddress]
    [StringLength(100)]
    public string Email { get; set; }
}
Adding data annotations improves input validation and provides better user feedback when invalid data is entered.

Common Operations

Search by Email

var customer = await _context.Customers
    .FirstOrDefaultAsync(c => c.Email == email);

Search by Document

var customer = await _context.Customers
    .FirstOrDefaultAsync(c => c.Document == documentNumber);

Find Customers by Name

var customers = await _context.Customers
    .Where(c => c.FirstName.Contains(searchTerm) || c.LastName.Contains(searchTerm))
    .ToListAsync();

Birthday List for Current Month

var currentMonth = DateTime.Now.Month;
var birthdayCustomers = await _context.Customers
    .Where(c => c.Birthday.Month == currentMonth)
    .OrderBy(c => c.Birthday.Day)
    .ToListAsync();

Privacy and Security

PII Protection

Customer data contains sensitive PII requiring proper protection

Access Control

Implement role-based access for viewing customer information

Audit Logging

Track who accesses and modifies customer records

Data Encryption

Consider encrypting sensitive fields at rest and in transit

Advanced Features

Group customers by demographics, purchase history, or behavior for targeted marketing campaigns.
Use customer data to implement point-based loyalty programs and track reward balances.
Link customers to their transaction history for personalized recommendations and analytics.
Add fields to track customer preferences for email, SMS, and promotional communications.

GDPR Compliance

For international deployments, consider implementing:
  • Right to Access: Allow customers to request their data
  • Right to Rectification: Easy data correction mechanisms
  • Right to Erasure: “Delete my account” functionality
  • Data Portability: Export customer data in standard formats
  • Consent Management: Track consent for data processing and marketing
Deleting customer records may impact referential integrity if linked to orders or transactions. Consider soft deletes or data archival strategies.

Build docs developers (and LLMs) love