Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public static bool HttpClient <T>(T request, string BaseAddress, string Uri, out CustomExceptionRAC customException, string RequestType = "POST")
        {
            bool ReturnValue = false;

            customException = null;
            try
            {
                var result = HttpResponse <T>(request, BaseAddress, Uri, RequestType);
                if (result != null)
                {
                    if (result.IsSuccessStatusCode)
                    {
                        ReturnValue = true;
                    }
                    else if (result.StatusCode.Equals(HttpStatusCode.NotFound))
                    {
                        ReturnValue = false;
                    }
                    else
                    {
                        customException = new CustomExceptionRAC();
                        try
                        {
                            var readTask = result.Content.ReadAsAsync <CustomExceptionRAC>();
                            readTask.Wait();
                            var Exception = readTask.Result;
                            customException = Exception as CustomExceptionRAC;
                            ReturnValue     = false;
                            // customException.IsValid = true;
                        }
                        catch (Exception Ex)
                        {
                            ReturnValue = false;
                            customException.errorState = result.ReasonPhrase;
                            //customException.IsValid = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                customException            = new CustomExceptionRAC();
                customException.errorState = ex != null ? (ex.InnerException != null ? ex.InnerException.Message : ex.Message) : "Some thing unexpected happen";
                ReturnValue = false;
            }
            return(ReturnValue);
        }
Esempio n. 3
0
 public static R HttpClientRAC <T, R>(T request, string BaseAddress, string Uri, out CustomExceptionRAC 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
             {
                 customException = new CustomExceptionRAC();
                 try
                 {
                     var readTask = result.Content.ReadAsAsync <CustomExceptionRAC>();
                     readTask.Wait();
                     var Exception = readTask.Result;
                     customException = Exception as CustomExceptionRAC;
                     // customException.IsValid = true;
                 }
                 catch (Exception Ex)
                 {
                     customException.errorState = result.ReasonPhrase;
                     //customException.IsValid = false;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         customException            = new CustomExceptionRAC();
         customException.errorState = ex != null ? (ex.InnerException != null ? ex.InnerException.Message : ex.Message) : "Some thing unexpected happen";
     }
     return(default(R));
 }
Esempio n. 4
0
        public bool RecoveryEmailJCH(RecoveryEmailRACRequest recoveryEmailRACRequest, out string ErrorMessage, out CustomExceptionRAC customException)
        {
            customException = null;
            ErrorMessage    = string.Empty;
            bool recoveryEmailRACResponse = false;

            if (Registration.CheckNet())
            {
                string RACBaseUrl   = ConfigurationManager.AppSettings["RACBaseUrl"];
                string RACSignInUrl = "account/forgot-password";
                recoveryEmailRACResponse = Registration.HttpClient <RecoveryEmailRACRequest>(recoveryEmailRACRequest, RACBaseUrl, RACSignInUrl, out customException);
                if (customException != null)
                {
                    return(false);
                }
            }
            else
            {
                ErrorMessage = "Internet is not available";
            }
            return(recoveryEmailRACResponse);
        }
Esempio n. 5
0
        public UserRACResponse UserLoginJCHAuth(UserRACRequest user, out string ErrorMessage, out CustomExceptionRAC customException)
        {
            customException = null;
            ErrorMessage    = string.Empty;
            UserRACResponse userResponse = new UserRACResponse();

            if (Registration.CheckNet())
            {
                string RACBaseUrl   = ConfigurationManager.AppSettings["RACBaseUrl"];
                string RACSignInUrl = "auth/sign-in";
                userResponse = Registration.HttpClientRAC <UserRACRequest, UserRACResponse>(user, RACBaseUrl, RACSignInUrl, out customException);
                if (customException != null)
                {
                    return(null);
                }
            }
            else
            {
                ErrorMessage = "Internet is not available";
            }
            return(userResponse);
        }
Esempio n. 6
0
 public bool CheckUserPassword(RegistrationModel registrationModel, string BaseUrl, string action, out string ErrorMessage, out CustomExceptionRAC customException)
 {
     customException = null;
     ErrorMessage    = string.Empty;
     if (!string.IsNullOrWhiteSpace(registrationModel.Username) && !string.IsNullOrWhiteSpace(registrationModel.Password))
     {
         UserRACRequest user = new UserRACRequest {
             email = registrationModel.Username, password = registrationModel.Password
         };
         UserRACResponse userResponse = new UserRACResponse();
         if (Registration.CheckNet())
         {
             userResponse = Registration.HttpClientRAC <UserRACRequest, UserRACResponse>(user, BaseUrl, action, out customException);
             if (userResponse != null && !string.IsNullOrEmpty(userResponse.token))
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             ErrorMessage = "Internet is not available";
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }