Guest User

Untitled

a guest
Aug 22nd, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. public ActionResult Login(LoginM us)
  2. {
  3. try
  4. {
  5. cuentaM account = new cuentaM();
  6. HttpClient client = new HttpClient();
  7.  
  8. var result = client.GetAsync("http://localhost:26723/api/Login" + "?email=" + us.email + "&password=" + us.password).Result;
  9. if (result.IsSuccessStatusCode)
  10. {
  11. account = result.Content.ReadAsAsync<cuentaM>().Result;
  12. }
  13.  
  14. Session["cuenta"] = account;
  15. return RedirectToAction("Index", "Home");
  16. }
  17. catch (Exception ex)
  18. {
  19. throw;
  20.  
  21. }
  22. }
  23.  
  24. public HttpResponseMessage Get(string email, string password)
  25. {
  26. try
  27. {
  28. using (elevationbEntities db = new elevationbEntities())
  29. {
  30. usuario user = db.usuarios.Where(m => m.email == email && m.password == password).SingleOrDefault();
  31. cuentaM account = new cuentaM();
  32. if (user != null)
  33. {
  34. account = (from o in db.cuentas
  35. join cu in db.cuentausuarios on o.idCuenta equals cu.idCuenta
  36. join u in db.usuarios on cu.idUsuario equals u.idUsuario
  37. where u.idUsuario == user.idUsuario
  38. select new cuentaM { idUsuario = user.idUsuario, idCuenta = o.idCuenta, CodigoUnico = o.CodigoUnico })
  39. .FirstOrDefault();
  40. }
  41. else
  42. {
  43. account.Error = "Wrong Password or Email";
  44. }
  45.  
  46. HttpResponseMessage response;
  47. response = Request.CreateResponse(HttpStatusCode.OK, account);
  48. return response;
  49. }
  50. }
  51. catch (TaskCanceledException ex)
  52. {
  53.  
  54. HttpResponseMessage response;
  55. response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
  56. return response;
  57. }
  58.  
  59. }
Add Comment
Please, Sign In to add comment