Table of Contents

Class ItemCategoriesController

Namespace
KadicErp.WebApi.Controllers.Catalog
Assembly
KadicErp.WebApi.dll
[Route("api/[controller]")]
[Authorize]
public class ItemCategoriesController : GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>
Inheritance
object
ControllerBase
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>
ItemCategoriesController
Inherited Members
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.Sender
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.CreateGetByIdQuery(Guid)
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.CreateGetAllQuery(PaginatorRequestDto, bool?)
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.SetCommandId(UpdateItemCategoryCommand, Guid)
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.HandleCommandResult(Result)
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.HandleCommandResult<T>(Result<T>, string)
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.Create(CreateItemCategoryCommand)
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.Update(Guid, UpdateItemCategoryCommand)
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.GetById(Guid)
GenericCrudControllerBase<ItemCategoryDto, CreateItemCategoryCommand, UpdateItemCategoryCommand, GetItemCategoryByIdQuery, GetAllItemCategoriesQuery>.GetAll(PaginatorRequestDto, bool?)

Constructors

ItemCategoriesController(ISender, ICurrentUser, ITenantIdContext, IStringLocalizer<GeneralMessages>)

public ItemCategoriesController(ISender sender, ICurrentUser currentUser, ITenantIdContext tenantContext, IStringLocalizer<GeneralMessages> localizer)

Parameters

sender ISender
currentUser ICurrentUser
tenantContext ITenantIdContext
localizer IStringLocalizer<GeneralMessages>

Methods

Activate(Guid)

[HttpPatch("{id}/activate")]
[Authorize(Policy = "CATALOG_ITEM_CATEGORIES_ACTIVATE")]
public Task<IActionResult> Activate(Guid id)

Parameters

id Guid

Returns

Task<IActionResult>

Create(CreateItemCategoryCommand)

POST endpoint for creating a new entity. Returns 201 Created with Location header on success.

IMPORTANT: Override in derived class to add [HttpPost] and [Authorize(Policy = ...)]

[HttpPost]
[Authorize(Policy = "CATALOG_ITEM_CATEGORIES_CREATE")]
[ProducesResponseType(typeof(Result<Guid>), 201)]
[ProducesResponseType(typeof(Result), 400)]
[ProducesResponseType(typeof(Result), 409)]
public override Task<IActionResult> Create(CreateItemCategoryCommand command)

Parameters

command CreateItemCategoryCommand

Returns

Task<IActionResult>

Deactivate(Guid)

[HttpPatch("{id}/deactivate")]
[Authorize(Policy = "CATALOG_ITEM_CATEGORIES_DEACTIVATE")]
public Task<IActionResult> Deactivate(Guid id)

Parameters

id Guid

Returns

Task<IActionResult>

GetAll(PaginatorRequestDto, bool?)

GET endpoint for retrieving paginated list of entities. Supports optional isActive filter.

IMPORTANT: Override in derived class to add [HttpGet] and [Authorize(Policy = ...)] Override CreateGetAllQuery if you need additional filters. Note: ProducesResponseType attributes cannot be added here due to generic type parameters. Add them in derived class if needed for Swagger documentation.

[NonAction]
public override Task<IActionResult> GetAll(PaginatorRequestDto paginator, bool? isActive = null)

Parameters

paginator PaginatorRequestDto
isActive bool?

Returns

Task<IActionResult>

GetAll(PaginatorRequestDto, bool?, CancellationToken)

[HttpGet]
[Authorize(Policy = "CATALOG_ITEM_CATEGORIES_VIEW")]
[ProducesResponseType(typeof(PaginatorResponseDto<ItemCategoryDto>), 200)]
[ProducesResponseType(typeof(Error), 400)]
public Task<IActionResult> GetAll(PaginatorRequestDto paginator, bool? isActive = null, CancellationToken cancellationToken = default)

Parameters

paginator PaginatorRequestDto
isActive bool?
cancellationToken CancellationToken

Returns

Task<IActionResult>

GetById(Guid)

GET endpoint for retrieving a single entity by ID. Returns 404 Not Found if entity doesn't exist.

IMPORTANT: Override in derived class to add [HttpGet("{id}")] and [Authorize(Policy = ...)] Note: ProducesResponseType attributes cannot be added here due to generic type parameters. Add them in derived class if needed for Swagger documentation.

[HttpGet("{id}")]
[Authorize(Policy = "CATALOG_ITEM_CATEGORIES_VIEW")]
[ProducesResponseType(typeof(ItemCategoryDto), 200)]
[ProducesResponseType(typeof(Error), 404)]
public override Task<IActionResult> GetById(Guid id)

Parameters

id Guid

Returns

Task<IActionResult>

SetCommandId(UpdateItemCategoryCommand, Guid)

Updates the command with the ID from route. This method must be overridden in derived classes to properly set the Id.

For record types with 'with' expression, use:

protected override UpdateXCommand SetCommandId(UpdateXCommand command, Guid id)
    => command with { Id = id };
protected override UpdateItemCategoryCommand SetCommandId(UpdateItemCategoryCommand command, Guid id)

Parameters

command UpdateItemCategoryCommand
id Guid

Returns

UpdateItemCategoryCommand

Update(Guid, UpdateItemCategoryCommand)

PUT endpoint for updating an existing entity. Returns 200 OK on success.

IMPORTANT: Override in derived class to add [HttpPut("{id}")] and [Authorize(Policy = ...)]

[HttpPut("{id}")]
[Authorize(Policy = "CATALOG_ITEM_CATEGORIES_UPDATE")]
[ProducesResponseType(typeof(Result), 200)]
[ProducesResponseType(typeof(Result), 400)]
[ProducesResponseType(typeof(Result), 404)]
[ProducesResponseType(typeof(Result), 409)]
public override Task<IActionResult> Update(Guid id, UpdateItemCategoryCommand command)

Parameters

id Guid
command UpdateItemCategoryCommand

Returns

Task<IActionResult>