Пример #1
0
 /// <summary>
 /// To add the user role details.
 /// </summary>
 /// <param name="userrole"></param>
 /// <param name="accessToken"></param>
 /// <returns></returns>
 public bool AddUserRole(UserRole userrole, string accessToken)
 {
     try
     {
         dynamic session = null;
         if (!string.IsNullOrEmpty(accessToken))
         {
             session = _sessionManager.GetSessionValues(accessToken);
         }
         if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR)
         {
             using (var repository = new UserRoleRepository(session.DatabaseId()))
             {
                 bool isCheckRoleAndUser = repository.CheckRoleAndUser(userrole.RoleID, userrole.UserID);
                 if (isCheckRoleAndUser)
                 {
                     bool isExistUserRoleCount = repository.ExistUserRole(userrole.UserID, userrole.RoleID);
                     if (isExistUserRoleCount)
                     {
                         userrole.CreatedDate = DateTime.Now;
                         userrole.UpdatedDate = DateTime.Now;
                         repository.AddUserRole(userrole);
                         return(true);
                     }
                     else
                     {
                         return(false);
                     }
                 }
             }
         }
         else
         {
             throw new Exception("Unable to get database connection.");
         }
     }
     catch
     {
         throw;
     }
     return(false);
 }