Catrobat.IDE.Core.ViewModels.Service.UploadProgramLoginViewModel.LoginAction C# (CSharp) Method

LoginAction() private method

private LoginAction ( ) : void
return void
        private async void LoginAction()
        {
            if (string.IsNullOrEmpty(_username) || string.IsNullOrEmpty(_password))
            {
                ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Main_UploadProgramLoginErrorCaption"),
                    AppResourcesHelper.Get("Main_UploadProgramMissingLoginData"), MissingLoginDataCallback, MessageBoxOptions.Ok);
            }
            else
            {
                JSONStatusResponse statusResponse = await ServiceLocator.WebCommunicationService.LoginOrRegisterAsync(_username, _password, null,
                                                             ServiceLocator.CultureService.GetCulture().TwoLetterISOLanguageName,
                                                             RegionInfo.CurrentRegion.TwoLetterISORegionName);
                Context.CurrentToken = statusResponse.token;
                Context.CurrentUserName = _username;

                switch (statusResponse.statusCode)
                {
                    case StatusCodes.ServerResponseOk:
                        if (NavigationCallback != null)
                        {
                            NavigationCallback();
                        }
                        else
                        {
                            //TODO: Throw error because of navigation callback shouldn't be null
                            throw new Exception("This error shouldn't be thrown. The navigation callback must not be null.");
                        }
                        break;

                    case StatusCodes.ServerResponseLoginFailed:
                    case StatusCodes.ServerResponseRegistrationFailed:
                        ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Main_UploadProgramLoginErrorCaption"),
                            AppResourcesHelper.Get("Main_UploadProgramLoginErrorStatic"), WrongLoginDataCallback, MessageBoxOptions.Ok);
                        break;

                    case StatusCodes.ServerResponseMissingEmail:
                        ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Main_UploadProgramLoginErrorCaption"),
                            AppResourcesHelper.Get("Main_UploadProgramLoginNonExistingUser"), WrongLoginDataCallback, MessageBoxOptions.Ok);
                        break;

                    case StatusCodes.HTTPRequestFailed:
                        ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Main_UploadProgramLoginErrorCaption"),
                            AppResourcesHelper.Get("Main_NoInternetConnection"), WrongLoginDataCallback, MessageBoxOptions.Ok);
                        break;

                    default:
                        string messageString = string.IsNullOrEmpty(statusResponse.answer) ? string.Format(AppResourcesHelper.Get("Main_UploadProgramUndefinedError"), statusResponse.statusCode.ToString()) :
                                                string.Format(AppResourcesHelper.Get("Main_UploadProgramLoginError"), statusResponse.answer);
                        ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Main_UploadProgramLoginErrorCaption"),
                            messageString, WrongLoginDataCallback, MessageBoxOptions.Ok);
                        break;
                }
            }
        }