// public JsonResult PegaColetores(int empresa) { string ret = string.Empty; List <ColetorModel> lista_retorno = new List <ColetorModel>(); // try { List <Coletor> lista_coletores = db.Coletor.Where(a => a.Id_Empresa == empresa && a.Id_Maquina == null).ToList(); // foreach (Coletor item in lista_coletores) { ColetorModel cm = new ColetorModel(); // cm.Id = item.Id; cm.Descricao = item.Descricao; // lista_retorno.Add(cm); } // ret = "ok"; } catch (Exception exc) { ret = exc.Message; } // return(Json(new { ret, lista_retorno, results = 1, success = true }, JsonRequestBehavior.AllowGet)); }
// public List <ColetorModel> CarregaDadosColetores() { List <Coletor> lista_coletores = new List <Coletor>(); List <EmpresaModel> lista_empresas = new List <EmpresaModel>(); List <ColetorModel> lista_coletor_models = new List <ColetorModel>(); // if (Codigo_Empresa > 0) { lista_coletores = db.Coletor.Where(a => a.Id_Empresa == Codigo_Empresa).ToList(); if (Tipo_Empresa == 1) { ViewBag.ShowCrudIncluir = "inline"; ViewBag.ShowCrudEditar = "inline"; ViewBag.ShowCrudExcluir = "inline"; Empresa empresa = db.Empresa.Where(x => x.Id == Codigo_Empresa).FirstOrDefault(); // EmpresaModel empresa_model = new EmpresaModel(); empresa_model.Id = empresa.Id; empresa_model.Nome = empresa.Nome; lista_empresas.Add(empresa_model); // string empresas = empresa.Empresas; if (!string.IsNullOrEmpty(empresas)) { string[] empresas_array = empresas.Split(','); int[] ids = Array.ConvertAll(empresas_array, s => int.Parse(s)); var lista_sub_empresas = db.Empresa.Where(r => ids.Contains(r.Id)); if (lista_sub_empresas.Any()) { List <Coletor> lista_sub_coletores = new List <Coletor>(); foreach (Empresa sub_empresa in lista_sub_empresas) { empresa_model = new EmpresaModel(); empresa_model.Id = sub_empresa.Id; empresa_model.Nome = sub_empresa.Nome; lista_empresas.Add(empresa_model); lista_sub_coletores = db.Coletor.Where(x => x.Id_Empresa == sub_empresa.Id).ToList(); lista_coletores.AddRange(lista_sub_coletores); } } } } else { ViewBag.ShowCrudIncluir = "none"; ViewBag.ShowCrudEditar = "none"; ViewBag.ShowCrudExcluir = "none"; } // string spossuiAlerta = string.Empty; foreach (Coletor item in lista_coletores) { ColetorModel oColetor = new ColetorModel(); // oColetor.Id = item.Id; oColetor.Id_Empresa = item.Id_Empresa.HasValue ? item.Id_Empresa.Value : Codigo_Empresa; oColetor.Id_Maquina = item.Id_Maquina; // oColetor.Empresa = item.Empresa.Nome; oColetor.Ativo = item.Ativo; oColetor.Descricao = item.Descricao; oColetor.MAC = item.MAC.ToUpper(); oColetor.Alerta = item.Alerta; int tot_alertas = db.ColetorAlerta.Where(x => x.Id_Coletor == item.Id && x.Id_Empresa == oColetor.Id_Empresa).ToList().Count; // if (item.Alerta.HasValue && item.Alerta.Value == 1) { spossuiAlerta = "Sim (" + tot_alertas + ")"; } else { spossuiAlerta = "Não (" + tot_alertas + ")"; } oColetor.PossuiAlerta = spossuiAlerta; // if (oColetor.Id_Maquina != null && oColetor.Id_Maquina > 0) { oColetor.Maquina = db.Maquina.Where(a => a.ID == oColetor.Id_Maquina).FirstOrDefault().Descricao; } // lista_coletor_models.Add(oColetor); } } // return(lista_coletor_models); }