Esempio n. 1
0
        public JObject Login(string usuario, string clave)
        {
            logs.Add(string.Format("Entro al login de usuario"));
            logs = saveLogs(logs);
            ASISTENCIAS_CAMMESA_ENTITIES ctx = new ASISTENCIAS_CAMMESA_ENTITIES();
            logs.Add(string.Format("Creo el contexto"));
            logs = saveLogs(logs);
            //ODBCDataService dataservice = new ODBCDataService(); 
            //USUARIO usuarioODBC = new USUARIO();
            try
            {
                USUARIO user = ctx.USUARIO.FirstOrDefault(p => (p.USUARIO1 == usuario && p.CLAVE == clave));
                if (user != null)
                {
                    var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
                    
                    JObject jsonObject = new JObject();
                    jsonObject.Add("id", user.ID);
                    jsonObject.Add("nombre", user.NOMBRE);
                    jsonObject.Add("apellido", user.APELLIDO);
                    jsonObject.Add("usuario", user.USUARIO1);
                    jsonObject.Add("clave", user.CLAVE);

                   // JObject json = JObject.Parse(user.ToJson<USUARIO>());
                    return jsonObject;
                }
                else {

                  //  var str = "{}";
                  //  JObject j = JObject.Parse(str);
                    return null;
                }
                // return await dataService.GetDocumentByID("AsistenciaCammesa", "Asistencia", clave, valor);
            }
            catch (Exception ex)
            {
                logs.Add(string.Format("Exception in Login  InnerException:{0}, Message:{1}, TargetSite:{2}, Source:{3}, StackTrace: {4}", ex.InnerException, ex.Message, ex.TargetSite, ex.Source, ex.StackTrace));
                logs = saveLogs(logs);
                var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(string.Format("Requested collection may be empty or Null")),
                    StatusCode = HttpStatusCode.NotFound,
                    ReasonPhrase = "Requested collection may be empty or Null"
                };
                logs.Add(string.Format("El resultado de la conexion a la base MONGO, HttpResponseMessage: {0}", resp));
                logs = saveLogs(logs);
                throw new HttpResponseException(resp);
            }
        }
Esempio n. 2
0
        public List<JObject> GetTareas(string usuario)
        {
            logs.Add(string.Format("Entro al login de usuario"));
            logs = saveLogs(logs);
            ASISTENCIAS_CAMMESA_ENTITIES ctx = new ASISTENCIAS_CAMMESA_ENTITIES();
            logs.Add(string.Format("Creo el contexto"));
            logs = saveLogs(logs);
            try
            {
                var usu = Convert.ToInt32(usuario);
                // db.Items.Where(x => x.userid == user_ID).Select(x => x.Id).Distinct();
                List<TAREA> tareas = ctx.TAREA.Where(p => p.ID_USUARIO == usu && p.ESTADO == 0 && p.DELETE == 0).ToList();
                List<JObject> list = new List<JObject>();
                if (tareas.Count > 0)
                {
                    foreach (TAREA tarea in tareas)
                    {

                        JObject jsonObject = new JObject();
                        jsonObject.Add("id", tarea.ID);
                        jsonObject.Add("fecha", tarea.FECHA);
                        jsonObject.Add("asunto", tarea.ASUNTO);
                        jsonObject.Add("prioridad", tarea.PRIORIDAD);
                        jsonObject.Add("estado", tarea.ESTADO);
                        jsonObject.Add("tecnico", tarea.USUARIO.APELLIDO);
                        jsonObject.Add("tarea", tarea.TAREA1);
                        list.Add(jsonObject);
                    }

                    return list;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                logs.Add(string.Format("Exception in Login  InnerException:{0}, Message:{1}, TargetSite:{2}, Source:{3}, StackTrace: {4}", ex.InnerException, ex.Message, ex.TargetSite, ex.Source, ex.StackTrace));
                logs = saveLogs(logs);
                var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(string.Format("Requested collection may be empty or Null")),
                    StatusCode = HttpStatusCode.NotFound,
                    ReasonPhrase = "Requested collection may be empty or Null"
                };
                logs.Add(string.Format("El resultado de la conexion a la base MONGO, HttpResponseMessage: {0}", resp));
                logs = saveLogs(logs);
                throw new HttpResponseException(resp);
            }
        }