Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/interezante456-pixel/nuevo-proyecto-viernes/llms.txt

Use this file to discover all available pages before exploring further.

Categories are the primary way to group products in Tienda Mi Cholo’s inventory. Every product must belong to exactly one category, and the selected category is shown as an amber badge in the product list table. Categories also act as a grouping dimension in the dashboard’s low-stock summary, making it easier to spot which product segments are running low. All authenticated users can view the category list; creating, editing, and deleting categories is restricted to the Administrador and Gerente roles.

Default Categories

The application seeds six categories into the database on first run. These cover the typical product range of a neighborhood convenience store:
IDNombreDescripción
1LácteosLeche, queso, yogurt y derivados
2BebidasGaseosas, jugos, agua y bebidas
3SnacksGalletas, papas, dulces y golosinas
4LimpiezaDetergentes, lejía, jabones
5AbarrotesArroz, azúcar, aceite, fideos
6Frutas y VerdurasProductos frescos del día
Create all the categories your store needs before you start adding products. The product creation form requires a category selection from this list, and there is no option to add a new category inline from the product form.

Category Fields

Each category carries two user-facing fields, as defined in the Categoria model:
NombreCategoria
string
required
The category name shown throughout the system — in the product list badge, the product form dropdown, and the dashboard tables. Maximum 50 characters. Must be unique enough to be meaningful at a glance (e.g., Lácteos, Bebidas).
Descripcion
string
An optional description of what products belong to this category. Maximum 200 characters. Displayed in the category list table to help staff understand the scope of the category.
The ID_Categoria primary key is auto-generated by SQL Server (IDENTITY) and is never entered manually.

Managing Categories

1

View the category list

Navigate to /Categoria/Lista. The table displays the ID, name, and description of every category. All authenticated users can access this page.
2

Create a new category

Click Nueva Categoría (visible only to Administrador and Gerente). Fill in:
  • NombreCategoria — required, up to 50 characters.
  • Descripción — optional, up to 200 characters.
Submit the form to save. The controller adds the record and redirects to the list:
[Authorize(Roles = "Administrador,Gerente")]
[HttpPost]
public async Task<IActionResult> Nuevo(Categoria categoria)
{
    await _context.Categorias.AddAsync(categoria);
    await _context.SaveChangesAsync();
    return RedirectToAction(nameof(Lista));
}
3

Edit an existing category

Click the Editar button on any category row. The edit form is pre-filled with the current NombreCategoria and Descripcion. Save to persist the changes:
[Authorize(Roles = "Administrador,Gerente")]
[HttpPost]
public async Task<IActionResult> Editar(Categoria categoria)
{
    _context.Categorias.Update(categoria);
    await _context.SaveChangesAsync();
    return RedirectToAction(nameof(Lista));
}
Renaming a category is safe — the ID_Categoria foreign key used in the Producto table does not change.
4

Delete a category

Click the Eliminar button on any category row. A JavaScript confirmation dialog appears before the deletion is processed. See the warning below before proceeding.
Deleting a category that has products assigned to it will cause a referential integrity error in SQL Server. The Producto table holds a foreign key (Categoria_ID) that references Categoria.ID_Categoria. If any products belong to the category you are trying to delete, the database will reject the operation. Before deleting a category, reassign or delete all products in that category first.

Category in the Product Form

When a user with the Administrador or Gerente role opens the Nuevo Producto or Editar Producto form, the controller loads all categories from the database and passes them to the view:
ViewBag.Categorias = _context.Categorias.ToList();
The view renders them as a <select> dropdown:
<select asp-for="Categoria_ID" class="form-select-dark w-100" required>
    <option value="">Seleccione</option>
    @foreach (var cat in ViewBag.Categorias)
    {
        <option value="@cat.ID_Categoria">@cat.NombreCategoria</option>
    }
</select>
A product must have exactly one category — the field is required and the form will not submit without a selection. The chosen category name is then displayed as an amber badge next to the product name in the product list.

One category per product

The Categoria_ID foreign key on Producto is not nullable. Every product must be assigned to a category at creation time and must always have one when edited.

Category badge in the list

The category name appears as a styled amber badge (badge-amber) in the Categoría column of the product list, giving staff an instant visual grouping of each item.

Access Control Summary

OperationRoles allowed
View category list (Lista)All authenticated users
Create category (Nuevo)Administrador, Gerente
Edit category (Editar)Administrador, Gerente
Delete category (Eliminar)Administrador, Gerente
The CategoriaController is decorated with [Authorize] at the class level, ensuring unauthenticated users are redirected to the login page. Mutating actions additionally carry [Authorize(Roles = "Administrador,Gerente")].

Build docs developers (and LLMs) love