Sobes.tech
Junior — Middle

Can you give an example where standard CRUD operations are combined with additional custom business logic?

sobes.tech AI

Answer from AI

Example of combining standard CRUD operations with additional business logic in C#:

public class OrderService
{
    private readonly IOrderRepository _repository;

    public OrderService(IOrderRepository repository)
    {
        _repository = repository;
    }

    public void CreateOrder(Order order)
    {
        // Business logic: check product availability
        if (!IsProductAvailable(order.ProductId, order.Quantity))
            throw new InvalidOperationException("Product not available in the required quantity");

        // Standard create operation
        _repository.Add(order);

        // Additional logic: notify user
        NotifyUser(order.UserId, "Your order has been created");
    }

    // Other CRUD methods with business logic
}

Here, creating an order is a CRUD operation, but before saving, business rules are checked, and after, a notification is sent.