public DashBoardViewModel(INavigationService navigationService) : base(navigationService) { try { _navigationService = navigationService; webServiceManager = new WebServiceManager(); Title = "Inspections"; LoginCommand = new Command(async() => ExecuteLogoutCommandAsync()); UserRoleId = Convert.ToInt32(RememberMe.Get("UserRoleId")); //Xamarin.Forms.Device.BeginInvokeOnMainThread(async () => //{ // await Task.Delay(1000); // bool IsSyncDatabse = (Boolean)RememberMe.Get("isSyncDatabse", true); // if (IsSyncDatabse && ConfigurationCommon.App_Online) // { // InitData.SyncHeaderDetailsInServer(); // RememberMe.Set("isSyncDatabse", false); // await Xamarin.Forms.Application.Current.SavePropertiesAsync(); // } // InitData.GetAllInitData(); //}); } catch (Exception ex) { throw ex; } }
public override void OnNavigatedTo(INavigationParameters parameters) { bool IsSyncDatabse = (Boolean)RememberMe.Get("isSyncDatabse", true); //if (ConfigurationCommon.App_Online) //{ Xamarin.Forms.Device.BeginInvokeOnMainThread(async() => { await Task.Delay(1000); if (IsSyncDatabse && ConfigurationCommon.App_Online) { InitData.SyncHeaderDetailsInServer(); RememberMe.Set("isSyncDatabse", false); await Xamarin.Forms.Application.Current.SavePropertiesAsync(); } InitData.GetAllInitData(); }); //} }
public LoginPageViewModel(INavigationService navigationService) : base(navigationService) { _navigationService = navigationService; webServiceManager = new WebServiceManager(); //Title = "Login"; UserId = Convert.ToString(RememberMe.Get("username")); Password = Convert.ToString(RememberMe.Get("password")); IsSwitchedToggled = (Boolean)RememberMe.Get("isSwitchedToggled", true); LoginCommand = new Command(async() => Login_Command()); ForgetCommand = new Command(async() => Forget_Command()); RegisterCommand = new Command(async() => Register_Command()); UserId = "*****@*****.**"; Password = "******"; if (IsSwitchedToggled) { if (!string.IsNullOrEmpty(UserId) && !string.IsNullOrEmpty(Password)) { _navigationService.NavigateAsync("NavigationPage/DashboardPage"); } } }
public async void AddNew_Command() { if (SelectedCompany == null) { await App.Current.MainPage.DisplayAlert("Alert ", "Please Select Company Name!", "ok"); } else if (string.IsNullOrEmpty(Invoice)) { await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Invoice!", "ok"); } else if (SelectedProduct == null) { await App.Current.MainPage.DisplayAlert("Alert ", "Please Select Product Name!", "ok"); } else if (SelectedVariety == null) { await App.Current.MainPage.DisplayAlert("Alert ", "Please Select Variety Name!", "ok"); } else if (SelectedBrand == null) { await App.Current.MainPage.DisplayAlert("Alert", "Please Select Brand Name!", "ok"); } else if (SelectedCountryofOrigin == null) { await App.Current.MainPage.DisplayAlert("Alert", "Please Select CountryofOrigin Name!", "ok"); } else if (TotalBoxQua == 0) { await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Total Box Quantities!", "ok"); } else if (TempOnCaja == 0) { await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Temp On Caja!", "ok"); } else if (TempOnTermografo == 0) { await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Temp On Termografo!", "ok"); } else if (SelectedPalletizingCondition == null) { await App.Current.MainPage.DisplayAlert("Alert", "Please Select Palletizing Condition!", "ok"); } else { try { UserDialogs.Instance.ShowLoading("Loading..."); RememberMe.Set("isSyncDatabse", true); await Xamarin.Forms.Application.Current.SavePropertiesAsync(); InspectionHeadersRequestDTO inspectionHeaderRequestDTO = new InspectionHeadersRequestDTO() { Id = _InspectionHeader != null ? _InspectionHeader.Id : 0, CompanyId = (int)SelectedCompany.Id, InspectionDate = DateTime.Now, UserId = Convert.ToInt32(RememberMe.Get("userID")), Invoice = Invoice, ProducerId = (int)SelectedProduct.Id, VarietyId = (int)SelectedVariety.Id, BrandId = (int)SelectedBrand.Id, CountryofOriginId = (int)SelectedCountryofOrigin.Id, TotalBoxQuantities = TotalBoxQua, TempOnCaja = TempOnCaja, TempOnTermografo = TempOnTermografo, PalletizingConditionId = (int)SelectedPalletizingCondition.Id, }; Model.InspectionHeaderTable inspectionHeaderTable = new Model.InspectionHeaderTable { Id = 0, CompanyId = inspectionHeaderRequestDTO.CompanyId, InspectionDate = inspectionHeaderRequestDTO.InspectionDate, UserId = inspectionHeaderRequestDTO.UserId, Invoice = inspectionHeaderRequestDTO.Invoice, ProducerId = inspectionHeaderRequestDTO.ProducerId, VarietyId = inspectionHeaderRequestDTO.VarietyId, BrandId = inspectionHeaderRequestDTO.BrandId, CountryofOriginId = inspectionHeaderRequestDTO.CountryofOriginId, TotalBoxQuantities = inspectionHeaderRequestDTO.TotalBoxQuantities, TempOnCaja = inspectionHeaderRequestDTO.TempOnCaja, TempOnTermografo = inspectionHeaderRequestDTO.TempOnTermografo, PalletizingConditionId = inspectionHeaderRequestDTO.PalletizingConditionId, }; if (ConfigurationCommon.App_Online) { var result = await webServiceManager.RegistrationInspectionHeaderAsync(inspectionHeaderRequestDTO).ConfigureAwait(true);; if (result.IsSuccess && result.Data.StatusCode == 0) { await App.Current.MainPage.DisplayAlert("Alert", "Inspection Header has been Saved!", "ok"); int InspectionID = _InspectionHeader != null ? _InspectionHeader.Id : 0; var parameters = new NavigationParameters(); if (InspectionID > 0) { HeaderAsync(inspectionHeaderTable, result.Data.Id, false); parameters.Add("HeaderID", result.Data.Id); await _navigationService.NavigateAsync("InspectionDetailsListPage", parameters); } else { UserDialogs.Instance.ShowLoading(); HeaderAsync(inspectionHeaderTable, result.Data.Id, true); parameters.Add("HeaderID", result.Data.Id); parameters.Add("ScreenRight", "New Detail Inspection"); await _navigationService.NavigateAsync("AddNewDetailsInspectionPage", parameters); UserDialogs.Instance.HideLoading(); } } else { await App.Current.MainPage.DisplayAlert("Alert", result.Data.Status, "ok"); } } else { int MaxHeaderCode = 0; if (inspectionHeaderRequestDTO.Id == 0) { var data = await InitData.HeaderRepo.GetMaxCode(x => x.Id, false); MaxHeaderCode = (int)data.Id + 1; } else { MaxHeaderCode = inspectionHeaderRequestDTO.Id; } if (inspectionHeaderRequestDTO.Id > 0) { HeaderAsync(inspectionHeaderTable, MaxHeaderCode, false); await App.Current.MainPage.DisplayAlert("Alert", "Inspection Header has been Saved!", "Ok"); var parameters = new NavigationParameters(); if (MaxHeaderCode > 0) { parameters.Add("HeaderID", MaxHeaderCode); await _navigationService.NavigateAsync("InspectionDetailsListPage", parameters); } } else { HeaderAsync(inspectionHeaderTable, MaxHeaderCode, true); await App.Current.MainPage.DisplayAlert("Alert", "Inspection Header has been Saved!", "Ok"); var parameters = new NavigationParameters(); if (MaxHeaderCode > 0) { parameters.Add("HeaderID", MaxHeaderCode); await _navigationService.NavigateAsync("InspectionDetailsListPage", parameters); } } } } catch (Exception ex) { UserDialogs.Instance.HideLoading(); throw ex; } finally { UserDialogs.Instance.HideLoading(); } } }
public async void Login_Command() { if (UserId == null || userid == "") { await App.Current.MainPage.DisplayAlert("Alert ", "Please Enter EmailID", "ok"); } else if (Password == null || Password == "") { await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Password", "ok"); } else if (Color.Red == EmailColor) { await App.Current.MainPage.DisplayAlert("Alert", "Email is not in correct format!", "ok"); } else if (ConfigurationCommon.App_Online) { try { UserDialogs.Instance.ShowLoading("Loading..."); if (ConfigurationCommon.App_Online) { UsersRequestDTO clientRequestDTO = new UsersRequestDTO() { Email = UserId, UserPwd = Password, //ApplicationId = ConfigurationCommon.ApplicationId, //DeviceToken = RememberMe.Get("PushDeviceToken").ToString(), //DeviceName = Device.RuntimePlatform, }; var result = await webServiceManager.LoginAsync(clientRequestDTO).ConfigureAwait(true);; if (result.IsSuccess && string.IsNullOrEmpty(result.Data.Status)) { UserData = new User() { CompanyId = result.Data._Users.CompanyId, //ApplicationId = result.Data._Users.ApplicationId, UserRoleId = result.Data._Users.UserRoleId, Id = result.Data._Users.Id }; RememberMe.Set("userID", result.Data._Users.Id); RememberMe.Set("CmpID", result.Data._Users.CompanyId); RememberMe.Set("UserRoleId", result.Data._Users.CompanyId); //if (IsSwitchedToggled) //{ RememberMe.Set("username", this.UserId); RememberMe.Set("password", this.Password); //} RememberMe.Set("isSwitchedToggled", IsSwitchedToggled); RememberMe.Set("isDatabaseUpdate", false); await _navigationService.NavigateAsync("DashboardPage"); await Xamarin.Forms.Application.Current.SavePropertiesAsync(); } else { App.Current.MainPage.DisplayAlert("Alert ", result.Data.Status, "ok"); } } } catch (Exception ex) { UserDialogs.Instance.HideLoading(); throw ex; } //finally //{ // UserDialogs.Instance.HideLoading(); //} } else { if (UserId != Convert.ToString(RememberMe.Get("username"))) { await App.Current.MainPage.DisplayAlert("Alert", "Please Enter valid EmailID!", "ok"); } else if (Password != Convert.ToString(RememberMe.Get("password"))) { await App.Current.MainPage.DisplayAlert("Alert", "Please Enter valid Password!", "ok"); } else { RememberMe.Set("isSwitchedToggled", IsSwitchedToggled); await _navigationService.NavigateAsync("DashboardPage"); await Xamarin.Forms.Application.Current.SavePropertiesAsync(); } } }