This is a migrated thread and some comments may be shown as answers.

Update odata v4 with patch method

1 Answer 343 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 22 Aug 2016, 09:52 AM

Hi I am able to call my odata controller with the correct key but I am missing the payload, so delta is null.

How can I set the payload? and also return the updated entity?

datasource definition:

var baseUrl = "odata/reports",
            dataSource = new kendo.data.DataSource({
                type: "odata-v4",
                transport: {
                    read: {
                        url: baseUrl,
                        dataType: "json"
                    },
                    update: {
                        url: (data) => {
                            return baseUrl + "(" + data.models[0].Id + ")";
                        },
                        dataType: "json",
                        type: "PATCH"
                    },
                    destroy: {
                        url: baseUrl,
                        dataType: "json",
                        type: "DELETE"
                    },
                    create: {
                        url: baseUrl,
                        dataType: "json",
                        type: "POST"
                    }
                },

 

webapi odata controller:

public IHttpActionResult Patch(int key, Delta<T> delta)
        {
            Validate(delta.GetEntity());


            if (!ModelState.IsValid)
                return BadRequest(ModelState);


            var entity = Repository.GetByKey(key);
            if (entity == null)
                return NotFound();


            if (!AuthenticationService.HasWriteAccess(CurentUser, entity))
                return Unauthorized();


            try
            {
                delta.Patch(entity);
                Repository.Save();
            }
            catch (Exception e)
            {
                return InternalServerError(e);
            }
            return Updated(entity);
        }

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 24 Aug 2016, 07:44 AM

Hello Martin,

Please refer to our Odata 4 with WebAPI controller project which demonstrates how to implement CRUD operations with Kendo UI Grid OData -v4 and web api. 

Regards,
Boyan Dimitrov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or