void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) { try { CategoryDataProvider _CategoryDataProvider = new CategoryDataProvider(); if (e.Result.Contains("no Category found")) { ListCategoryData = new List<CategoryOfflineViewModel>(); this.lstCateoryItems.ItemsSource = ListCategoryData; } else { //Parse JSON result var rootObject = JsonConvert.DeserializeObject<RootObject_Category>(e.Result); if (rootObject.success == 1) { foreach (var itm in rootObject.response.data) { CategoryOfflineViewModel obj = new CategoryOfflineViewModel(); 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.imageName = itm.imageName; obj.active = itm.active; _CategoryDataProvider = new CategoryDataProvider(); var result = _CategoryDataProvider.AddCategoryOffline(obj, "True"); if (result == true) { //MessageBox.Show("successfully registerd Customer."); } } //==================================================================================================================== // Fill Category List From Offline DB //==================================================================================================================== _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; // 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; } }
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)); } }