public int[] GetByTestDemographic_Id(int test_id) {//////////obtiene el Id del demografico segun el test(rossana) /* Select Demographic_Id from DemographicsInTest where Test_Id=135 */ DemographicsInTestsServices demo = new DemographicsInTestsServices(); List <DemographicsInTest> demlist = demo.GetAllRecords().ToList(); List <DemographicsInTest> listfinal = new List <DemographicsInTest>(); int i = 0, contador = 0; var sql = ( from dem in demlist where dem.Test_Id == test_id select new { dem.Demographic_Id } ).Distinct().ToList(); ///obtiene los id de demografico que se tiene en DemographicsInTest por medicion(Test_Id) sin repetirse contador = sql.Count(); //cuenta los demografico que trajo la consulta anterior int[] num = new int[contador]; foreach (var qe in sql) { num[i] = qe.Demographic_Id; //listfinal.Add(num[i]); i++; } //select dem.Questionnaire_Id return(num); }
public bool deletebydemogandtest(DemographicsInTest entity)///borra de la tabla demographicsInTest aquellos campos que tengan el id de la medicion y el id del demografico enviado { try { /*_repository.Delete(entity.Id); * select Id from DemographicSelectorDetails * where Questionnaire_Id=31 AND Test_Id=134 AND Demographic_Id=2; * */ DemographicsInTestsServices demo = new DemographicsInTestsServices(); List <DemographicsInTest> demlist = demo.GetAllRecords().ToList(); List <DemographicsInTest> listfinal = new List <DemographicsInTest>(); int i = 0, contador = 0; var sql = ( from dem in demlist where dem.Test_Id == entity.Test_Id && dem.Demographic_Id == entity.Demographic_Id //&& dem.Selector == 0 select new { dem.Id } ).ToList(); ///obtiene los id de demografico que se tiene en DemographicSelectorDetails por medicion(Test_Id) y cuestionario(Questionnaire_Id) sin repetirse contador = sql.Count(); //cuenta los demografico que trajo la consulta anterior int[] num = new int[contador]; foreach (var qe in sql) { _repository.Delete(qe.Id);//borra uno a uno los demograficos en el test } SaveChanges(); } catch { return(false); } return(true); }
private void CreateDemographicsInTest(int test_id) { DemographicsInTestsServices dits = new DemographicsInTestsServices(); DemographicsInTest dit; int[] demographics = new int[7] { 1, 2, 3, 5, 7, 10, 11 }; bool b = true; foreach (int i in demographics) { dit = new DemographicsInTest(); dit.Demographic_Id = i; dit.Selector = false; dit.Test_Id = test_id; if (i == 11) { dit.FOT_Id = this.fotId; } b = b && dits.Add(dit); } this.Ok = b; }