question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I can not insert, delete or update data Web API Service.

See original GitHub issue

Hello! 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);
    }

image image image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Severanincommented, Oct 30, 2018

T685999

0reactions
sometimesElencommented, Oct 31, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found