3

There is a crud operations in default Single Page Application template of ASP.NET MVC 4 as below.

upshot.js is interacted with response from DbDataController's actions and if operation fails then upshot.js takes validation errors and it is able to show on client side.

What i need to do is putting my own business rules in operations. But it is not clear that where to put validation errors in DbDataController.

For example : InsertEntity(entity); Operation can put validation errors if it fails and validation errors sent to client automaticly. But i want to put my business validation errors if it is occur. 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);
    }
}

1 Answers1

0

Check Fluent Validation, there is nothing better and easier!

Novkovski Stevo Bato
  • 1,013
  • 1
  • 23
  • 56