public async Task <UserMobile> Login(string Email, string Password) { if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password)) { return(await Task.FromResult(new UserMobile(false, "Usuário e/ou senha inválidos"))); } else { using (var client = new HttpClient()) { UserMobile user = new UserMobile(Email, Password); var param = JsonConvert.SerializeObject(user); HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json"); var response = client.PostAsync(string.Format(Constants.WebServiceEndPoint + Constants.UserEndPoint + "login"), contentPost).Result; var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode.Equals(HttpStatusCode.OK)) { UserMobile userResponse = JsonConvert.DeserializeObject <UserMobile>(json); userResponse.Success = true; return(await Task.FromResult(userResponse)); } else { MobileException exception = JsonConvert.DeserializeObject <MobileException>(json); return(await Task.FromResult(new UserMobile(false, exception.Message))); } } } }
public async Task <LaboratoryMobile> GetByLaboratoryCode(string LaboratoryCode) { try { if (string.IsNullOrEmpty(LaboratoryCode)) { return(await Task.FromResult(new LaboratoryMobile(false, "Laboratório inválido"))); } else { using (var client = new HttpClient()) { var response = client.GetAsync(string.Format(Constants.WebServiceEndPoint + Constants.LaboratoryEndPoint + "getbylaboratorycode/" + LaboratoryCode)).Result; var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode.Equals(HttpStatusCode.OK)) { LaboratoryMobile laboratoryResponse = JsonConvert.DeserializeObject <LaboratoryMobile>(json); laboratoryResponse.Success = true; return(await Task.FromResult(laboratoryResponse)); } else { MobileException exception = JsonConvert.DeserializeObject <MobileException>(json); return(await Task.FromResult(new LaboratoryMobile(false, exception.Message))); } } } } catch (Exception e) { return(null); } }
public async Task <AnalysisMobile> GetByAnalysisCode(string AnalysisCode) { try { if (string.IsNullOrEmpty(AnalysisCode)) { return(await Task.FromResult(new AnalysisMobile(false, "Análise inválido"))); } else { using (var client = new HttpClient()) { var response = client.GetAsync(string.Format(Constants.WebServiceEndPoint + Constants.AnalysisEndPoint + "getbyanalysiscode/" + AnalysisCode)).Result; var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode.Equals(HttpStatusCode.OK)) { AnalysisMobile analysisResponse = JsonConvert.DeserializeObject <AnalysisMobile>(json); analysisResponse.Success = true; return(await Task.FromResult(analysisResponse)); } else { MobileException exception = JsonConvert.DeserializeObject <MobileException>(json); return(await Task.FromResult(new AnalysisMobile(false, exception.Message))); } } } } catch (Exception e) { return(null); } }