Catrobat.IDE.Core.ViewModels.Service.UploadProgramRegisterViewModel.RegisterAction C# (CSharp) Method

RegisterAction() private method

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

                Context.CurrentToken = statusResponse.token;
                Context.CurrentUserName = _username;
                Context.CurrentUserEmail = _email;

                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.ServerResponseRegisterOk:
                        ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Main_UploadProgramRegistrationSucessful"),
                            string.Format(AppResourcesHelper.Get("Main_UploadProgramWelcome"), _username), RegistrationSuccessfulCallback, MessageBoxOptions.Ok);
                        break;

                    case StatusCodes.ServerResponseLoginFailed:
                        ServiceLocator.NotifictionService.ShowMessageBox(AppResourcesHelper.Get("Main_UploadProgramLoginErrorCaption"),
                            AppResourcesHelper.Get("Main_UploadProgramRegisterExistingUser"), 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;
                }
            }
            IsSending = false;
        }