Example #1
0
        public static void UpdateGoogleMilesUri(int originKey, Dictionary <int, string> lookupDestinationDict, bool updateAll = false)
        {
            int destKey = 0;

            //bool updateAll = UpdateAll.IsChecked.Value;
            using (var mdc = new MilesDataContext())
            {
                foreach (var dest in lookupDestinationDict)
                {
                    destKey = dest.Key;

                    //Get the Mile Record
                    var mRec = from mtable in mdc.Miles
                               where mtable.FromId == originKey && mtable.ToId == destKey
                               select mtable;
                    foreach (Mile mile in mRec)
                    {
                        mile.GoogleUri = GoogleHelper.CreateGoogleMilesTableLink(originKey, mile.ToId);
                    }

                    //Submit changes to table
                    try
                    {
                        mdc.SubmitChanges();
                    }
                    catch (Exception exceptUpdate)
                    {
                        MessageBox.Show(exceptUpdate.Message.ToString());
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Method that updates the miles in the miles table
        /// </summary>
        /// <param name="originKey"></param>
        /// <param name="lookupOrigin"></param>
        /// <param name="lookupDestinationDict"></param>

        public static void UpdateMileage(int originKey, string lookupOrigin, Dictionary <int, string> lookupDestinationDict, bool updateAll = false)
        {
            int destKey = 0;

            using (var mdc = new MilesDataContext())
            {
                foreach (var dest in lookupDestinationDict)
                {
                    destKey = dest.Key;
                    if (updateAll)
                    {
                        //Get the Mile Record
                        var mRec = from mtable in mdc.Miles
                                   where mtable.FromId == originKey && mtable.ToId == destKey
                                   select mtable;
                        foreach (Mile mile in mRec)
                        {
                            mile.Miles = (Int32)GoogleHelper.GetMileage(lookupOrigin, dest.Value);
                        }
                    }
                    else
                    {
                        //Get the Mile Record
                        var mRec = from mtable in mdc.Miles
                                   where mtable.FromId == originKey && mtable.ToId == destKey && mtable.Miles == 0
                                   select mtable;
                        foreach (Mile mile in mRec)
                        {
                            mile.Miles = (Int32)GoogleHelper.GetMileage(lookupOrigin, dest.Value);
                        }
                    }

                    //Submit changes to table
                    try
                    {
                        mdc.SubmitChanges();
                    }
                    catch (Exception exceptUpdate)
                    {
                        MessageBox.Show(exceptUpdate.Message.ToString());
                    }
                }
            }
        }