// GET: Prueba public async Task <ActionResult> Index() { if (Session["login"] != null) { Business.Data.Dominio.ApiHelper api = new Business.Data.Dominio.ApiHelper(); string url = "http://localhost:17045/Api/user"; using (HttpResponseMessage response = await Business.Data.Dominio.ApiHelper.ApiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { var resp = await response.Content.ReadAsStringAsync(); List <UsuariosCE> contributors = JsonConvert.DeserializeObject <List <UsuariosCE> >(resp); View(contributors); } } return(View()); } else { return(RedirectToAction("login", "loginController")); } }
public async Task <ActionResult> Login(userLoginCE model) { if (!ModelState.IsValid) { Business.Data.Dominio.ApiHelper api = new Business.Data.Dominio.ApiHelper(); string url = "http://localhost:17045/Api/login/Authenticate"; using (HttpResponseMessage response = await Business.Data.Dominio.ApiHelper.ApiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { RedirectToAction(""); } } return(View(model)); } else { return(View()); } }
public async Task <ActionResult> CrearUsuario(UsuariosCE usr) { if (ModelState.IsValid) { var json = JsonConvert.SerializeObject(usr); var data = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); Business.Data.Dominio.ApiHelper api = new Business.Data.Dominio.ApiHelper(); string url = "http://localhost:17045/Api/login/Crear"; using (HttpResponseMessage response = await Business.Data.Dominio.ApiHelper.ApiClient.PostAsync(url, data)) { if (response.IsSuccessStatusCode) { return(RedirectToAction("Index", "Prueba")); } } } return(View()); }
public async Task <ActionResult> login(userLoginCE model) { ViewBag.validacion = ""; if (ModelState.IsValid) { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); Business.Data.Dominio.ApiHelper api = new Business.Data.Dominio.ApiHelper(); string url = "http://localhost:17045/Api/login/Authenticate"; using (HttpResponseMessage response = await Business.Data.Dominio.ApiHelper.ApiClient.PostAsync(url, data)) { if (response.IsSuccessStatusCode) { // var result = response.Content.ReadAsStringAsync().Result; var resp = await response.Content.ReadAsStringAsync(); var details = JObject.Parse(resp); Session["login"] = details["data"]; return(RedirectToAction("Index", "Prueba")); } else { ViewBag.validacion = "Usuario o contraseña no son validos"; } } return(View(model)); } else { return(View()); } }