public static GainEnergyCoinCollection LoadByAppartementDate(Appartement p_appartement, DateTime p_date)
        {
            GainEnergyCoinCollection l_result = new GainEnergyCoinCollection();

            GainEnergyCoinCollection l_intermediateResult = GainEnergyCoinCollection.LoadByAppartementDateRange(p_appartement, p_date);

            if (l_intermediateResult.Count > 0)
            {
                DateTime l_maxDate = l_intermediateResult.OrderBy(g => g.Date).Last().Date;
                l_result.AddRange(l_intermediateResult.Where(r => r.Date == l_maxDate));
            }

            return l_result;
        }
        public void Run()
        {
            foreach (string batCamelId in batiments)
            {
                // Création du batiment
                Batiment batiment = new Batiment();
                batiment.CamelId = batCamelId;
                batiment.Save();

                Log("création batiment A");

                foreach (string camelIdApart in batimentA)
                {
                    // Création de l'appartement
                    Appartement apart = new Appartement();
                    apart.Nom = camelIdApart;
                    apart.CamelId = camelIdApart;
                    apart.Batiment = batiment;
                    apart.Save();

                    Log("création apart " + camelIdApart);

                    foreach (string voie in voies)
                    {
                        // Récupération des mesures semaine par semaine
                        for (DateTime begin = new DateTime(2013, 6, 1); begin <= end; begin = begin.AddMonths(1))
                        {
                            CamelResponseResource l_res = CamelGet(batCamelId, camelIdApart, voie, begin, begin.AddMonths(1));

                            // Sauvegarde des mesures en base de données
                            if (l_res != null && l_res.error == null && l_res.result != null &&
                                l_res.result[0].chs != null && l_res.result[0].chs[0] != null &&
                                l_res.result[0].chs[0].vals != null && l_res.result[0].chs[0].vals.Length > 1)
                            {
                                foreach (vals values in l_res.result[0].chs[0].vals)
                                {
                                    DateTime date = DateTimeHelper.ConvertTimeStampToDateTime(values.date);
                                    Mesure mes = new Mesure();
                                    mes.Date = date;
                                    mes.Appartement = apart;
                                    mes.Type = voie;
                                    mes.Valeur = values.val;

                                    mes.Save();
                                }
                            }
                        }
                    }
                }
            }
        }