public bool UserRoleSpecific(string email, string password, out CustomExceptionVRF customExceptionVRF) { bool IsValid = false; customExceptionVRF = null; string ErrorMessage = string.Empty; UserRegionRequest userRegionRequest = new UserRegionRequest { // Username = email Username = "******" }; //TODO UserRegionResponse userRegionResponse = GetVRFUserData(userRegionRequest, out customExceptionVRF, out ErrorMessage); //VRF WebApi if (userRegionResponse != null && customExceptionVRF == null) { if (string.IsNullOrWhiteSpace(ErrorMessage)) { UserVRF userVrf = new UserVRF { Username = email, UserRole = userRegionResponse.data.role, UserRegion = userRegionResponse.data.regionCode, Password = password, SyncDate = DateTime.Now }; MyRegion myRegion = GetRegionVRF(userVrf.UserRegion); DoRegistration(myRegion, userVrf); IsValid = true; } } return(IsValid); }
public bool IsValid(out string ErrorMessage, out CustomExceptionRAC customExceptionRAC) { customExceptionRAC = null; CustomExceptionVRF customExceptionVRF = null; bool IsValidUserRole = false; sv = GetSVRF(); if (CheckNet()) { string RACBaseUrl = ConfigurationManager.AppSettings["RACBaseUrl"]; string RACSignInUrl = "auth/sign-in"; bool IsValidUser = CheckUserPassword(sv, RACBaseUrl, RACSignInUrl, out ErrorMessage, out customExceptionRAC); if (IsValidUser) { IsValidUserRole = UserRoleSpecific(sv.Username, sv.Password, out customExceptionVRF); //if (customExceptionVRF != null)//todo //{ //} } return(IsValidUser && IsValidUserRole); } else { ErrorMessage = "Internet is not available"; return(true); } }
public static R HttpClientJCH <T, R>(T request, string BaseAddress, string Uri, out CustomExceptionVRF customException, string RequestType = "POST") { customException = null; try { var result = HttpResponse <T>(request, BaseAddress, Uri, RequestType); if (result != null) { if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <R>(); readTask.Wait(); // R user = readTask.Result; return(readTask.Result); } else if (result.StatusCode.Equals(HttpStatusCode.NotFound)) { customException = new CustomExceptionVRF(); //try //{ customException.desc = "The user login is not mapped to the role"; customException.stackTrace = result.ReasonPhrase; // customException.IsValid = true; //} //catch (Exception Ex) //{ // customException.stackTrace = result.ReasonPhrase; // //customException.IsValid = false; //} } else { customException = new CustomExceptionVRF(); try { var readTask = result.Content.ReadAsAsync <CustomExceptionVRF>(); readTask.Wait(); var Exception = readTask.Result; customException = Exception as CustomExceptionVRF; // customException.IsValid = true; } catch (Exception Ex) { customException.stackTrace = result.ReasonPhrase; //customException.IsValid = false; } } } } catch (Exception ex) { customException = new CustomExceptionVRF(); customException.stackTrace = ex != null ? (ex.InnerException != null ? ex.InnerException.Message : ex.Message) : "Some thing unexpected happen"; } return(default(R)); }
public UserRegionResponse GetVRFUserData(UserRegionRequest userRegion, out CustomExceptionVRF customExceptionVRF, out string ErrorMessage) { customExceptionVRF = null; ErrorMessage = string.Empty; UserRegionResponse userRegionResponse = null; if (Registration.CheckNet()) { string VRFBaseUrl = ConfigurationManager.AppSettings["VRFBaseUrl"]; string VrfUserDataActionUrl = "api/user/{0}"; userRegionResponse = Registration.HttpClientJCH <UserRegionRequest, UserRegionResponse>(userRegion, VRFBaseUrl, string.Format(VrfUserDataActionUrl, userRegion.Username), out customExceptionVRF, "GET"); } else { ErrorMessage = "Internet is not available"; } return(userRegionResponse); }