0

I Want to execute second Login(contactnumber,password) but after passing the argument it is still calling the list login method How to resolve this?

[HttpGet]
            public IEnumerable<UserDetail> Login()
            {
                using (HeandSheEntities entities = new HeandSheEntities())
                {
                    return entities.UserDetails.ToList();
                }
            }
            [System.Web.Http.AcceptVerbs("GET")]
            [System.Web.Http.HttpGet]
            public HttpResponseMessage Login(String ContactNumber, String Password)    {
                {  String Upass = encryption(Password);
                    using (HeandSheEntities entities = new HeandSheEntities())
                    {
                        bool userphone = entities.UserDetails.Any(u => u.UserContactNumber.Equals(ContactNumber));
                        bool userpass = entities.UserDetails.Any(u => u.UserPassword.Equals(Upass));
                        if (ModelState.IsValid && userphone && userpass)
                        {
                           var user = entities.UserDetails.FirstOrDefault(u => u.UserContactNumber.Equals(ContactNumber));
                            if (user != null)
                                return Request.CreateResponse(HttpStatusCode.OK, user, new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"));
                            else
                                return Request.CreateResponse(HttpStatusCode.BadRequest, "Either Contact Number or password is not correct", new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"));

                        }
                        else
                        {
                            return Request.CreateResponse(HttpStatusCode.BadRequest, "Either Contact Number or password is not correct", new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"));
                        }
                        }
                    }
           }
akjjain91
  • 11
  • 2

1 Answers1

0

You use the same name for both action methods with the same http verb. You cannot overload action methods. See here and here. Semantically you should use POST http method for changing state (for example logging user) and it will work.

[HttpPost]
public HttpResponseMessage Login(String ContactNumber, String Password) 
Ivan R.
  • 1,875
  • 1
  • 13
  • 11