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.");
                    }
                }
            }
        }
        void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            try
            {
                CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider();

                if (e.Result.Contains("no Sub Category found"))
                {
                    ListSubCategoryData = new List<SubCategoryOfflineViewModel>();
                    this.lstSubCateoryItems.ItemsSource = ListSubCategoryData;
                }
                else
                {
                    //Parse JSON result
                    var rootObject = JsonConvert.DeserializeObject<RootObject_SubCategory>(e.Result);
                    if (rootObject.success == 1)
                    {
                        foreach (var itm in rootObject.response.data)
                        {
                            SubCategoryOfflineViewModel obj = new SubCategoryOfflineViewModel();
                            obj.categoryId = Convert.ToString(itm.categoryId);
                            obj.organizationId = Convert.ToString(itm.organizationId);
                            obj.categoryCode = Convert.ToString(itm.categoryCode);
                            obj.categoryDescription = itm.categoryDescription;
                            obj.parentCategoryId = itm.parentCategoryId;
                            obj.parentCategory = itm.parentCategory;
                            obj.imageName = itm.imageName;
                            obj.active = itm.active;

                            _CategoryDataProvider = new CategoryDataProvider();
                            var result = _CategoryDataProvider.AddSubCategoryOffline(obj, "True");
                            if (result == true)
                            {
                                //MessageBox.Show("successfully registerd Sub Category.");
                            }
                        }

                        //====================================================================================================================
                        // Fill Sub Category List From Offline DB
                        //====================================================================================================================

                        _CategoryDataProvider = new CategoryDataProvider();
                        ListSubCategoryData = new List<SubCategoryOfflineViewModel>();
                        foreach (var itm in rootObject.response.data)
                        {
                            var Source = "/Assets/category/icon_sub_categories.png";
                            if (!string.IsNullOrEmpty(itm.imageName))
                            {
                                Source = Utilities.GetMarketplaceURL() + uploadImagePath.SUBCATEGORY + itm.imageName;
                            }

                            ListSubCategoryData.Add(new SubCategoryOfflineViewModel { 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, parentCategory = itm.parentCategory, fullImagePath = Source });
                        };
                        this.lstSubCateoryItems.ItemsSource = ListSubCategoryData;

                        // hide Loader
                        myIndeterminateProbar.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        MessageBox.Show(rootObject.response.message.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something wrong happened.");
            }
            finally
            {
                // hide Loader
                myIndeterminateProbar.Visibility = Visibility.Collapsed;
            }
        }
        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.DeleteAllSubCategoryOffline();
                if (result == true)
                {
                    // Success
                }

                //====================================================================================================================
                // Fill Category List
                //====================================================================================================================
                // Parameters
                EmployeeRequest obj = new EmployeeRequest();
                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/subCategoryListing/")), "POST", data);
                //Assign Event Handler0
                webClient.UploadStringCompleted += wc_UploadStringCompleted;
            }
        }
        public SubCategoryListPage()
        {
            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."

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

                                // Show Loader
                                myIndeterminateProbar.Visibility = Visibility.Visible;
                                CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider();
                                var result = _CategoryDataProvider.GetsyncedSubCategoryOfflineList("False");

                                if (result != null)
                                {
                                    if (result.Count > 0)
                                    {
                                        try
                                        {
                                            foreach (var itm in result)
                                            {
                                                // Parameters
                                                SubCategoryRequest obj = new SubCategoryRequest();
                                                obj.organizationId = _organizationId; // Logged In organizationId
                                                obj.categoryId = Convert.ToInt32(itm.categoryId);
                                                obj.categoryCode = itm.categoryCode;
                                                obj.categoryDescription = itm.categoryDescription;
                                                obj.parentCategoryId = Convert.ToInt32(itm.parentCategoryId); // 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();
                                ListSubCategoryData = new List<SubCategoryOfflineViewModel>();
                                foreach (var itm in _CategoryDataProvider.GetAllSubCategoryOfflineList())
                                {
                                    var Source = "/Assets/category/icon_sub_categories.png";
                                    if (!string.IsNullOrEmpty(itm.imageName))
                                    {
                                        Source = Utilities.GetMarketplaceURL() + uploadImagePath.SUBCATEGORY + itm.imageName;
                                    }

                                    ListSubCategoryData.Add(new SubCategoryOfflineViewModel { 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, parentCategory = itm.parentCategory, fullImagePath = Source });
                                };
                                this.lstSubCateoryItems.ItemsSource = ListSubCategoryData;
                            }
                        }
                    }
                }
            }
            else
            {
                NavigationService.Navigate(new Uri("/Views/Login/LoginPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // Parameters
            SubCategoryRequest obj = new SubCategoryRequest();
            obj.organizationId = _organizationId; // Logged In organizationId
            obj.categoryCode = txtsubcategoryName.Text;
            obj.categoryDescription = txtsubcategoryDescription.Text;

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

                ListPickerItem selectedItemState = this.listPickerCategory.ItemContainerGenerator.ContainerFromItem(this.listPickerCategory.SelectedItem) as ListPickerItem;
                SubCategoryOfflineViewModel SelecteddataCategory = selectedItemState.DataContext as SubCategoryOfflineViewModel;
                obj.parentCategoryId = Convert.ToInt32(SelecteddataCategory.categoryId);

                String data = string.Empty;

                if (Validation() == true)
                {
                    // Show Loader
                    myIndeterminateProbar.Visibility = Visibility.Visible;

                    //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 sub category in offline mode.");
                                NavigationService.Navigate(new Uri("/Views/SubCategory/SubCategoryListPage.xaml", UriKind.Relative));
                            }

                            if (_mode == "Edit")
                            {
                                obj.categoryId = _categoryId;
                                obj.parentCategoryId = _ParentCategoryID;

                                CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider();
                                var result = _CategoryDataProvider.UpdateSubCategoryOffline(obj, "False");
                                if (result == true)
                                {
                                    MessageBox.Show("successfully Updated.");
                                    NavigationService.Navigate(new Uri("/Views/SubCategory/SubCategoryListPage.xaml", UriKind.Relative));
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Something wrong happened.");
                    }
                }
            }
        }