private void SetupTypeIntervalConfigData(TypeIntervalConfiguration existing, bool removeNew)
 {
     var item = existing;
     
     App.Instance.StaticServiceData.IntervalConfiguration = item;
     
     StorageUtility.SaveItem(STATIC_TYPEINTERVALCONFIG_FOLDER, item, item.TypeIntervalConfigurationId, App.Instance.User.UserName);
 }
        private async void LoadCachedTypeIntervalConfiguration(Action<BMA.BusinessLogic.TypeIntervalConfiguration, Exception> callback)
        {
            var retVal = new BMA.BusinessLogic.TypeIntervalConfiguration();
            try
            {
                foreach (var item in await StorageUtility.ListItems(STATIC_TYPEINTERVAL_FOLDER, App.Instance.User.UserName))
                {
                    var staticType = await StorageUtility.RestoreItem<BMA.BusinessLogic.TypeIntervalConfiguration>(STATIC_TYPEINTERVALCONFIG_FOLDER, item, App.Instance.User.UserName);
                    IntervalConfiguration = staticType;
                }
                //SetupIntervalData(retVal, false);
                //IntervalConfiguration = retVal;

                callback(IntervalConfiguration, null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                callback(null, ex);
            }
        }
        public void SaveTypeIntervalConfiguration(TypeIntervalConfiguration typeIntervalConfig, Action<Exception> callback)
        {
            try
            {
                App.Instance.StaticServiceData.SetServerStatus(status =>
                {
                    //continue with local if status is ok but is pending Sync
                    if (status != Model.StaticServiceData.ServerStatus.Ok || !App.Instance.IsSync)
                    {
                        try
                        {
                            SetupTypeIntervalConfigData(typeIntervalConfig, false);

                            App.Instance.IsSync = false;

                            callback(null);
                        }
                        catch (Exception ex)
                        {
                            callback(ex);
                        }
                    }
                    else
                    {
                        var client = new StaticClient();
                        client.SaveTypeIntervalConfigAsync(typeIntervalConfig);
                        client.SaveTypeIntervalConfigCompleted += (sender, completedEventArgs) =>
                        {
                            if (completedEventArgs.Error == null)
                            {
                                SetupTypeIntervalConfigData(completedEventArgs.Result, true);

                                //Only update sync when offline and in login and main pages
                                //App.Instance.IsSync = true;

                                callback(null);
                            }
                            else
                                callback(completedEventArgs.Error);
                        };
                    }
                });
            }
            catch (Exception)
            {
                throw;
            }
        }