mardi 4 août 2015

Angularjs Web Api Multpli Post action

i am beginner in Angularjs i want to in my web api controller two post methods one for registration and another one for login.there are my web api controller have two post methods

  //[EnableCors(origins: "*", headers: "*", methods: "*")]
   // [ActionName("register")]
   // [HttpPost]
    public HttpResponseMessage PostRegister(Users Student)
    {
        if (ModelState.IsValid)
        {
            Random rnd = new Random();
            int card = rnd.Next(52);
            Student.user_id = card;
            // _usertManager.AddUser(Student);
            var activateToken = WebSecurity.CreateUserAndAccount(Student.user_mail, Student.password, Student);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, Student);
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = Student.user_id }));
            //  _mailManager.Sendmail("salah.rzzaz90@gmail.com", "salahsayedrzzaz@gmail.com","dd","dd");
            return response;
        }
        else
        {
            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
    }
    ////[EnableCors(origins: "*", headers: "*", methods: "*")]
    //[ActionName("Login")]
    //[HttpPost]
    public HttpResponseMessage PostLogin(string userMaill, string passwordd)
    {
        if (ModelState.IsValid)
        {
            _usertManager.Login(userMaill, passwordd);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, userMaill);
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { userMaill = userMaill }));
            return response;
        }
        else
        {
            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
    }

my angular service : this.post = function (Users) { var request = $http({ method: "post", url: "/api/HomeApi", data:Users }); return request; } this.post = function (userMaill, passwordd) { var request = $http({ method: "post", url: "/api/HomeApi", data: { userMaill: userMaill, passwordd: passwordd } }); return request; }

my angular controller :

$scope.save = function () {
    var Users = {
        user_id: $scope.user_id,
        user_mail: $scope.user_mail,
        fullname: $scope.fullname,
        mobile: $scope.mobile,
        secondmail: $scope.secondmail,
        password: $scope.password,
        type: $scope.type


    };

        var promisePost = CRUD_OperService.post(Users);
        promisePost.then(function (pl) {
            $scope.user_id = pl.data.user_id;
            GetAllRecords();
            $scope.Message = "Student Updated Successfuly";
            ClearModels();
        }, function (err) {
            console.log("Err" + err);
        });

};



$scope.login = function () {

    var userMaill = $scope.userMaill;
    var passwordd = $scope.passwordd;


    var promisePost = CRUD_OperService.put(userMaill, passwordd);
    promisePost.then(function (pl) {
        $scope.user_id = pl.data.user_id;
        GetAllRecords();
        $scope.Message = "done";
        ClearModels();
    }, function (err) {
        console.log("Err" + err);
    });

};

My problem that when i click register and login scope it call PostRegister




Aucun commentaire:

Enregistrer un commentaire