/** * Updates local db using the Modiefied date in case of new or updated ingredients * */ private void SynchronizeIngredients() { LastUpdate = new DateTime(1983, 11, 20); if (dataHandler.QueryIngredients().Count > 0) { LastUpdate = dataHandler.QueryIngredients().OrderByDescending(i => i.Modified).Select(j => j.Modified.GetValueOrDefault()).First(); } List <Ingredient> ServerIngredients = serviceHandler.CallService <List <Ingredient> >(@"QueryIngredients"); if (ServerIngredients != null) { List <Ingredient> newIngredients = ServerIngredients.Where(i => i.Modified > LastUpdate).Select(j => j).ToList(); foreach (var item in newIngredients) { if (dataHandler.QueryIngredients().Where(p => p.IngredientId.Equals(item.IngredientId)).Count() == 0) { if (dataHandler.InsertIngredient(item)) { IngredientInformer.Invoke(); } } else { if (dataHandler.UpdateIngredient(item)) { IngredientInformer.Invoke(); } } } } }
public List <Ingredient> QueryIngredients() { GetSynchronizerStatus(); if (connected) { return(serviceHandler.CallService <List <Ingredient> >(@"QueryIngredients")); } else { return(localDH.QueryIngredients()); } }
private void SyncronizeIngrdients() { //Get latest Date when the list was synchronized DateTime LastIngredientUpdate = dataHandler.QueryIngredients().OrderByDescending(i => i.DatedModified).Select(j => j.DatedModified).First(); List <Ingredient> ServerIngredients = (List <Ingredient>)serviceHandler.CallService <List <Ingredient> >(@"QueryIngredients"); List <Ingredient> newIngredients = ServerIngredients.Where(i => i.DatedModified > LastIngredientUpdate).Select(j => j).ToList(); if (newIngredients.Count > 0) { foreach (var item in newIngredients) { dataHandler.AddIngredient(item); } } }