0

I have created a web api with Individual User authentication. After user get registered his information is stored in 2 tables, his general information is stored in "AspNetUsers" table and his role is stored in "AspNetUserRoles" table. Now the problem is when I am trying to delete any user from the list, its not working.Here is the delete action:

[ResponseType(typeof(AspNetUser))]
        [ActionName("EmployeeInfo")]
        [DeflateCompression]
        public IHttpActionResult DeleteEmployeeInformation(string Id)
        {

                AspNetUser AspNetUser = db.AspNetUsers.Find(Id);
                if (AspNetUser == null)
                {
                    return NotFound();
                }

                db.AspNetUsers.Remove(AspNetUser);
                db.SaveChanges();

                return Ok(AspNetUser);

        }

and here is the ajax call:

 function DeleteEmployeeInformations(recordID) {
        jQuery.support.cors = true;
        var id = recordID

        $.ajax({
            url: 'http://localhost:61115/api/EmployeeInformations/EmployeeInfo/' + id,
            type: 'DELETE',
            contentType: "application/json;charset=utf-8",
            success: function (data) {
                GetAllEmployeeInformations();
            },
            error: function (x, y, z) {
                alert(x + '\n' + y + '\n' + z);
            }
        });
    }

This action is working fine without asp.net identity but its not working when I am using asp.net identity. So what should I do? Thanks.

hutchonoid
  • 32,982
  • 15
  • 99
  • 104
Diamond Stone
  • 115
  • 3
  • 9

1 Answers1

0

The AspNetUser and associated tables are supposed to be accessed using the ASP .NET Identity framework.

This would involve using specific classes in order to perform CRUD operation on User, Roles etc. In this case it would be a UserManager.

This article is an introduction to that:

Introduction to ASP.NET Identity

In order to delete a User, you would use the UserManager.Delete method. You would also need to check and remove any existing roles via the UserManager too.

There is a very good example on GitHub which shows the common features that I found useful to get started.

AspnetIdentitySample

hutchonoid
  • 32,982
  • 15
  • 99
  • 104