public IDandToken Registration(ClientDto userdto) { if (ModelState.IsValid == false) { return(new IDandToken()); } IdentityResult result = repos.CreateClient(userdto); if (result.Succeeded) { using (HttpClient httpClient = new HttpClient()) { Dictionary <string, string> tokenDetails = null; // var messageDetails = new Message { Id = 4, Message1 = des }; HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:4700/"); var login = new Dictionary <string, string> { { "grant_type", "password" }, { "username", userdto.Email }, { "password", userdto.Password }, }; var response = client.PostAsync("Token", new FormUrlEncodedContent(login)).Result; if (response.IsSuccessStatusCode) { tokenDetails = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content.ReadAsStringAsync().Result); if (tokenDetails != null && tokenDetails.Any()) { var tokenNo = tokenDetails.FirstOrDefault().Value; IdentityUser user = repos.Find(userdto.Email, userdto.Password); Client newclient = new Client { NationalID = userdto.NationalID, ClientName = userdto.Name, UserID = user.Id }; context.Clients.Add(newclient); context.SaveChanges(); return(new IDandToken { ID = user.Id, Token = tokenDetails.FirstOrDefault().Value }); } } } } return(new IDandToken()); }