示例#1
0
 public static List <int> GetDates()
 {
     using (var db = new DatasetContext())
     {
         Console.WriteLine($"{DateTime.Now} | DB | Query Dates");
         // a list of every stored dataset's date
         return(db.Datasets.Select(x => x.EffectiveDate).ToList());
     }
 }
示例#2
0
 public static Dataset Retrieve(int effective)
 {
     using (var db = new DatasetContext())
     {
         Console.WriteLine($"{DateTime.Now} | DB | Query Dataset #{effective}");
         // if the date exists, return it
         // otherwise, return empty set
         var single = db.Datasets.Build().SingleOrDefault(x => x.EffectiveDate == effective);
         if (single != default)
         {
             return(single);
         }
         else
         {
             return new Dataset()
                    {
                        EffectiveDate = effective
                    }
         };
     }
 }
示例#3
0
        public static void Capture()
        {
            Console.WriteLine($"{DateTime.Now} | DB  | Save Dataset #{Sources.Today.EffectiveDate}");
            int effective = DateTime.Now.ConvertToEffective();

            using (var db = new DatasetContext())
            {
                // if the data set exists, update it
                // otherwise, insert it
                var single = db.Datasets.SingleOrDefault(x => x.EffectiveDate == effective);
                if (single != default)
                {
                    single.Trips = Sources.Today.Trips;
                }
                else
                {
                    db.Datasets.Add(Sources.Today);
                }

                db.SaveChanges();
            }
        }