I can not insert, delete or update data Web API Service.
See original GitHub issueHello! I use in the project Dotnet Core 2.1.4 WebApi and Angular 6. I use devextreme-aspnet-data-nojquery. When loadUrl data is sent to the client, and when using insertUrl, updateUrl, deleteUrl, the data is not received by the server.
Client:
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { Api } from 'src/app/lib/_servers';
import CustomStore from 'devextreme/data/custom_store';
import { createStore } from 'devextreme-aspnet-data-nojquery';
@Component({
selector: 'app-building',
templateUrl: './building.component.html',
styleUrls: ['./building.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class BuildingComponent {
masterDetailDataSource: any;
dataSource: CustomStore;
constructor() {
this.dataSource = createStore({
key: 'id',
loadUrl: Api.uavr + '/JBuilding/load',
insertUrl: Api.uavr + '/JBuilding/InsertJBuilding',
updateUrl: Api.uavr + '/JBuilding/UpdateJBuilding',
deleteUrl: Api.uavr + '/JBuilding/DeleteSection',
onBeforeSend: function(method, ajaxOptions) {
const jwt = JSON.parse(localStorage.getItem('currentUser'));
ajaxOptions.xhrFields = { withCredentials: true };
ajaxOptions.headers = { 'Authorization': 'Bearer ' + jwt.token };
console.log(ajaxOptions);
}
});
}
}
Server
[HttpPut("UpdateJBuilding")]
public IActionResult UpdateJBuilding(int key, string values)
{
var section = _uavr.Jbuilding.FirstOrDefault(o => o.Id == key);
if (section == null)
return StatusCode(409, "Ошибка, раздел не найден");
JsonConvert.PopulateObject(values, section);
if (!TryValidateModel(section))
return BadRequest(ModelState.ToFullErrorString());
_uavr.SaveChanges();
return Ok();
}
[HttpPost("InsertJBuilding")]
public IActionResult InsertJBuilding(string values)
{
var newJBuilding = new Jbuilding();
JsonConvert.PopulateObject(values, newJBuilding);
if (!TryValidateModel(newJBuilding))
return BadRequest(ModelState.ToFullErrorString());
_uavr.Jbuilding.Add(newJBuilding);
_uavr.SaveChanges();
return Ok();
}
[HttpDelete("DeleteSection")]
public IActionResult DeleteSection(int key)
{
var jBuilding = _uavr.Jbuilding.FirstOrDefault(o => o.Id == key);
// if (jBuilding == null)
// return StatusCode(409, "Раздел не найден");
_uavr.Jbuilding.Remove(jBuilding);
_uavr.SaveChanges();
return Ok(key);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
PUT and Delete not working with ASP.NET WebAPI ...
I'm working on a ASP.NET WebAPI project with basic CRUD operations. The project runs locally and has a sample database living inside Windows ......
Read more >Update and delete table rows using the Web API
Read how to perform update and delete operations on tables using the Web API.
Read more >How to: Update, Insert, and Delete Data with the ...
With the LinqDataSource control, you can create Web pages that enable users to update, insert, and delete data. You do not have to...
Read more >Insert, Update, and Delete Data Using RESTful Services
In the RESTful Services navigator, right-click locations/:id, select Add Handler and then select DELETE. Click Apply.
Read more >Update & Remove Entities in .NET Core 3.1 Web API with ...
We create the new C# class UpdateCharacterDto and actually can copy and paste all properties from the GetCharacterDto . public class ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
T685999
Hi, Thank you for creating a ticket in our Support Center. We need additional time to research it.
We also kindly ask you to continue our communication in the context of the T685999 thread. Feel free to contact us there if you have any further questions.