private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // Show Loader
            myIndeterminateProbar.Visibility = Visibility.Visible;

            // Parameters
            CategoryRequest obj = new CategoryRequest();
            obj.organizationId = _organizationId; // Logged In organizationId
            obj.categoryCode = txtcategoryName.Text;
            obj.categoryDescription = txtcategoryDescription.Text;
            obj.parentCategoryId = 0; // 0 for category and category id for subcategory

            if (Utilities.CheckInternetConnection())
            {
                // ----------------------------------------------------------------------
                // "Network Status: Connected."

                String data = string.Empty;

                if (Validation() == true)
                {
                    //Initialize WebClient
                    WebClient webClient = new WebClient();

                    //Set Header
                    webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
                    webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                    webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";

                    if (_mode == "Add")
                    {
                        data = "organizationId=" + obj.organizationId + "&categoryCode=" + obj.categoryCode + "&categoryDescription=" + obj.categoryDescription + "&parentCategoryId=" + obj.parentCategoryId;
                        webClient.UploadStringAsync(new Uri(Utilities.GetURL("category/addCategory/")), "POST", data);
                    }
                    if (_mode == "Edit")
                    {
                        obj.categoryId = _categoryId;

                        data = "organizationId=" + obj.organizationId + "&categoryId=" + obj.categoryId + "&categoryCode=" + obj.categoryCode + "&categoryDescription=" + obj.categoryDescription + "&parentCategoryId=" + obj.parentCategoryId;
                        webClient.UploadStringAsync(new Uri(Utilities.GetURL("category/updateCategory/")), "POST", data);
                    }

                    //Assign Event Handler
                    webClient.UploadStringCompleted += wc_UploadSaveCompleted;
                }
            }
            else
            {
                // ----------------------------------------------------------------------
                //  "Network Status: Not Connected."

                MessageBoxResult objMessageBox = MessageBox.Show("Right now you are in offline mode. data save and will be sent to the server the next time you are online.", "Network Status !", MessageBoxButton.OKCancel);
                if (objMessageBox == MessageBoxResult.OK)
                {
                    try
                    {
                        if (Validation() == true)
                        {
                            if (_mode == "Add")
                            {
                                MessageBox.Show("You can not create a new category in offline mode.");
                            }

                            if (_mode == "Edit")
                            {
                                CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider();
                                var result = _CategoryDataProvider.UpdateCategoryOffline(obj, "False");
                                if (result == true)
                                {
                                    MessageBox.Show("successfully Updated.");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Something wrong happened.");
                    }
                }
            }
        }
        public CategoryListPage()
        {
            InitializeComponent();

            IsolatedStorageFile ISOFile = IsolatedStorageFile.GetUserStoreForApplication();
            if (IsolatedStorageSettings.ApplicationSettings.Contains("islogin"))
            {
                if (!(Convert.ToString(IsolatedStorageSettings.ApplicationSettings["islogin"]).ToLower() == "yes"))
                {
                    NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
                }
                else
                {
                    if (ISOFile.FileExists("CurrentLoginUserDetails"))//read current user login details
                    {
                        using (IsolatedStorageFileStream fileStream = ISOFile.OpenFile("CurrentLoginUserDetails", FileMode.Open))
                        {
                            DataContractSerializer serializer = new DataContractSerializer(typeof(LoginViewModel));
                            var ObjUserData = (LoginViewModel)serializer.ReadObject(fileStream);
                            this.txtHeaderOrgName.Text = ObjUserData.organizationName;
                            this.txtHeaderFullName.Text = ObjUserData.firstName + " " + ObjUserData.lastName;
                            _employeeId = Convert.ToInt32(ObjUserData.employeeId);
                            _organizationId = Convert.ToInt32(ObjUserData.organizationId);
                            lstMenuItems.ItemsSource = Utilities.GetMenuItems(MenuCode.CatMngt);

                            if (Utilities.CheckInternetConnection())
                            {
                                // ----------------------------------------------------------------------
                                // "Network Status: Connected."

                                //====================================================================================================================
                                // Category module Data Synchronization
                                //====================================================================================================================

                                // Show Loader
                                myIndeterminateProbar.Visibility = Visibility.Visible;
                                CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider();
                                var result = _CategoryDataProvider.GetsyncedCategoryOfflineList("False");
                                if (result != null)
                                {
                                    if (result.Count > 0)
                                    {
                                        try
                                        {
                                            foreach (var itm in result)
                                            {
                                                // Parameters
                                                CategoryRequest obj = new CategoryRequest();
                                                obj.organizationId = _organizationId; // Logged In organizationId
                                                obj.categoryId = Convert.ToInt32(itm.categoryId);
                                                obj.categoryCode = itm.categoryCode;
                                                obj.categoryDescription = itm.categoryDescription;
                                                obj.parentCategoryId = 0; // 0 for category and category id for subcategory

                                                String data = string.Empty;

                                                //Initialize WebClient
                                                WebClient webClient = new WebClient();

                                                //Set Header
                                                webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
                                                webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                                                webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";

                                                data = "organizationId=" + obj.organizationId + "&categoryId=" + obj.categoryId + "&categoryCode=" + obj.categoryCode + "&categoryDescription=" + obj.categoryDescription + "&parentCategoryId=" + obj.parentCategoryId;
                                                webClient.UploadStringAsync(new Uri(Utilities.GetURL("category/updateCategory/")), "POST", data);

                                                //Assign Event Handler
                                                webClient.UploadStringCompleted += wc_UploadSaveCompleted;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show("Something wrong happened.");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //====================================================================================================================
                                // Fill Category List From Offline DB
                                //====================================================================================================================

                                CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider();
                                ListCategoryData = new List<CategoryOfflineViewModel>();
                                foreach (var itm in _CategoryDataProvider.GetAllCategoryOfflineList())
                                {
                                    var Source = "/Assets/category/category_icon.png";
                                    if (!string.IsNullOrEmpty(itm.imageName))
                                    {
                                        Source = Utilities.GetMarketplaceURL() + uploadImagePath.CATEGORY + itm.imageName;
                                    }

                                    ListCategoryData.Add(new CategoryOfflineViewModel { categoryId = itm.categoryId, organizationId = itm.organizationId, categoryCode = itm.categoryCode, categoryDescription = itm.categoryDescription, imageName = itm.imageName, imagePath = itm.imagePath, active = itm.active, parentCategoryId = itm.parentCategoryId, createDt = itm.createDt, lastModifiedDt = itm.lastModifiedDt, lastModifiedBy = itm.lastModifiedBy, fullImagePath = Source });
                                };
                                this.lstCateoryItems.ItemsSource = ListCategoryData;
                            }
                        }
                    }
                }
            }
            else
            {
                NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }
        public bool UpdateCategoryOffline(CategoryRequest CustomerOffline, string _synced)
        {
            bool result = false;
            try
            {
                using (var db = new SQLite.SQLiteConnection(_dbPath))
                {
                    var objCategoryOffline = db.Query<PointePayApp.Model.CategoryOffline>("select * from CategoryOffline where categoryId=" + CustomerOffline.categoryId).FirstOrDefault();
                    if (objCategoryOffline != null)
                    {
                        //objCategoryOffline.categoryId = Convert.ToString(CustomerOffline.categoryId);
                        //objCategoryOffline.organizationId = Convert.ToString(CustomerOffline.organizationId);
                        objCategoryOffline.categoryCode = Convert.ToString(CustomerOffline.categoryCode);
                        objCategoryOffline.categoryDescription = CustomerOffline.categoryDescription;
                        objCategoryOffline.parentCategoryId = Convert.ToString(CustomerOffline.parentCategoryId);
                        //objCategoryOffline.active = CustomerOffline.active;

                        objCategoryOffline.synced = _synced;  // i.e. Need to synced when online and Update the synced status = "True"

                        db.RunInTransaction(() =>
                        {
                            db.Update(objCategoryOffline);
                        });
                    }
                }

                result = true;
            }//try
            catch (Exception ex)
            {

            }//catch
            return result;
        }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (Utilities.CheckInternetConnection())
            {
                // ----------------------------------------------------------------------
                // "Network Status: Connected."

                // Show Loader
                myIndeterminateProbar.Visibility = Visibility.Visible;

                //====================================================================================================================
                // Clear offline Customer table
                //====================================================================================================================

                CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider();
                var result = _CategoryDataProvider.DeleteAllCategoryOffline();
                if (result == true)
                {
                    // Success
                }

                //====================================================================================================================
                // Fill Category List
                //====================================================================================================================
                // Parameters
                CategoryRequest obj = new CategoryRequest();
                obj.organizationId = _organizationId;
                obj.set = 1;
                obj.count = Utilities.GetListCount();
                String data = "organizationId=" + obj.organizationId + "&set=" + obj.set + "&count=" + obj.count;

                //Initialize WebClient
                WebClient webClient = new WebClient();
                //Set Header
                webClient.Headers[HttpRequestHeader.Authorization] = Utilities.GetAuthorization();
                webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en_US";
                webClient.UploadStringAsync(new Uri(Utilities.GetURL("category/categoryListing/")), "POST", data);
                //Assign Event Handler0
                webClient.UploadStringCompleted += wc_UploadStringCompleted;
            }
        }