0

I want to create an application with JayData + WCF/RIA Services but i need to detect the changes in the client side (Javascript) entities to put the business logic on the server side.

E.g: if i change a name of a customer, i want to do some validation before i update it on the server.

Is there anyway to do something like this?

    [Insert]
    public void InsertCustomer(Customer customer)
    {
        // Some validation before insert
    }

    [Update]
    public void UpdateCustomer(Customer customer)
    {
        // Some validation before update
    }

    [Delete]
    public void DeleteCustomer(Customer customer)
    {
        // Some validation before delete
    }
Kaffee Bohne
  • 1,457
  • 3
  • 14
  • 17

2 Answers2

0

Maybe this is not what you need but I give a shot: you can validate fields on the client with a custom validator function attached to the field. Here is how you do it: After importing the data context with JaySvcUtil.exe modify the entity and decorate the field with a customValidator:

$data.Entity.extend("UserModel", {
    Id: { type: "int", key: true, computed: true },
    UserName: { type: "string", required: true,
               customValidator: function (v) { return !v || v.length == 3 }, 
               errorMessage: "custom error, length: 3" }
});

In the current version there is no entity level validation functions. If you want them to be, submit a user story on JayData.org/backlogs or an issue at github.com/jaydata/jaydata

Peter Aron Zentai
  • 11,482
  • 5
  • 41
  • 71
  • I need to ensure that a user cannot modifiy another user's data (server side validation). It seems it's work very well with Interceptions: http://blogs.microsoft.co.il/blogs/gilf/archive/2008/11/01/interceptions-in-ado-net-data-services.aspx – Kaffee Bohne Jun 11 '12 at 15:58
  • 1
    What authentication do you use? When you write WCF Ria Services do you actually mean WCF Data Services + EntityFramework? Ria Services is for Silverlight (mainly) and can not be used together with JayData. WCF Data Services is what provides OData. – Peter Aron Zentai Jun 12 '12 at 07:01
  • Thanks for the comment - I was wondering if I can get RIA Services working with JayData. – John Mar 28 '15 at 19:06
0

To address this securely you need to do it on the server side (and not in JayData) and you need to implement authentication either on .NET way or on you own Then have a check in the onupdate server side method and make something like this:

C# code:

[Insert]
public void InsertCustomer(Customer customer) {
    if (! customer.LoginName == Thread.CurrentPrincipal.Identity.Name ) {
      throw new SomeValidtionException()
    }
}

Is this what you need?

Peter Aron Zentai
  • 11,482
  • 5
  • 41
  • 71