private TbKtpRow GetDataKtp(string userName)
        {
            TbKtpRow result = new TbKtpRow();

            using (var connection = SqlConnections.NewByKey("Rukuntangga"))
            {
                var data = connection.Query <TbKtpRow>("SpGetKtpFromUsername", param: new { UserName = userName }, commandType: System.Data.CommandType.StoredProcedure);
                if (data != null)
                {
                    result = data.FirstOrDefault();
                }
            }

            return(result);
        }
        private UserDefinition GetFirst(IDbConnection connection, BaseCriteria criteria)
        {
            var user = connection.TrySingle <Entities.UserRow>(criteria);

            if (user != null)
            {
                TbKtpRow dataKtp = GetDataKtp(user.Username);
                List <TbSlideShowRow> dataSlideshow = new List <TbSlideShowRow>();
                if (dataKtp.KodeRt != null && dataKtp.KodeRt != "")
                {
                    dataSlideshow = GetSlideshow(dataKtp.KodeRt);
                }

                string userRoles = GetUserRoles(user.UserId.Value);

                //var permission = TwoLevelCache.GetLocalStoreOnly("ScriptUserPermissions:" + user.UserId.Value, TimeSpan.Zero,
                //UserPermissionRow.Fields.GenerationKey, () =>
                //{
                //    var permissions = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);

                //    if (permissionsUsedFromScript == null)
                //    {
                //        permissionsUsedFromScript = new UserPermissionRepository().ListPermissionKeys().Entities
                //            .Where(permissionKey =>
                //            {
                //                // this sends permission information for all permission keys to client side.
                //                // if you don't need all of them to be available from script, filter them here.
                //                // this is recommended for security / performance reasons...
                //                return true;
                //            }).ToArray();
                //    }

                //    foreach (var permissionKey in permissionsUsedFromScript)
                //    {
                //        if (Authorization.HasPermission(permissionKey))
                //            permissions[permissionKey] = true;
                //    }

                //    return permissions;
                //});

                return(new UserDefinition
                {
                    UserId = user.UserId.Value,
                    Username = user.Username,
                    Email = user.Email,
                    UserImage = user.UserImage,
                    DisplayName = user.DisplayName,
                    IsActive = user.IsActive.Value,
                    Source = user.Source,
                    PasswordHash = user.PasswordHash,
                    PasswordSalt = user.PasswordSalt,
                    UpdateDate = user.UpdateDate,
                    LastDirectoryUpdate = user.LastDirectoryUpdate,
                    Ktp = dataKtp,
                    SlideShow = dataSlideshow,
                    UserRoles = userRoles
                });
            }


            return(null);
        }