// GET: Home public ActionResult Index() { string config = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "YourCredentials.json"); DateTime LastDateUpdated = DateTime.Parse("2016-01-01"); using (var ctx = new AdExContext()) { var date= ctx.AdExStats.OrderByDescending(x => x.Date).Select(x => x.Date).FirstOrDefault(); if(date != default(DateTime)) { LastDateUpdated = date; } } //Get and update data from Google ADX IntegrationAPI api = new IntegrationAPI(config); var googledata=api.FetchAdexchangeData(LastDateUpdated.ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd")); api.UpdateData(googledata); //Hardcoded, dont have UI right now //Will get from UI: DateRange, TagID DateRange range = new DateRange(); range.DateFrom = DateTime.Parse("2016-01-01"); range.DateTo = DateTime.Parse("2016-01-12"); long Tagid = 4642798920; api.GenerateReport(ReportType.ConcreteSiteByFormatsByMonth, range, Tagid); return View(); }
static public bool UpdateAdx(List<AdExGoogleStats> data) { try { if (data != null || data.Count !=0) { using (var ctx = new AdExContext()) { foreach (var item in data) { if (ctx.AdExStats.Any(x=>x.Id == item.Id && x.Date==item.Date && x.Size == item.Size)) { ctx.Entry(item).State = EntityState.Modified; } else { ctx.AdExStats.Add(item); } ctx.SaveChanges(); } Logger.Write("DataUpdated", "DataUpdated"); return true; } } } catch(Exception ex) { Logger.Write("ex_DataUpdated", ex.Message); return false; } return false; }