How to use business validation in DbDataController?

The ASP.NET MVC 4 Single Page Application Template uses the crud command by default.

upshot.js interacts with the response from the actions of the DbDataController, and if the operation fails, then upshot.js accepts validation errors and can display on the client side.

What I need to do is put my own business rules in the operation. But it is unclear where to place validation errors in the DbDataController.

For example: An InsertEntity(entity);operation may put validation errors if it fails, and validation errors sent to the client automatically. But I want to put business verification errors if that happens. So where can I put it there?

public partial class TasksSPAController : DbDataController<MvcApplication8.Models.TasksSPAContext>
{
    public IQueryable<MvcApplication8.Models.TodoItem> GetTodoItems() {
        return DbContext.TodoItems.OrderBy(t => t.TodoItemId);
    }

    public void InsertTodoItem(MvcApplication8.Models.TodoItem entity) {
            //before this action i want to check business validation rules.
            // if it is not validated so i want to put errors to response 
            // that is usable by upshot.js
            InsertEntity(entity);
    }

    public void UpdateTodoItem(MvcApplication8.Models.TodoItem entity) {
        UpdateEntity(entity);
    }

    public void DeleteTodoItem(MvcApplication8.Models.TodoItem entity) {
        DeleteEntity(entity);
    }
}
+3
1

, !

0

All Articles