1. Bernhard Stoeter
  2. SnapDevelop
  3. Thursday, 23 July 2020 14:34 PM UTC

Hi all,

I'm playing with the .NET DataWindow / SnapDevelop sample "CRUD Operations with .NET DataStore". How can I get back the new database generated identity value(s) of the inserted row(s)?

Bernhard

Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Friday, 24 July 2020 01:22 AM UTC
  2. SnapDevelop
  3. # 1

Hi Bernhard,

You can return the data needed in the Create action, refer to the following code:

// POST api/sample/create
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult Create([FromBody]D_Department department)
{
    try
    {
        int count = _sampleService.Create(department);

        if (count == 0)
        {
            return StatusCode(StatusCodes.Status500InternalServerError);
        }

        // Return HTTP code 201 with URI in the Header and model in the Body.
        return Created($"api/sample/retrieveone/{department.Departmentid}", department);
    }
    catch (Exception ex)
    {
        return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
    }
}

Regards,

Logan

Comment
  1. Bernhard Stoeter
  2. Thursday, 30 July 2020 12:26 PM UTC
Hi Logan,

thank you, I got it running.

Bernhard
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.