The PayMode model represents different payment methods accepted by the supermarket. It provides a flexible way to manage payment options like cash, credit cards, debit cards, mobile payments, and other transaction types.
namespace SupermarketWEB.Models{ public class PayMode { public int Id { get; set; } public string Name { get; set; } public string Observation { get; set; } }}
Additional notes, instructions, or details about the payment method. Can include processing fees, acceptance criteria, or special handling instructions.
var cashPayment = new PayMode{ Name = "Cash", Observation = "Physical currency. No processing fees. Exact change preferred."};context.PayModes.Add(cashPayment);await context.SaveChangesAsync();
If you need to temporarily disable payment methods without deleting them, consider adding an IsActive boolean property.
// Enhanced PayMode with IsActive flagpublic class PayMode{ public int Id { get; set; } public string Name { get; set; } public string Observation { get; set; } public bool IsActive { get; set; } = true;}// Query only active payment methodsvar activePayModes = await context.PayModes .Where(p => p.IsActive) .ToListAsync();
// In a controller or servicepublic async Task<List<SelectListItem>> GetPaymentMethodsDropdown(){ return await context.PayModes .OrderBy(p => p.Name) .Select(p => new SelectListItem { Value = p.Id.ToString(), Text = p.Name }) .ToListAsync();}
using System.ComponentModel.DataAnnotations;public class PayMode{ public int Id { get; set; } [Required(ErrorMessage = "Payment method name is required")] [StringLength(100, MinimumLength = 2)] public string Name { get; set; } [Required(ErrorMessage = "Observation is required")] [StringLength(500)] [Display(Name = "Notes/Instructions")] public string Observation { get; set; }}
For more advanced scenarios, consider extending the model:
public class PayMode{ public int Id { get; set; } public string Name { get; set; } public string Observation { get; set; } // Extended properties public bool IsActive { get; set; } = true; public decimal ProcessingFeePercentage { get; set; } public decimal MinimumAmount { get; set; } public decimal MaximumAmount { get; set; } public bool RequiresVerification { get; set; } public string IconUrl { get; set; } public int DisplayOrder { get; set; }}