コード例 #1
0
ファイル: LoginPageVM.cs プロジェクト: zorasdangol/KOTApp
        public async void ExecuteLoginCommand()
        {
            try
            {
                IsLoading     = true;
                User.UserName = UserName;
                User.Password = Password;
                User.ip1      = ip1;
                User.ip2      = ip2;
                User.ip3      = ip3;
                User.ip4      = ip4;
                User.Port     = Port;
                User.UniqueID = Helpers.Data.deviceToken;

                Helpers.Constants.SetMainURL(User);
                var functionResponse = UserValidator.CheckUser(User);
                if (functionResponse.status == "error")
                {
                    DependencyService.Get <IMessage>().ShortAlert(functionResponse.Message);
                }
                else
                {
                    //DependencyService.Get<IMessage>().ShortAlert("Connecting to Server. Please Wait..");

                    functionResponse = await LoginConnection.UserVerficationAsync(User);

                    if (functionResponse.status == "ok")
                    {
                        Helpers.Constants.User = User;
                        Helpers.Constants.SetMainURL(User);
                        LoginUser.SetUserAndIP(App.DatabaseLocation, User);

                        var menuitemResponse = await LoadMenuItem.GetMenuItemAsync();

                        if (menuitemResponse.status == "ok")
                        {
                            Helpers.Data.MenuItemsList = JsonConvert.DeserializeObject <List <KOTAppClassLibrary.Models.MenuItem> >(menuitemResponse.result.ToString());
                            MenuItemsAccess.SaveList(App.DatabaseLocation, Helpers.Data.MenuItemsList);
                        }

                        DependencyService.Get <IMessage>().ShortAlert("Logged In Successfully");
                        App.Current.MainPage = new NavigationPage(new HomePage());
                        //App.Current.MainPage = (new MasterPage());
                    }
                    else
                    {
                        DependencyService.Get <IMessage>().ShortAlert(functionResponse.Message);
                    }
                    IsLoading = false;
                }
            }catch (Exception e)
            {
                IsLoading = false;
                DependencyService.Get <IMessage>().ShortAlert("Error::" + e.Message);
            }
        }