Example #1
0
        public async Task<ServiceReturn<string>> VerifyUserAndCreatePatient(AuthenticationType tipoAuth, string username, string nif, System.DateTime birthDate, string name, string email, string phoneNumber, string gender, string destination, string version, string successMessage = "", string errorMessage = "")
        {
            var uiMessages = new Dictionary<string, string>();
            if (!string.IsNullOrEmpty(errorMessage))
                uiMessages.Add(ServiceReturnHandling.GenericMessageKey, errorMessage);
            else
                uiMessages.Add(ServiceReturnHandling.GenericMessageKey, AppResources.NotPossibleCreatePacient);

            if (!string.IsNullOrEmpty(successMessage))
                uiMessages.Add(ServiceReturnHandling.SuccessMessageKey, successMessage);

            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");
                Generated.UsersClient sc = new Generated.UsersClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                var result = await sc.VerifyUserAndCreatePatientAsync(username, nif, "SMS", birthDate, name, email, phoneNumber, gender, destination, phoneNumber, string.Empty, string.Empty, string.Empty, string.Empty, true, GetGPAppVersion());

                return ServiceReturnHandling.BuildSuccessCallReturn<string>(result, uiMessages);
            }
            catch (Exception ex)
            {
                try
                {
                    var gpExp = ((Generated.GPlatformException)ex).Response;
                    var localExcp = Newtonsoft.Json.JsonConvert.DeserializeObject<GPlatformClientException>(gpExp);

                    if (!string.IsNullOrEmpty(ex.Message) && ex.Message.Contains("The HTTP status code of the response was not expected (40"))
                        uiMessages[ServiceReturnHandling.GenericMessageKey] = localExcp.Description;
                }
                catch (Exception) { }

                return ServiceReturnHandling.HandleException<string>(ex, uiMessages);
            }
        }
Example #2
0
        public async Task<bool> CheckIfUserEmailsIsAlreadyRegistered(AuthenticationType tipoAuth, string email)
        {

            string excepMessage = string.Empty;
            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");
                Generated.UsersClient sc = new Generated.UsersClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                var result = await sc.GetByUsernameAsync(email, GetGPAppVersion());

                SessionExternal session = TranslateSessionExternalGPToLocal(result);
                if (session.UserId != null)
                {
                    excepMessage = AppResources.ExistingUserEmail;
                    throw new Exception(AppResources.ExistingUserEmail);
                }
                else
                    return false;
            }
            catch (Exception ex)
            {
                if (string.IsNullOrEmpty(excepMessage)) // Erros genericos
                    throw new Exception(AppResources.CouldNotValidateExistingUserEmail);

                throw ex; // Erros com mensagem definida
            }

        }