public RESTAPIGetRolesResponse GetUserRoles()
        {
            RESTAPIGetRolesResponse response = new RESTAPIGetRolesResponse();

            statusUtils.GetRoles(response);
            return(response);
        }
Beispiel #2
0
        public void GetRoles(RESTAPIGetRolesResponse response)
        {
            List <RESTAPIRolesInterchange> roleInterchangeList = null;
            List <Role> rolelist = null;

            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                roleInterchangeList = new List <RESTAPIRolesInterchange>();
                rolelist            = new List <Role>();

                rolelist = query.GetRole(context);

                if (rolelist != null)
                {
                    foreach (var role in rolelist)
                    {
                        RESTAPIRolesInterchange rolesInterchange = new RESTAPIRolesInterchange(role);
                        roleInterchangeList.Add(rolesInterchange);
                    }
                    response.Status = Enum.GetName(typeof(ResponseStatusType), ResponseStatusType.Success);
                }
                else
                {
                    response.Status = Enum.GetName(typeof(ResponseStatusType), ResponseStatusType.Failure);
                }
            }
                                              , readOnly: true
                                              );

            if (roleInterchangeList != null && roleInterchangeList.Count > 0)
            {
                response.RolesList.AddRange(roleInterchangeList);
            }
        }
Beispiel #3
0
        public GetProfileResponse GetCustomerProfileByDefaultUserLogin(GetProfileResponse response, UserAuthenticationInterchange UserAuthInterchange, bool RetainOldValues, APIMethods apiRetainOldValues)
        {
            User user = null;
            List <RoleMapping> roles = null;

            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                user  = query.GetUserDetails(context, UserAuthInterchange.UserId);
                roles = query.GetUserRoles(context, UserAuthInterchange.UserId);
            }
                                              , readOnly: true
                                              );


            List <int>       roleids   = roles.Select(r => r.RoleId).ToList();
            List <UserRoles> userRoles = new List <UserRoles>();

            RESTAPIGetRolesResponse rolesResponse = new RESTAPIGetRolesResponse();

            statusUtils.GetRoles(rolesResponse);

            if (rolesResponse.RolesList.Count != 0)
            {
                var rolResponseList = rolesResponse.RolesList.Where(r => roleids.Contains(r.RoleId)).ToList();
                foreach (var role in rolResponseList)
                {
                    userRoles.Add(new UserRoles()
                    {
                        Id = role.RoleId, Name = role.RoleName
                    });
                }
            }


            response.Credentials = new AccessCredentials()
            {
                UserID       = Convert.ToInt32(user.UserId),
                SessionToken = (user.SessionToken),
                CallerId     = UserAuthInterchange.CallerId,
                Token        = user.SessionToken,
                Roles        = userRoles
                               //RoleID = roles.Select(x=> x.RoleID).ToList(),
            };

            response.CustomerProfileObject = new CustomerProfile()
            {
                Locale       = user.Locale,
                FirstName    = user.FirstName,
                LastName     = user.LastName,
                EmailAddress = user.EmailAddress
            };


            //if (string.IsNullOrEmpty(UserAuthInterchange.UserName) || string.IsNullOrEmpty(UserAuthInterchange.Password))
            //{
            //    response.ErrorList.Add(Responses.Faults.InvalidCredentials);
            //    return response;
            //}



            if (response == null && response.ErrorList.Count != 0)
            {
                response.ErrorList.Add(Responses.Faults.ServerIsBusy);
            }

            return(response);
        }
Beispiel #4
0
        private GetProfileResponse GetCustomerProfileFromHPIDAndDatabase(GetProfileResponse response, UserAuthenticationInterchange hppAuthInterchange, TokenDetails sessionToken, CustomerIds idS, bool RetainOldValues, APIMethods apiRetainOldValues)
        {
            User profile = null;
            List <RoleMapping> roleMappings = null;

            try
            {
                // check is done based on profile, customerId is also generated for a new profile
                bool IsNewCustomer = false;

                RequestFindOrInsertHPIDProfile requestFindOrInsertHPID = new RequestFindOrInsertHPIDProfile();
                requestFindOrInsertHPID.Locale =
                    string.IsNullOrEmpty(response?.CustomerProfileObject?.Locale)?TranslationUtils.Locale(hppAuthInterchange.LanguageCode, hppAuthInterchange.CountryCode):response?.CustomerProfileObject?.Locale;
                requestFindOrInsertHPID.HPIDprofileId      = idS.HPIDid;
                requestFindOrInsertHPID.HPPprofileId       = idS.HPPid;
                requestFindOrInsertHPID.tokenDetails       = sessionToken;
                requestFindOrInsertHPID.clientId           = hppAuthInterchange.ClientId;
                requestFindOrInsertHPID.apiRetainOldValues = apiRetainOldValues;
                requestFindOrInsertHPID.EmailAddrees       = response?.CustomerProfileObject?.EmailAddress;
                requestFindOrInsertHPID.CompanyName        = response?.CustomerProfileObject?.CompanyName;
                requestFindOrInsertHPID.ActiveHealth       = response.CustomerProfileObject.ActiveHealth;
                requestFindOrInsertHPID.FirstName          = response?.CustomerProfileObject?.FirstName;
                requestFindOrInsertHPID.LastName           = response.CustomerProfileObject.LastName;



                profile = userUtils.FindOrInsertHPIDProfile(response, requestFindOrInsertHPID, out IsNewCustomer);

                if (response.ErrorList.Count > 0)
                {
                    return(response);
                }

                if (profile.RoleMappings.Count == 0)
                {
                    roleMappings = roleUtils.InsertRoleMapping(response, profile.UserId);
                }
                else
                {
                    roleMappings = profile.RoleMappings.ToList();
                }


                hppAuthInterchange.UserId = Convert.ToInt32(profile.UserId);
                hppAuthInterchange.Token  = sessionToken.AccessToken;
                hppAuthInterchange.IsHPID = true;



                // Register profile & session token in database
                customerUtils.InsertOrUpdateHPPToken(response, (UserAuthentication)hppAuthInterchange, RetainOldValues);

                List <int>       roleids   = roleMappings.Select(r => r.RoleId).ToList();
                List <UserRoles> userRoles = new List <UserRoles>();

                RESTAPIGetRolesResponse rolesResponse = new RESTAPIGetRolesResponse();

                statusUtils.GetRoles(rolesResponse);

                if (rolesResponse.RolesList.Count != 0)
                {
                    var rolResponseList = rolesResponse.RolesList.Where(r => roleids.Contains(r.RoleId)).ToList();
                    foreach (var roles in rolResponseList)
                    {
                        userRoles.Add(new UserRoles()
                        {
                            Id = roles.RoleId, Name = roles.RoleName
                        });
                    }
                }


                response.Credentials = new AccessCredentials()
                {
                    UserID       = Convert.ToInt32(profile.UserId),
                    SessionToken = QueryUtils.GetMD5(sessionToken.AccessToken),
                    CallerId     = hppAuthInterchange.CallerId,
                    Token        = sessionToken.AccessToken,
                    Roles        = userRoles
                };

                response = GetProfileDataFromDatabase(response, profile);
                response.CustomerProfileObject.IsNewCustomer = IsNewCustomer;
                response.LoginDate = hppAuthInterchange.LoginDate;
            }
            catch (Exception ex)
            {
                response.ErrorList.Add(new Fault("GetCustomerProfileFailed", ex.Message));
            }

            return(response);
        }