public ActionResult Login()
        {
            //user_name=userapi
            //password=T3s@m321
            //contentType=json

            //http://vdms5.tesacom.net/abm/abm_equipos.php
            //oper=exists
            //ESN=123123123123
            //contentType=json

            //http://vdms5.tesacom.net/abm/abm_equipos.php
            //oper=add
            //TipoEQP=10004
            //ESN=123123123123
            //IMSI=123123123123
            //contentType=json
            try {
                if (Session["Logueado"] != null) {

                    if (Session["Logueado"].ToString() == "True")
                    {
                        string imei = "";//"300215010568090";
                        uint phoneCode = 0;
                        uint hashvar1 = 0;
                        uint hashvar2 = 0;
                        Encoding unicode = Encoding.Unicode;
                        Encoding utf8 = Encoding.UTF8;
                        crc_32c hash = new crc_32c();
                        if (Request.Form["Imei"] != null && Request.Form["PhoneCode"] != null)
                        {
                            imei = Request.Form["Imei"].ToString();
                            string insertImei = String.Format("IE{0}", imei);
                            phoneCode = Convert.ToUInt32(Request.Form["PhoneCode"]);
                            byte[] imeib = GetBytes(imei);
                            imeib = Encoding.Convert(unicode, utf8, imeib);
                            hashvar1 = hash.toHash1(imeib, imeib.Length);

                            if (hashvar1 == phoneCode)
                            {
                                hashvar2 = hash.toHash2(imeib, imeib.Length);
                                //POST("http://vdms5.tesacom.net/abm/abm_equipos.php", JsonConvert.SerializeObject(json));
                                string oper = "exists";
                                int tipoEq = 10004;
                                string result = "";

                                string loginState = GET("http://vdms5.tesacom.net/login.php?user_name=userapi&password=T3s@m321");

                                string url = String.Format("http://vdms5.tesacom.net/abm/abm_equipos.php?oper={0}&ESN={1}&contentType=json",oper,insertImei);
                                string jsonExists = GET(url);
                                try
                                {
                                    JObject jsonData = new JObject();
                                    jsonData = JObject.Parse(jsonExists);
                                    foreach (JProperty jsonProperty in jsonData.Children().ToList())
                                    {
                                        if (jsonProperty.Name.ToString() == "success")
                                        {
                                            result = jsonProperty.Value.ToString();
                                            logs.Add(string.Format("Se consultó si existía el equipo con IMEI{0} y el resultado es success:{1}", insertImei, jsonProperty.Value.ToString()));
                                            logs = saveLogs(logs);
                                        }
                                    }
                                }
                                catch (Exception ex) { }
                                 if (result == "false")
                                 {
                                     oper = "add";
                                     loginState = GET("http://vdms5.tesacom.net/login.php?user_name=userapi&password=T3s@m321");

                                     url = String.Format("http://vdms5.tesacom.net/abm/abm_equipos.php?oper={0}&TipoEQP={1}&ESN={2}&IMSI={3}&contentType=json", oper, tipoEq, insertImei, insertImei);

                                     string jsonAddEquip = GET(url);
                                     try
                                     {
                                         JObject jsonData = new JObject();
                                         jsonData = JObject.Parse(jsonAddEquip);
                                         foreach (JProperty jsonProperty in jsonData.Children().ToList())
                                         {
                                             if (jsonProperty.Name.ToString() == "success")
                                             {
                                                 logs.Add(string.Format("El alta del equipo con IMEI{0} se ha efectuado con el siguiente resultado success:{1}",insertImei,jsonProperty.Value.ToString()));
                                                 logs = saveLogs(logs);
                                             }

                                         }
                                     }
                                     catch (Exception ex) { }

                                     ViewData["Estado"] = "OK";
                                     ViewData["Validar"] = String.Format("Portal Code :: {0}. Enter this number into your phone to complete the registration.", hashvar2);
                                 }
                                 else {
                                     ViewData["Estado"] = "";
                                     ViewData["Validar"] = String.Format("Error :: The handset with the IMEI{0} is already registered.",imei);
                                 }

                            }
                            else
                            {
                                ViewData["Validar"] = "Error :: Please enter a valid Phone Code.";
                                ViewData["Estado"] = "";
                            }

                        }
                        else
                        {
                            ViewData["Validar"] = "Error :: Please enter a valid Imei and Phone Code.";
                            ViewData["Estado"] = "";
                        }
                    }
                    else
                    {
                        ViewData["Validar"] = "Error :: You must be logged to register the handset.";
                        ViewData["Estado"] = "";
                        logs.Add(string.Format("El usuarioapi no se logueo success:{0}", Session["Logueado"].ToString()));
                        logs = saveLogs(logs);
                    }
                }
                else
                {
                    ViewData["Validar"] = "Error :: You must be logged to register the handset.";
                    ViewData["Estado"] = "";
                    logs.Add(string.Format("El usuarioapi no se logueo session null"));
                    logs = saveLogs(logs);
                }

            }
            catch (Exception ex) {

            }
            return View("Index");
        }
        public ActionResult Login()
        {
            //user_name=userapi
            //password=T3s@m321
            //contentType=json

            //http://vdms.tesacom.net/abm/abm_equipos.php
            //oper=exists
            //ESN=123123123123
            //contentType=json

            //http://vdms.tesacom.net/abm/abm_equipos.php
            //oper=add
            //TipoEQP=10004
            //ESN=123123123123
            //IMSI=123123123123
            //contentType=json
            try {
                if (Session["Logueado"] != null) {

                    if (Session["Logueado"].ToString() == "True")
                    {
                        string imei = "";//"300215010568090";
                        int idProyecto = 0;
                        uint phoneCode = 0;
                        uint hashvar1 = 0;
                        uint hashvar2 = 0;
                        Encoding unicode = Encoding.Unicode;
                        Encoding utf8 = Encoding.UTF8;
                        crc_32c hash = new crc_32c();
                        if (Request.Form["Imei"] != null && Request.Form["PhoneCode"] != null && Request.Form["Imei"] != "" && Request.Form["PhoneCode"] != "" && Regex.IsMatch(Request.Form["Imei"], "^[0-9]*$") == true && Regex.IsMatch(Request.Form["PhoneCode"], "^[0-9]*$") == true)
                        {
                            imei = Request.Form["Imei"].ToString();

                            idProyecto = Convert.ToInt32(Request.Form["idProyecto"]); //DESPUES DESCOMENTALOOOOOOOOOOOOOOOOO

                            string insertImei = String.Format("IE{0}", imei);
                            phoneCode = Convert.ToUInt32(Request.Form["PhoneCode"]);
                            byte[] imeib = GetBytes(imei);
                            imeib = Encoding.Convert(unicode, utf8, imeib);
                            hashvar1 = hash.toHash1(imeib, imeib.Length);

                            if (hashvar1 == phoneCode)
                            {
                                hashvar2 = hash.toHash2(imeib, imeib.Length);
                                //POST("http://vdms.tesacom.net/abm/abm_equipos.php", JsonConvert.SerializeObject(json));
                                string oper = "exists";
                                int tipoEq = 10004;
                                string result = "";

                                string loginState = GET("http://vdms.tesacom.net/login.php?user_name=userapi&password=T3s@m321");

                                string url = String.Format("http://vdms.tesacom.net/abm/abm_equipos.php?oper={0}&ESN={1}&contentType=json",oper,insertImei);
                                string jsonExists = GET(url);
                                try
                                {
                                    JObject jsonData = new JObject();
                                    jsonData = JObject.Parse(jsonExists);
                                    foreach (JProperty jsonProperty in jsonData.Children().ToList())
                                    {
                                        if (jsonProperty.Name.ToString() == "success")
                                        {
                                            result = jsonProperty.Value.ToString();
                                            logs.Add(string.Format("Se consultó si existía el equipo con IMEI{0} y el resultado es success:{1}", insertImei, jsonProperty.Value.ToString()));
                                            logs = saveLogs(logs);
                                        }
                                    }
                                }
                                catch (Exception ex) { }
                                 if (result == "false")
                                 {
                                     oper = "add";
                                     loginState = GET("http://vdms.tesacom.net/login.php?user_name=userapi&password=T3s@m321");

                                     url = String.Format("http://vdms.tesacom.net/abm/abm_equipos.php?oper={0}&TipoEQP={1}&ESN={2}&IMSI={3}&idProyecto={4}&contentType=json", oper, tipoEq, insertImei, insertImei, idProyecto);

                                     string jsonAddEquip = GET(url);
                                     try
                                     {
                                         JObject jsonData = new JObject();
                                         jsonData = JObject.Parse(jsonAddEquip);
                                         foreach (JProperty jsonProperty in jsonData.Children().ToList())
                                         {
                                             if (jsonProperty.Name.ToString() == "success")
                                             {
                                                 logs.Add(string.Format("El alta del equipo con IMEI{0} se ha efectuado con el siguiente resultado success:{1}",insertImei,jsonProperty.Value.ToString()));
                                                 logs = saveLogs(logs);
                                             }
                                         }
                                     }
                                     catch (Exception ex) { }

                                     string dir = System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);//System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                                     if (net.Tesacom.IridiumExtremeUtilities.IridiumToMySQL.SendPortalStatusToHandset(imei, dir))
                                      {
                                          logs.Add("Se envio correctamente el email de Portal Status message");
                                          logs = saveLogs(logs);
                                      }
                                      else
                                      {
                                          logs.Add("No se envio el email de Portal Status message");
                                          logs = saveLogs(logs);
                                      }
                                     ViewData["Estado"] = "OK";
                                     ViewData["Validar"] = String.Format("Código del portal : {0}. Ingrese este número en su teléfono para completar la registración.", hashvar2);
                                 }
                                 else {

                                     ViewData["Estado"] = "";
                                     ViewData["Validar"] = String.Format("El equipo con IMEI{0} ya se encuentra registrado y su portal code es: {1}, debe ingresar otro.",imei,hashvar2);
                                 }

                            }
                            else
                            {
                                ViewData["Validar"] = "Por favor ingrese un Phone Code válido.";
                                ViewData["Estado"] = "";
                            }

                        }
                        else
                        {
                            ViewData["Validar"] = "Por favor ingrese un Imei y Phone Code válido.";
                            ViewData["Estado"] = "";
                        }
                    }
                    else
                    {
                        ViewData["Validar"] = "Se ha producido un error por favor actualice la página e intente nuevamente.";
                        ViewData["Estado"] = "";
                        logs.Add(string.Format("El usuarioapi no se logueo success:{0}", Session["Logueado"].ToString()));
                        logs = saveLogs(logs);
                    }
                }
                else
                {
                    ViewData["Validar"] = "Se ha producido un error por favor actualice la página e intente nuevamente.";
                    ViewData["Estado"] = "";
                    logs.Add(string.Format("El usuarioapi no se logueo session null"));
                    logs = saveLogs(logs);
                }

            }
            catch (Exception ex) {
                ViewData["Validar"] = "Por favor ingrese un Imei y Phone Code válido.";
                ViewData["Estado"] = "";
            }
            return View("Index");
        }